1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
#!/usr/bin/perl
use strict;
use warnings;
use Debian::Debhelper::Dh_Lib;
use Debian::PkgJs::Utils;
use Debian::PkgJs::Version;
use File::Basename;
my $DOCFILES =
qr/^(?:(?:co(?:de_of_conduct|ntributing)|maintaining|security)\.md|readme(?:.*\.(?:m(?:arkdown|d)|txt))?|authors?(?:\.(?:txt|md))?|notice(?:\.txt)?)$/i;
my $CHANGELOGS = qr/^(?:change(?:log(?:\.md)?|s(?:\.md)?)|history(?:\.md)?)$/i;
my $autoDispatch;
init();
exit 0 if $ENV{DEB_BUILD_OPTIONS} and $ENV{DEB_BUILD_OPTIONS} =~ /\bnodoc\b/;
my $components = root_components_list() // {};
my ( $main, $docFiles );
{
opendir my $dir, 'debian';
unless ( -e 'debian/docs'
or grep { /(?:^|\.)docs$/ } readdir $dir )
{
$main = pjson( main_package() )->{name};
}
closedir $dir;
}
if ( -e 'debian/nodejs/docs' ) {
$docFiles = getDocFiles('debian/nodejs/docs');
}
else {
$docFiles = getDocFiles();
}
install_doc_files($docFiles);
sub getDocFiles {
my ($fixedList) = @_;
my $res;
if ($fixedList) {
my @pList = open_file($fixedList);
foreach my $pattern (@pList) {
my @list = glob($pattern);
D: foreach my $docFile (@list) {
foreach my $cmp ( keys %$components ) {
$cmp =~ s#/+$##;
if ( $docFile =~ m#^\Q$cmp\E/# ) {
push @{ $res->{ $components->{$cmp} } }, $docFile;
last D;
}
}
push @{ $res->{$main} }, $docFile if $main;
}
}
}
else {
$components->{ main_package() } = $main if $main;
my %cmps = %$components;
foreach my $cmp ( keys %cmps ) {
$cmp =~ s#/+$##;
my $dir;
opendir( $dir, $cmp ) or next;
my @changelogs;
push @{ $res->{$cmp} }, map { "$cmp/$_" } grep {
push @changelogs, $_
if $_ =~ $CHANGELOGS;
$_ =~ $DOCFILES
} readdir $dir;
if ( ( !$main or $cmp ne $main ) and @changelogs ) {
push @{ $res->{$cmp} }, map { "$cmp/$_ changelog" } @changelogs;
}
}
}
return $res;
}
sub install_doc_files {
my ($tree) = @_;
my $pkg = $ARGV[0];
if ( $pkg and $pkg eq 'auto_dispatch' ) {
$pkg = undef;
$autoDispatch = 1;
}
my @pkgs = grep { /\w/ } getpackages();
unless ( $pkg or $autoDispatch ) {
if ( @pkgs != 1 ) {
@pkgs = grep { /^node-/ } @pkgs;
if ( @pkgs != 1 ) {
die "Set package as argument of $0";
}
}
@pkgs = ( $pkgs[0] );
}
foreach my $pkg (@pkgs) {
my $tmp = "debian/$pkg/usr/share/doc/";
doit( qw(mkdir -p), $tmp ) unless -e $tmp;
foreach my $cmp ( keys %$tree ) {
next unless $cmp and $components->{$cmp};
next if $autoDispatch and !isInPkg( $pkg, $components->{$cmp} );
my @docFiles = @{ $tree->{$cmp} };
my $vpkg = 'node-' . normalize_name( $components->{$cmp} || $main );
doit( 'mkdir', "$tmp/$vpkg" ) unless -e "$tmp/$vpkg";
foreach my $doc (@docFiles) {
my $dst;
( $doc, $dst ) = split( /\s+/, $doc ) if $doc =~ /\s+/;
if ( -d $doc ) {
print_and_doit( qw(cp -a --reflink=auto),
$doc, "$tmp/$vpkg/" )
unless -e "$tmp/$vpkg/" . basename($doc);
}
elsif ($dst) {
print_and_doit( qw(install -m 644),
$doc, "$tmp/$vpkg/$dst" )
unless -e "$tmp/$vpkg/$dst";
}
else {
print_and_doit( qw(install -m 644), $doc, "$tmp/$vpkg/" )
unless -e "$tmp/$vpkg/" . basename($doc);
}
}
if ( $cmp ne main_package and $pkg ne $vpkg ) {
print_and_doit( qw(ln -s), "../$pkg/copyright", "$tmp/$vpkg/" )
unless -e "$tmp/$vpkg/copyright";
}
}
}
}
my @npaths;
sub isInPkg {
my ( $pkg, $name ) = @_;
unless (@npaths) {
my $multiArch = `dpkg-architecture -q DEB_TARGET_MULTIARCH`;
chomp $multiArch;
@npaths = (
'usr/share/nodejs', 'usr/lib/nodejs', "usr/lib/$multiArch/nodejs"
);
}
my $res = 0;
foreach (@npaths) {
$res = 1
if -d "debian/$pkg/$_/$name"
or -f "debian/$pkg/$_/$name.js"
or -l "debian/$pkg/$_/$name.js";
}
return $res;
}
__END__
=pod
=head1 NAME
dh_nodejs_autodocs - automatically install components doc files
=head1 SYNOPSIS
override_dh_installdocs:
dh_installdocs
dh_nodejs_autodocs
For multiple binary packages:
override_dh_installdocs:
dh_installdocs
dh_nodejs_autodocs node-foo
Or best:
override_dh_installdocs:
dh_installdocs
dh_nodejs_autodocs auto_dispatch
=head1 DESCRIPTION
dh_nodejs_autodocs automatically install README.md, CONTRIBUTING.md,... for
each root component in its C</usr/share/doc/node-name> directory.
If no C<debian/*docs> is found, it does the same for the main component.
=head2 Multiple binary package
=over
=item * If no argument is given, dh_nodejs_autodocs installs the whole
auto-selected documentation in the binary package which name starts with
"node-".
If none exists or if there is more than one, it fails.
=item * If dh_nodejs_autodocs is launched with B<auto_dispatch>, it dispatches
auto-selected doc in related binary packages.
=item * If dh_nodejs_autodocs is launched with a binary package name,
it installs the whole auto-selected doc in it.
=back
=head1 COPYRIGHT AND LICENSE
Copyright Yadd E<lt>yadd@debian.orgE<gt>
Licensed under GPL-2+ (see /usr/share/common-licenses/GPL-2)
=cut
|