Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Arnout Vandecappelle <arnout@mind.be>
To: buildroot@busybox.net
Subject: [Buildroot] [pkg-perl infra V6 3/9] scancpan: a new script
Date: Tue, 11 Feb 2014 08:13:33 +0100	[thread overview]
Message-ID: <52F9CD9D.5020904@mind.be> (raw)
In-Reply-To: <1392034997-12394-4-git-send-email-francois.perrad@gadz.org>

On 02/10/14 13:23, Francois Perrad wrote:
> which creates Perl/CPAN package files
> 
> Signed-off-by: Francois Perrad <francois.perrad@gadz.org>
> ---
>  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<recommended> 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<MetaCPAN::API::Tiny> (version 1.131730)
> +which was included at the beginning of this file by the tool C<fatpack>.
> +
> +See L<http://search.cpan.org/~nperez/MetaCPAN-API-Tiny-1.131730/>.
> +
> +See L<http://search.cpan.org/search?query=App-FatPacker&mode=dist>.
> +
> +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

  reply	other threads:[~2014-02-11  7:13 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-10 12:23 [Buildroot] [pkg-perl infra V6 0/9] a package infrastructure for Perl/CPAN modules Francois Perrad
2014-02-10 12:23 ` [Buildroot] [pkg-perl infra V6 1/9] host-perl: export and rename PERL5LIB Francois Perrad
2014-02-10 19:40   ` Peter Korsgaard
2014-02-10 12:23 ` [Buildroot] [pkg-perl infra V6 2/9] pkg-perl: new infrastructure Francois Perrad
2014-02-11  6:29   ` Arnout Vandecappelle
2014-02-10 12:23 ` [Buildroot] [pkg-perl infra V6 3/9] scancpan: a new script Francois Perrad
2014-02-11  7:13   ` Arnout Vandecappelle [this message]
2014-02-10 12:23 ` [Buildroot] [pkg-perl infra V6 4/9] host-perl-xml-parser: rename and refactor with perl infrastructure Francois Perrad
2014-02-11  6:26   ` Arnout Vandecappelle
2014-02-10 12:23 ` [Buildroot] [pkg-perl infra V6 5/9] host-perl-module-build: new package Francois Perrad
2014-02-10 12:23 ` [Buildroot] [pkg-perl infra V6 6/9] perl: remove useless patch Francois Perrad
2014-02-10 19:40   ` Peter Korsgaard
2014-02-10 12:23 ` [Buildroot] [pkg-perl infra V6 7/9] manual: adding packages perl Francois Perrad
2014-02-11  7:17   ` Arnout Vandecappelle
2014-02-10 12:23 ` [Buildroot] [pkg-perl infra V6 8/9] cpanminus: remove it Francois Perrad
2014-02-10 19:40   ` Peter Korsgaard
2014-02-10 12:23 ` [Buildroot] [pkg-perl infra V6 9/9] perl: remove PERL_INSTALL_TARGET_GOALS Francois Perrad
2014-02-10 20:51   ` Arnout Vandecappelle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52F9CD9D.5020904@mind.be \
    --to=arnout@mind.be \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox