From mboxrd@z Thu Jan 1 00:00:00 1970 From: Arnout Vandecappelle Date: Tue, 11 Feb 2014 08:13:33 +0100 Subject: [Buildroot] [pkg-perl infra V6 3/9] scancpan: a new script In-Reply-To: <1392034997-12394-4-git-send-email-francois.perrad@gadz.org> References: <1392034997-12394-1-git-send-email-francois.perrad@gadz.org> <1392034997-12394-4-git-send-email-francois.perrad@gadz.org> Message-ID: <52F9CD9D.5020904@mind.be> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: buildroot@busybox.net On 02/10/14 13:23, Francois Perrad wrote: > which creates Perl/CPAN package files > > Signed-off-by: Francois Perrad > --- > support/scripts/scancpan | 694 ++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 694 insertions(+) > create mode 100755 support/scripts/scancpan > > diff --git a/support/scripts/scancpan b/support/scripts/scancpan > new file mode 100755 > index 0000000..90ecae4 > --- /dev/null > +++ b/support/scripts/scancpan > @@ -0,0 +1,694 @@ > +#!/usr/bin/env perl > + > +# This chunk of stuff was generated by App::FatPacker. To find the original > +# file's code, look for the end of this BEGIN block or the string 'FATPACK' [snip] It's a pity that it isn't possible to put the included package in a separate file, that would be easier to review. > +use 5.010; > +use strict; > +use warnings; > +use Fatal qw(open close); > + > +use Getopt::Long; > +use Pod::Usage; > +use File::Basename; > +use Module::CoreList; > +use MetaCPAN::API::Tiny; > + > +my ($help, $man, $quiet, $force, $recommend); > +GetOptions( 'help|?' => \$help, > + 'man' => \$man, > + 'quiet|q' => \$quiet, > + 'force|f' => \$force, > + 'recommend' => \$recommend > +) or pod2usage(-exitval => 1); > +pod2usage(-exitval => 0) if $help; > +pod2usage(-exitval => 0, -verbose => 2) if $man; > +pod2usage(-exitval => 1) if scalar @ARGV == 0; > + > +my %dist; > +my %deps_build; > +my %deps_runtime; > +my $mcpan = MetaCPAN::API::Tiny->new(); > + > +sub fetch { > + my $name = shift; > + unless ($dist{$name}) { > + say qq{fetch ${name}} unless $quiet; > + my $result = $mcpan->release( distribution => $name ); > + $dist{$name} = $result; > + my @deps_build = (); > + my @deps_runtime = (); > + my $mb; > + foreach my $dep (@{$result->{dependency}}) { > + my $modname = ${$dep}{module}; > + $mb = 1 if $modname eq q{Module::Build}; > + next if $modname eq q{perl}; > + next if $modname =~ m|^Alien|; > + next if $modname =~ m|^Win32|; > + next if Module::CoreList::first_release( $modname ); This one depends on the perl version installed on the host to decide which packages should be included... But the host that runs scancpan may be a different one than the one that builds buildroot. I think we should baseline a specific minimal perl version (and check for it in dependencies.sh), and compare with that minimum for host packages. For target packages, we should compare against the version found in package/perl/perl.mk. > + next if ${$dep}{phase} eq q{develop}; > + next if ${$dep}{phase} eq q{test}; > + next if !$recommend && ${$dep}{relationship} ne q{requires}; > + my $distname = $mcpan->module( $modname )->{distribution}; > + if (${$dep}{phase} eq q{runtime}) { > + push @deps_runtime, $distname; > + } > + else { # configure, build > + push @deps_build, $distname; > + } > + fetch( $distname ); > + } > + unshift @deps_build, q{Module-Build} if $mb; > + $deps_build{$name} = \@deps_build; > + $deps_runtime{$name} = \@deps_runtime; > + } > + return; > +} > + > +foreach my $distname (@ARGV) { > + fetch( $distname ); > +} > +say scalar keys %dist, q{ packages fetched.} unless $quiet; > + > +sub fsname { > + my $name = shift; > + return q{perl-} . lc $name; > +} > + > +sub brname { > + my $name = shift; > + $name =~ s|-|_|g; > + return uc $name; > +} > + > +while (my ($distname, $dist) = each %dist) { > + my $fsname = fsname( $distname ); > + my $dirname = q{package/} . $fsname; > + my $cfgname = $dirname . q{/Config.in}; > + my $mkname = $dirname . q{/} . $fsname . q{.mk}; > + my $brname = brname( $fsname ); > + mkdir $dirname unless -d $dirname; > + if ($force || !-f $cfgname) { > + my $abstract = $dist->{abstract} || q{NO ABSTRACT}; > + say qq{write ${cfgname}} unless $quiet; > + open my $fh, q{>}, $cfgname; > + say {$fh} qq{config BR2_PACKAGE_${brname}}; > + say {$fh} qq{\tbool "${fsname}"}; > + foreach my $dep (@{$deps_runtime{$distname}}) { > + my $brdep = brname( fsname( $dep ) ); > + say {$fh} qq{\tselect BR2_PACKAGE_${brdep}}; > + } > + say {$fh} qq{\thelp}; > + say {$fh} qq{\t ${abstract}}; Instead of putting the unhelpful NO ABSTRACT text, it's better to make the help text entry conditional on $dist->{abstract}. > + say {$fh} qq{}; > + close $fh; > + } > + if ($force || !-f $mkname) { > + my $version = $dist->{version}; > + my $site = dirname( $dist->{download_url} ); > + my($scheme, $auth, $path) = $dist->{download_url} =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)|; > + my($filename, $directories, $suffix) = fileparse( $path, q{tar.gz}, q{tgz} ); > + my $dependencies = join q{ }, map( { q{host-} . fsname( $_ ); } @{$deps_build{$distname}} ), > + map( { fsname( $_ ); } @{$deps_runtime{$distname}} ); > + my $host_dependencies = join q{ }, map { q{host-} . fsname( $_ ); } @{$deps_build{$distname}}, > + @{$deps_runtime{$distname}}; > + my $license = ref $dist->{license} eq 'ARRAY' > + ? join q{ }, @{$dist->{license}} > + : $dist->{license}; > + say qq{write ${mkname}} unless $quiet; > + open my $fh, q{>}, $mkname; > + say {$fh} qq{################################################################################}; > + say {$fh} qq{#}; > + say {$fh} qq{# ${fsname}}; > + say {$fh} qq{#}; > + say {$fh} qq{################################################################################}; > + say {$fh} qq{}; > + say {$fh} qq{${brname}_VERSION = ${version}}; > + say {$fh} qq{${brname}_SOURCE = ${distname}-\$(${brname}_VERSION).${suffix}}; > + say {$fh} qq{${brname}_SITE = \$(BR2_CPAN_MIRROR)${directories}}; > + say {$fh} qq{${brname}_DEPENDENCIES = perl ${dependencies}}; > + say {$fh} qq{#HOST_${brname}_DEPENDENCIES = ${host_dependencies}}; > + say {$fh} qq{${brname}_LICENSE = ${license}} if $license && $license ne q{unknown}; > + say {$fh} qq{}; > + say {$fh} qq{\$(eval \$(perl-package))}; > + say {$fh} qq{#\$(eval \$(host-perl-package))}; > + close $fh; > + } > +} > + > +my %pkg; > +my $cfgname = q{package/Config.in}; > +if (-f $cfgname) { > + open my $fh, q{<}, $cfgname; > + while (<$fh>) { > + chomp; > + $pkg{$_} = 1 if m|package/perl-|; > + } > + close $fh; > +} > + > +foreach my $distname (sort keys %dist) { > + my $fsname = fsname( $distname ); > + $pkg{qq{source "package/${fsname}/Config.in"}} = 1; > +} > + > +say qq{${cfgname} must contains the following lines:}; > +say join qq{\n}, sort keys %pkg; > + > +__END__ > + > +=head1 NAME > + > +support/scripts/scancpan Try-Tiny Moo > + > +=head1 SYNOPSIS > + > +supports/scripts/scancpan [options] [distname ...] > + > + Options: > + -help > + -man > + -quiet > + -force > + -recommend > + > +=head1 OPTIONS > + > +=over 8 > + > +=item B<-help> > + > +Print a brief help message and exits. > + > +=item B<-man> > + > +Prints the manual page and exits. > + > +=item B<-quiet> > + > +Executes without output > + > +=item B<-force> > + > +Forces the overwritting of existing files. > + > +=item B<-recommend> > + > +Adds I dependencies. > + > +=back > + > +=head1 DESCRIPTION > + > +This script creates the BR package files for all Perl/CPAN > +distributions required by all distname. These data are fetched from > +https://metacpan.org/. > + > +See the Buildroot documentation for details on the usage of the Perl > +infrastructure. > + > +=head1 LICENSE > + > +This script is a part of Buildroot. Please mention explicitly the license of this script. I guess you want it to be GPLv2+. In that case, include the entire GPL blurb (see the top of Makefile). Regards, Arnout > + > +This script requires the module C (version 1.131730) > +which was included at the beginning of this file by the tool C. > + > +See L. > + > +See L. > + > +These both libraries are free software and may be distributed under the same > +terms as perl itself. > + > +And perl may be distributed under the terms of Artistic v1 or GPL v1 license. > + > +=cut > -- Arnout Vandecappelle arnout at mind be Senior Embedded Software Architect +32-16-286500 Essensium/Mind http://www.mind.be G.Geenslaan 9, 3001 Leuven, Belgium BE 872 984 063 RPR Leuven LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle GPG fingerprint: 7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F