scancpan 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  1. #!/usr/bin/env perl
  2. # This chunk of stuff was generated by App::FatPacker. To find the original
  3. # file's code, look for the end of this BEGIN block or the string 'FATPACK'
  4. BEGIN {
  5. my %fatpacked;
  6. $fatpacked{"MetaCPAN/API/Tiny.pm"} = <<'METACPAN_API_TINY';
  7. package MetaCPAN::API::Tiny;
  8. {
  9. $MetaCPAN::API::Tiny::VERSION = '1.131730';
  10. }
  11. use strict;
  12. use warnings;
  13. # ABSTRACT: A Tiny API client for MetaCPAN
  14. use Carp;
  15. use JSON::PP 'encode_json', 'decode_json';
  16. use HTTP::Tiny;
  17. sub new {
  18. my ($class, @args) = @_;
  19. $#_ % 2 == 0
  20. or croak 'Arguments must be provided as name/value pairs';
  21. my %params = @args;
  22. die 'ua_args must be an array reference'
  23. if $params{ua_args} && ref($params{ua_args}) ne 'ARRAY';
  24. my $self = +{
  25. base_url => $params{base_url} || 'http://api.metacpan.org/v0',
  26. ua => $params{ua} || HTTP::Tiny->new(
  27. $params{ua_args}
  28. ? @{$params{ua_args}}
  29. : (agent => 'MetaCPAN::API::Tiny/'
  30. . ($MetaCPAN::API::VERSION || 'xx'))),
  31. };
  32. return bless($self, $class);
  33. }
  34. sub _build_extra_params {
  35. my $self = shift;
  36. @_ % 2 == 0
  37. or croak 'Incorrect number of params, must be key/value';
  38. my %extra = @_;
  39. my $ua = $self->{ua};
  40. foreach my $key (keys %extra)
  41. {
  42. # The implementation in HTTP::Tiny uses + instead of %20, fix that
  43. $extra{$key} = $ua->_uri_escape($extra{$key});
  44. $extra{$key} =~ s/\+/%20/g;
  45. }
  46. my $params = join '&', map { "$_=" . $extra{$_} } sort keys %extra;
  47. return $params;
  48. }
  49. # /source/{author}/{release}/{path}
  50. sub source {
  51. my $self = shift;
  52. my %opts = @_ ? @_ : ();
  53. my $url = '';
  54. my $error = "Provide 'author' and 'release' and 'path'";
  55. %opts or croak $error;
  56. if (
  57. defined ( my $author = $opts{'author'} ) &&
  58. defined ( my $release = $opts{'release'} ) &&
  59. defined ( my $path = $opts{'path'} )
  60. ) {
  61. $url = "source/$author/$release/$path";
  62. } else {
  63. croak $error;
  64. }
  65. $url = $self->{base_url} . "/$url";
  66. my $result = $self->{ua}->get($url);
  67. $result->{'success'}
  68. or croak "Failed to fetch '$url': " . $result->{'reason'};
  69. return $result->{'content'};
  70. }
  71. # /release/{distribution}
  72. # /release/{author}/{release}
  73. sub release {
  74. my $self = shift;
  75. my %opts = @_ ? @_ : ();
  76. my $url = '';
  77. my $error = "Either provide 'distribution', or 'author' and 'release', " .
  78. "or 'search'";
  79. %opts or croak $error;
  80. my %extra_opts = ();
  81. if ( defined ( my $dist = $opts{'distribution'} ) ) {
  82. $url = "release/$dist";
  83. } elsif (
  84. defined ( my $author = $opts{'author'} ) &&
  85. defined ( my $release = $opts{'release'} )
  86. ) {
  87. $url = "release/$author/$release";
  88. } elsif ( defined ( my $search_opts = $opts{'search'} ) ) {
  89. ref $search_opts && ref $search_opts eq 'HASH'
  90. or croak $error;
  91. %extra_opts = %{$search_opts};
  92. $url = 'release/_search';
  93. } else {
  94. croak $error;
  95. }
  96. return $self->fetch( $url, %extra_opts );
  97. }
  98. # /pod/{module}
  99. # /pod/{author}/{release}/{path}
  100. sub pod {
  101. my $self = shift;
  102. my %opts = @_ ? @_ : ();
  103. my $url = '';
  104. my $error = "Either provide 'module' or 'author and 'release' and 'path'";
  105. %opts or croak $error;
  106. if ( defined ( my $module = $opts{'module'} ) ) {
  107. $url = "pod/$module";
  108. } elsif (
  109. defined ( my $author = $opts{'author'} ) &&
  110. defined ( my $release = $opts{'release'} ) &&
  111. defined ( my $path = $opts{'path'} )
  112. ) {
  113. $url = "pod/$author/$release/$path";
  114. } else {
  115. croak $error;
  116. }
  117. # check content-type
  118. my %extra = ();
  119. if ( defined ( my $type = $opts{'content-type'} ) ) {
  120. $type =~ m{^ text/ (?: html|plain|x-pod|x-markdown ) $}x
  121. or croak 'Incorrect content-type provided';
  122. $extra{headers}{'content-type'} = $type;
  123. }
  124. $url = $self->{base_url}. "/$url";
  125. my $result = $self->{ua}->get( $url, \%extra );
  126. $result->{'success'}
  127. or croak "Failed to fetch '$url': " . $result->{'reason'};
  128. return $result->{'content'};
  129. }
  130. # /module/{module}
  131. sub module {
  132. my $self = shift;
  133. my $name = shift;
  134. $name or croak 'Please provide a module name';
  135. return $self->fetch("module/$name");
  136. }
  137. # file() is a synonym of module
  138. sub file { goto &module }
  139. # /author/{author}
  140. sub author {
  141. my $self = shift;
  142. my ( $pause_id, $url, %extra_opts );
  143. if ( @_ == 1 ) {
  144. $url = 'author/' . shift;
  145. } elsif ( @_ == 2 ) {
  146. my %opts = @_;
  147. if ( defined $opts{'pauseid'} ) {
  148. $url = "author/" . $opts{'pauseid'};
  149. } elsif ( defined $opts{'search'} ) {
  150. my $search_opts = $opts{'search'};
  151. ref $search_opts && ref $search_opts eq 'HASH'
  152. or croak "'search' key must be hashref";
  153. %extra_opts = %{$search_opts};
  154. $url = 'author/_search';
  155. } else {
  156. croak 'Unknown option given';
  157. }
  158. } else {
  159. croak 'Please provide an author PAUSEID or a "search"';
  160. }
  161. return $self->fetch( $url, %extra_opts );
  162. }
  163. sub fetch {
  164. my $self = shift;
  165. my $url = shift;
  166. my $extra = $self->_build_extra_params(@_);
  167. my $base = $self->{base_url};
  168. my $req_url = $extra ? "$base/$url?$extra" : "$base/$url";
  169. my $result = $self->{ua}->get($req_url);
  170. return $self->_decode_result( $result, $req_url );
  171. }
  172. sub post {
  173. my $self = shift;
  174. my $url = shift;
  175. my $query = shift;
  176. my $base = $self->{base_url};
  177. defined $url
  178. or croak 'First argument of URL must be provided';
  179. ref $query and ref $query eq 'HASH'
  180. or croak 'Second argument of query hashref must be provided';
  181. my $query_json = encode_json( $query );
  182. my $result = $self->{ua}->request(
  183. 'POST',
  184. "$base/$url",
  185. {
  186. headers => { 'Content-Type' => 'application/json' },
  187. content => $query_json,
  188. }
  189. );
  190. return $self->_decode_result( $result, $url, $query_json );
  191. }
  192. sub _decode_result {
  193. my $self = shift;
  194. my ( $result, $url, $original ) = @_;
  195. my $decoded_result;
  196. ref $result and ref $result eq 'HASH'
  197. or croak 'First argument must be hashref';
  198. defined $url
  199. or croak 'Second argument of a URL must be provided';
  200. if ( defined ( my $success = $result->{'success'} ) ) {
  201. my $reason = $result->{'reason'} || '';
  202. $reason .= ( defined $original ? " (request: $original)" : '' );
  203. $success or croak "Failed to fetch '$url': $reason";
  204. } else {
  205. croak 'Missing success in return value';
  206. }
  207. defined ( my $content = $result->{'content'} )
  208. or croak 'Missing content in return value';
  209. eval { $decoded_result = decode_json $content; 1 }
  210. or do { croak "Couldn't decode '$content': $@" };
  211. return $decoded_result;
  212. }
  213. 1;
  214. __END__
  215. =pod
  216. =head1 NAME
  217. MetaCPAN::API::Tiny - A Tiny API client for MetaCPAN
  218. =head1 VERSION
  219. version 1.131730
  220. =head1 DESCRIPTION
  221. This is the Tiny version of L<MetaCPAN::API>. It implements a compatible API
  222. with a few notable exceptions:
  223. =over 4
  224. =item Attributes are direct hash access
  225. The attributes defined using Mo(o|u)se are now accessed via the blessed hash
  226. directly. There are no accessors defined to access this elements.
  227. =item Exception handling
  228. Instead of using Try::Tiny, raw evals are used. This could potentially cause
  229. issues, so just be aware.
  230. =item Testing
  231. Test::Fatal was replaced with an eval implementation of exception().
  232. Test::TinyMocker usage is retained, but may be absorbed since it is pure perl
  233. =back
  234. =head1 CLASS_METHODS
  235. =head2 new
  236. new is the constructor for MetaCPAN::API::Tiny. In the non-tiny version of this
  237. module, this is provided via Any::Moose built from the attributes defined. In
  238. the tiny version, we define our own constructor. It takes the same arguments
  239. and provides similar checks to MetaCPAN::API with regards to arguments passed.
  240. =head1 PUBLIC_METHODS
  241. =head2 source
  242. my $source = $mcpan->source(
  243. author => 'DOY',
  244. release => 'Moose-2.0201',
  245. path => 'lib/Moose.pm',
  246. );
  247. Searches MetaCPAN for a module or a specific release and returns the plain source.
  248. =head2 release
  249. my $result = $mcpan->release( distribution => 'Moose' );
  250. # or
  251. my $result = $mcpan->release( author => 'DOY', release => 'Moose-2.0001' );
  252. Searches MetaCPAN for a dist.
  253. You can do complex searches using 'search' parameter:
  254. # example lifted from MetaCPAN docs
  255. my $result = $mcpan->release(
  256. search => {
  257. author => "OALDERS AND ",
  258. filter => "status:latest",
  259. fields => "name",
  260. size => 1,
  261. },
  262. );
  263. =head2 pod
  264. my $result = $mcpan->pod( module => 'Moose' );
  265. # or
  266. my $result = $mcpan->pod(
  267. author => 'DOY',
  268. release => 'Moose-2.0201',
  269. path => 'lib/Moose.pm',
  270. );
  271. Searches MetaCPAN for a module or a specific release and returns the POD.
  272. =head2 module
  273. my $result = $mcpan->module('MetaCPAN::API');
  274. Searches MetaCPAN and returns a module's ".pm" file.
  275. =head2 file
  276. A synonym of L</module>
  277. =head2 author
  278. my $result1 = $mcpan->author('XSAWYERX');
  279. my $result2 = $mcpan->author( pauseid => 'XSAWYERX' );
  280. Searches MetaCPAN for a specific author.
  281. You can do complex searches using 'search' parameter:
  282. # example lifted from MetaCPAN docs
  283. my $result = $mcpan->author(
  284. search => {
  285. q => 'profile.name:twitter',
  286. size => 1,
  287. },
  288. );
  289. =head2 fetch
  290. my $result = $mcpan->fetch('/release/distribution/Moose');
  291. # with parameters
  292. my $more = $mcpan->fetch(
  293. '/release/distribution/Moose',
  294. param => 'value',
  295. );
  296. This is a helper method for API implementations. It fetches a path from MetaCPAN, decodes the JSON from the content variable and returns it.
  297. You don't really need to use it, but you can in case you want to write your own extension implementation to MetaCPAN::API.
  298. It accepts an additional hash as "GET" parameters.
  299. =head2 post
  300. # /release&content={"query":{"match_all":{}},"filter":{"prefix":{"archive":"Cache-Cache-1.06"}}}
  301. my $result = $mcpan->post(
  302. 'release',
  303. {
  304. query => { match_all => {} },
  305. filter => { prefix => { archive => 'Cache-Cache-1.06' } },
  306. },
  307. );
  308. The POST equivalent of the "fetch()" method. It gets the path and JSON request.
  309. =head1 THANKS
  310. Overall the tests and code were ripped directly from MetaCPAN::API and
  311. tiny-fied. A big thanks to Sawyer X for writing the original module.
  312. =head1 AUTHOR
  313. Nicholas R. Perez <nperez@cpan.org>
  314. =head1 COPYRIGHT AND LICENSE
  315. This software is copyright (c) 2013 by Nicholas R. Perez <nperez@cpan.org>.
  316. This is free software; you can redistribute it and/or modify it under
  317. the same terms as the Perl 5 programming language system itself.
  318. =cut
  319. METACPAN_API_TINY
  320. s/^ //mg for values %fatpacked;
  321. unshift @INC, sub {
  322. if (my $fat = $fatpacked{$_[1]}) {
  323. if ($] < 5.008) {
  324. return sub {
  325. return 0 unless length $fat;
  326. $fat =~ s/^([^\n]*\n?)//;
  327. $_ = $1;
  328. return 1;
  329. };
  330. }
  331. open my $fh, '<', \$fat
  332. or die "FatPacker error loading $_[1] (could be a perl installation issue?)";
  333. return $fh;
  334. }
  335. return
  336. };
  337. } # END OF FATPACK CODE
  338. use 5.010;
  339. use strict;
  340. use warnings;
  341. use Fatal qw(open close);
  342. use Getopt::Long;
  343. use Pod::Usage;
  344. use File::Basename;
  345. use Module::CoreList;
  346. use HTTP::Tiny;
  347. use Safe;
  348. use MetaCPAN::API::Tiny;
  349. # Below, 5.026 should be aligned with the version of perl actually
  350. # bundled in Buildroot:
  351. die <<"MSG" if $] < 5.026;
  352. This script needs a host perl with the same major version as Buildroot target perl.
  353. Your current host perl is:
  354. $^X
  355. version $]
  356. You may install a local one by running:
  357. perlbrew install perl-5.26.0
  358. MSG
  359. my ($help, $man, $quiet, $force, $recommend, $test, $host);
  360. my $target = 1;
  361. GetOptions( 'help|?' => \$help,
  362. 'man' => \$man,
  363. 'quiet|q' => \$quiet,
  364. 'force|f' => \$force,
  365. 'host!' => \$host,
  366. 'target!' => \$target,
  367. 'recommend' => \$recommend,
  368. 'test' => \$test
  369. ) or pod2usage(-exitval => 1);
  370. pod2usage(-exitval => 0) if $help;
  371. pod2usage(-exitval => 0, -verbose => 2) if $man;
  372. pod2usage(-exitval => 1) if scalar @ARGV == 0;
  373. my %dist; # name -> metacpan data
  374. my %need_target; # name -> 1 if target package is needed
  375. my %need_host; # name -> 1 if host package is needed
  376. my %need_dlopen; # name -> 1 if requires dynamic library
  377. my %deps_build; # name -> list of host dependencies
  378. my %deps_runtime; # name -> list of target dependencies
  379. my %deps_optional; # name -> list of optional target dependencies
  380. my %license_files; # name -> list of license files
  381. my %checksum; # author -> list of checksum
  382. my $mirror = 'http://cpan.metacpan.org'; # a CPAN mirror
  383. my $mcpan = MetaCPAN::API::Tiny->new(base_url => 'http://fastapi.metacpan.org/v1');
  384. my $ua = HTTP::Tiny->new();
  385. sub get_checksum {
  386. my ($url) = @_;
  387. my ($path) = $url =~ m|^[^:/?#]+://[^/?#]*([^?#]*)|;
  388. my ($basename, $dirname) = fileparse( $path );
  389. unless ($checksum{$dirname}) {
  390. my $url = $mirror . $dirname . q{CHECKSUMS};
  391. my $response = $ua->get($url);
  392. $checksum{$dirname} = $response->{content};
  393. }
  394. my $chksum = Safe->new->reval($checksum{$dirname});
  395. return $chksum->{$basename}, $basename;
  396. }
  397. sub is_xs {
  398. my ($manifest) = @_;
  399. # This heuristic determines if a module is a native extension, by searching
  400. # some file extension types in the MANIFEST of the distribution.
  401. # It was inspired by http://deps.cpantesters.org/static/purity.html
  402. return $manifest =~ m/\.(swg|xs|c|h|i)[\n\s]/;
  403. }
  404. sub find_license_files {
  405. my ($manifest) = @_;
  406. my @license_files;
  407. foreach (split /\n/, $manifest) {
  408. next if m|/|;
  409. push @license_files, $_ if m/(ARTISTIC|COPYING|COPYRIGHT|LICENSE)/i;
  410. }
  411. if (scalar @license_files == 0 && $manifest =~ m/(README)[\n\s]/i) {
  412. @license_files = ($1);
  413. }
  414. return \@license_files;
  415. }
  416. sub fetch {
  417. my ($name, $need_target, $need_host, $top) = @_;
  418. $need_target{$name} = $need_target if $need_target;
  419. $need_host{$name} = $need_host if $need_host;
  420. unless ($dist{$name} && !$top) {
  421. say qq{fetch ${name}} unless $quiet;
  422. my $result = $mcpan->release( distribution => $name );
  423. $dist{$name} = $result;
  424. eval {
  425. my $manifest = $mcpan->source( author => $result->{author},
  426. release => $name . q{-} . $result->{version},
  427. path => 'MANIFEST' );
  428. $need_dlopen{$name} = is_xs( $manifest );
  429. $license_files{$name} = find_license_files( $manifest );
  430. };
  431. if ($@) {
  432. warn $@;
  433. $license_files{$name} = [];
  434. }
  435. my %build = ();
  436. my %runtime = ();
  437. my %optional = ();
  438. foreach my $dep (@{$result->{dependency}}) {
  439. my $modname = ${$dep}{module};
  440. next if $modname eq q{perl};
  441. next if $modname =~ m|^Alien|;
  442. next if $modname =~ m|^Win32|;
  443. next if !($test && $top) && $modname =~ m|^Test|;
  444. next if Module::CoreList::is_core( $modname, undef, $] );
  445. # we could use the host Module::CoreList data, because host perl and
  446. # target perl have the same major version
  447. next if ${$dep}{phase} eq q{develop};
  448. next if !($test && $top) && ${$dep}{phase} eq q{test};
  449. my $distname = $mcpan->module( $modname )->{distribution};
  450. if (${$dep}{phase} eq q{runtime}) {
  451. if (${$dep}{relationship} eq q{requires}) {
  452. $runtime{$distname} = 1;
  453. }
  454. else {
  455. $optional{$distname} = 1 if $recommend && $top;
  456. }
  457. }
  458. else { # configure, build
  459. $build{$distname} = 1;
  460. }
  461. }
  462. $deps_build{$name} = [keys %build];
  463. $deps_runtime{$name} = [keys %runtime];
  464. $deps_optional{$name} = [keys %optional];
  465. foreach my $distname (@{$deps_build{$name}}) {
  466. fetch( $distname, 0, 1 );
  467. }
  468. foreach my $distname (@{$deps_runtime{$name}}) {
  469. fetch( $distname, $need_target, $need_host );
  470. $need_dlopen{$name} ||= $need_dlopen{$distname};
  471. }
  472. foreach my $distname (@{$deps_optional{$name}}) {
  473. fetch( $distname, $need_target, $need_host );
  474. }
  475. }
  476. return;
  477. }
  478. foreach my $distname (@ARGV) {
  479. # Command-line's distributions
  480. fetch( $distname, !!$target, !!$host, 1 );
  481. }
  482. say scalar keys %dist, q{ packages fetched.} unless $quiet;
  483. # Buildroot package name: lowercase
  484. sub fsname {
  485. my $name = shift;
  486. $name =~ s|_|-|g;
  487. return q{perl-} . lc $name;
  488. }
  489. # Buildroot variable name: uppercase
  490. sub brname {
  491. my $name = shift;
  492. $name =~ s|-|_|g;
  493. return uc $name;
  494. }
  495. while (my ($distname, $dist) = each %dist) {
  496. my $fsname = fsname( $distname );
  497. my $dirname = q{package/} . $fsname;
  498. my $cfgname = $dirname . q{/Config.in};
  499. my $mkname = $dirname . q{/} . $fsname . q{.mk};
  500. my $hashname = $dirname . q{/} . $fsname . q{.hash};
  501. my $brname = brname( $fsname );
  502. mkdir $dirname unless -d $dirname;
  503. if ($need_target{$distname} && ($force || !-f $cfgname)) {
  504. my $abstract = $dist->{abstract};
  505. my $homepage = $dist->{resources}->{homepage} || qq{https://metacpan.org/release/${distname}};
  506. say qq{write ${cfgname}} unless $quiet;
  507. open my $fh, q{>}, $cfgname;
  508. say {$fh} qq{config BR2_PACKAGE_${brname}};
  509. say {$fh} qq{\tbool "${fsname}"};
  510. say {$fh} qq{\tdepends on !BR2_STATIC_LIBS} if $need_dlopen{$distname};
  511. foreach my $dep (sort @{$deps_runtime{$distname}}) {
  512. my $brdep = brname( fsname( $dep ) );
  513. say {$fh} qq{\tselect BR2_PACKAGE_${brdep}};
  514. }
  515. say {$fh} qq{\thelp};
  516. say {$fh} qq{\t ${abstract}\n} if $abstract;
  517. say {$fh} qq{\t ${homepage}};
  518. if ($need_dlopen{$distname}) {
  519. say {$fh} qq{\ncomment "${fsname} needs a toolchain w/ dynamic library"};
  520. say {$fh} qq{\tdepends on BR2_STATIC_LIBS};
  521. }
  522. close $fh;
  523. }
  524. if ($force || !-f $mkname) {
  525. my $version = $dist->{version};
  526. my ($path) = $dist->{download_url} =~ m|^[^:/?#]+://[^/?#]*([^?#]*)|;
  527. # this URL contains only the scheme, auth and path parts (but no query and fragment parts)
  528. # the scheme is not used, because the job is done by the BR download infrastructure
  529. # the auth part is not used, because we use $(BR2_CPAN_MIRROR)
  530. my ($filename, $directories, $suffix) = fileparse( $path, q{tar.gz}, q{tgz} );
  531. $directories =~ s|/$||;
  532. my $dependencies = join q{ }, map( { q{host-} . fsname( $_ ); } sort @{$deps_build{$distname}} ),
  533. map( { fsname( $_ ); } sort @{$deps_runtime{$distname}} );
  534. my $host_dependencies = join q{ }, map { q{host-} . fsname( $_ ); } sort( @{$deps_build{$distname}},
  535. @{$deps_runtime{$distname}} );
  536. my $license = ref $dist->{license} eq 'ARRAY'
  537. ? join q{ or }, @{$dist->{license}}
  538. : $dist->{license};
  539. # BR requires license name as in http://spdx.org/licenses/
  540. $license =~ s|apache_2_0|Apache-2.0|;
  541. $license =~ s|artistic_2|Artistic-2.0|;
  542. $license =~ s|mit|MIT|;
  543. $license =~ s|openssl|OpenSSL|;
  544. $license =~ s|perl_5|Artistic or GPL-1.0+|;
  545. my $license_files = join q{ }, @{$license_files{$distname}};
  546. say qq{write ${mkname}} unless $quiet;
  547. open my $fh, q{>}, $mkname;
  548. say {$fh} qq{################################################################################};
  549. say {$fh} qq{#};
  550. say {$fh} qq{# ${fsname}};
  551. say {$fh} qq{#};
  552. say {$fh} qq{################################################################################};
  553. say {$fh} qq{};
  554. say {$fh} qq{${brname}_VERSION = ${version}};
  555. say {$fh} qq{${brname}_SOURCE = ${distname}-\$(${brname}_VERSION).${suffix}};
  556. say {$fh} qq{${brname}_SITE = \$(BR2_CPAN_MIRROR)${directories}};
  557. say {$fh} qq{${brname}_DEPENDENCIES = ${dependencies}} if $need_target{$distname} && $dependencies;
  558. say {$fh} qq{HOST_${brname}_DEPENDENCIES = ${host_dependencies}} if $need_host{$distname} && $host_dependencies;
  559. say {$fh} qq{${brname}_LICENSE = ${license}} if $license && $license ne q{unknown};
  560. say {$fh} qq{${brname}_LICENSE_FILES = ${license_files}} if $license_files;
  561. say {$fh} qq{};
  562. foreach (sort @{$deps_optional{$distname}}) {
  563. next if grep { $_ eq $distname; } @{$deps_runtime{$_}}; # avoid cyclic dependencies
  564. my $opt_brname = brname( $_ );
  565. my $opt_fsname = fsname( $_ );
  566. say {$fh} qq{ifeq (\$(BR2_PACKAGE_PERL_${opt_brname}),y)};
  567. say {$fh} qq{${brname}_DEPENDENCIES += ${opt_fsname}};
  568. say {$fh} qq{endif};
  569. say {$fh} qq{};
  570. }
  571. say {$fh} qq{\$(eval \$(perl-package))} if $need_target{$distname};
  572. say {$fh} qq{\$(eval \$(host-perl-package))} if $need_host{$distname};
  573. close $fh;
  574. }
  575. if ($force || !-f $hashname) {
  576. my ($checksum, $filename) = get_checksum($dist->{download_url});
  577. my $md5 = $checksum->{md5};
  578. my $sha256 = $checksum->{sha256};
  579. say qq{write ${hashname}} unless $quiet;
  580. open my $fh, q{>}, $hashname;
  581. say {$fh} qq{# retrieved by scancpan from ${mirror}/};
  582. say {$fh} qq{md5 ${md5} ${filename}};
  583. say {$fh} qq{sha256 ${sha256} ${filename}};
  584. close $fh;
  585. }
  586. }
  587. my %pkg;
  588. my $cfgname = q{package/Config.in};
  589. if (-f $cfgname) {
  590. open my $fh, q{<}, $cfgname;
  591. while (<$fh>) {
  592. chomp;
  593. $pkg{$_} = 1 if m|package/perl-|;
  594. }
  595. close $fh;
  596. }
  597. foreach my $distname (keys %need_target) {
  598. my $fsname = fsname( $distname );
  599. $pkg{qq{\tsource "package/${fsname}/Config.in"}} = 1;
  600. }
  601. say qq{${cfgname} must contain the following lines:};
  602. say join qq{\n}, sort keys %pkg;
  603. __END__
  604. =head1 NAME
  605. utils/scancpan Try-Tiny Moo
  606. =head1 SYNOPSIS
  607. supports/scripts/scancpan [options] [distname ...]
  608. Options:
  609. -help
  610. -man
  611. -quiet
  612. -force
  613. -target/-notarget
  614. -host/-nohost
  615. -recommend
  616. -test
  617. =head1 OPTIONS
  618. =over 8
  619. =item B<-help>
  620. Prints a brief help message and exits.
  621. =item B<-man>
  622. Prints the manual page and exits.
  623. =item B<-quiet>
  624. Executes without output
  625. =item B<-force>
  626. Forces the overwriting of existing files.
  627. =item B<-target/-notarget>
  628. Switches package generation for the target variant (the default is C<-target>).
  629. =item B<-host/-nohost>
  630. Switches package generation for the host variant (the default is C<-nohost>).
  631. =item B<-recommend>
  632. Adds I<recommended> dependencies.
  633. =item B<-test>
  634. Adds dependencies for test.
  635. =back
  636. =head1 DESCRIPTION
  637. This script creates templates of the Buildroot package files for all the
  638. Perl/CPAN distributions required by the specified distnames. The
  639. dependencies and metadata are fetched from https://metacpan.org/.
  640. After running this script, it is necessary to check the generated files.
  641. You have to manually add the license files (PERL_FOO_LICENSE_FILES variable).
  642. For distributions that link against a target library, you have to add the
  643. buildroot package name for that library to the DEPENDENCIES variable.
  644. See the Buildroot documentation for details on the usage of the Perl
  645. infrastructure.
  646. The major version of the host perl must be aligned on the target one,
  647. in order to work with the right CoreList data.
  648. =head1 LICENSE
  649. Copyright (C) 2013-2017 by Francois Perrad <francois.perrad@gadz.org>
  650. This program is free software; you can redistribute it and/or modify
  651. it under the terms of the GNU General Public License as published by
  652. the Free Software Foundation; either version 2 of the License, or
  653. (at your option) any later version.
  654. This program is distributed in the hope that it will be useful,
  655. but WITHOUT ANY WARRANTY; without even the implied warranty of
  656. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  657. General Public License for more details.
  658. You should have received a copy of the GNU General Public License
  659. along with this program; if not, write to the Free Software
  660. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  661. This script is a part of Buildroot.
  662. This script requires the module C<MetaCPAN::API::Tiny> (version 1.131730)
  663. which was included at the beginning of this file by the tool C<fatpack>.
  664. See L<http://search.cpan.org/~nperez/MetaCPAN-API-Tiny-1.131730/>.
  665. See L<http://search.cpan.org/search?query=App-FatPacker&mode=dist>.
  666. These both libraries are free software and may be distributed under the same
  667. terms as perl itself.
  668. And perl may be distributed under the terms of Artistic v1 or GPL v1 license.
  669. =cut