/[gentoo-perl]/g-cpan/trunk/bin/g-cpan
Gentoo

Contents of /g-cpan/trunk/bin/g-cpan

Parent Directory Parent Directory | Revision Log Revision Log


Revision 154 - (show annotations) (download)
Wed Mar 21 15:03:04 2007 UTC (7 years, 8 months ago) by mcummings
File size: 37838 byte(s)
Added message for buildpkg users to update /etc/portage/packages, thanks fuzzyray :)
1 #!/usr/bin/perl -w
2 package main;
3
4 # Copyright 1999-2006 Gentoo Foundation
5 # Distributed under the terms of the GNU General Public License v2
6 #
7
8 # modules to use - these will need to be marked as
9 # dependencies, and installable by portage
10 use warnings;
11 use strict;
12 use File::Spec;
13 use File::Path;
14 use File::Basename;
15 use File::Copy;
16 use Term::ANSIColor;
17 use Cwd qw(getcwd abs_path cwd);
18 use YAML;
19 use YAML::Node;
20 use Carp;
21 use IO::File;
22 use DirHandle;
23
24 # Module load & configure
25 use Getopt::Long;
26 Getopt::Long::Configure("bundling");
27 use Log::Agent;
28 use Log::Agent::Driver::File;
29 use Log::Agent::Driver::Silent;
30
31 our $VERSION = "0.15_rc3";
32 my $prog = basename($0);
33
34 ##### Establish our tmpdir
35 unless ($ENV{TMPDIR}) { $ENV{TMPDIR} = '/var/tmp/g-cpan' }
36
37 my %dep_list = ();
38 my @perl_dirs = ("dev-perl", "perl-core", "perl-gcpan", "perl-text", "perl-tools", "perl-xml", "perl-dev", "dev-lang",);
39
40 ###############################
41 # Command line interpretation #
42 ###############################
43
44 # Declare options
45 # First, the main switches
46 my @main_switches = \my ($search, $list, $install, $generate, $buildpkgonly);
47
48 # Then, additional switches
49 my @additional_switches = \my ($upgrade, $pretend, $buildpkg, $ask);
50
51 # Then, the normal options
52 my ($debug, $verbose, $cpan_reload, $log);
53
54 # Set colors here so we can use them at will anywhere :)
55 my $green = color("bold green");
56 my $white = color("bold white");
57 my $cyan = color("bold cyan");
58 my $reset = color("reset");
59
60 #Get & Parse them
61 GetOptions(
62 'verbose|v' => \$verbose,
63 'search|s' => \$search,
64 'install|i' => \$install,
65 'upgrade|u' => \$upgrade,
66 'list|l' => \$list,
67 'log|L' => \$log,
68 'pretend|p' => \$pretend,
69 'buildpkg|b' => \$buildpkg,
70 'buildpkgonly|B' => \$buildpkgonly,
71 'ask|a' => \$ask,
72 'generate|g' => \$generate,
73 'debug|d' => \$debug,
74 'cpan_reload' => \$cpan_reload,
75 'help|h' => sub { exit_usage(); }
76 ) or exit_usage();
77
78 use lib "../lib";
79 use Gentoo;
80 use Gentoo::UI::Console;
81
82 if ($log)
83 {
84 open my $log_test, q{>>}, "/var/log/$prog/$prog.err"
85 or fatal(print_err("You don't have permission to perform logging to /var/log/$prog/$prog.err: $!"));
86 close($log_test);
87
88 my $log_driver = Log::Agent::Driver::File->make(
89 -prefix => "$prog",
90 -magic_open => 0,
91 -stampfmt => 'date',
92 -channels => {
93 'error' => "/var/log/$prog/$prog.err",
94 'output' => "/var/log/$prog/$prog.log",
95 }
96 );
97 logconfig(-driver => $log_driver);
98 }
99 else
100 {
101 my $log_driver = Log::Agent::Driver::Silent->make();
102 logconfig(-driver => $log_driver);
103 }
104
105 print_warn("*WARNING* - logging debug output can create large logs") if ($log && $debug);
106
107 if (($install || $ask || $buildpkg || $buildpkgonly || $upgrade) && $> > 0 && !$pretend)
108 {
109 print_err("INSUFFICIENT PERMISSIONS TO RUN EMERGE");
110 logerr("ERROR - INSUFFICIENT PERMISSIONS TO RUN EMERGE");
111 exit();
112 }
113
114 if (!$install && defined($ask))
115 {
116 $install = 1;
117 }
118
119 # Array containing the original values passed for installing
120 my %passed_to_install;
121
122 @ARGV > 0
123 and %passed_to_install = map { $_ => 1 } @ARGV;
124
125 # Array that will contain the portage friendly version of the values passed to install
126 my %really_install;
127
128 # Output error if more than one main switch is activated
129 #
130
131 if ((grep { defined $$_ } @main_switches) > 1)
132 {
133 print_err("You can't combine actions with each other.\n");
134 print_out("${white}Please consult ${cyan}$prog ${green}--help${reset} or ${cyan}man $prog${reset} for more information\n\n");
135 exit();
136 }
137
138 if (!grep { defined $$_ } @main_switches, @additional_switches)
139 {
140 print_err("You haven't told $prog what to do.\n");
141 print_out("${white}Please consult ${cyan}$prog ${green}--help${reset} or ${cyan}man $prog${reset} for more information\n\n");
142 exit();
143 }
144
145 # Output error if no arguments
146 if (@ARGV == 0 && !(defined $upgrade || defined $list))
147 {
148 print_err("Not even one module name or expression given!\n");
149 print_out("${white}Please consult ${cyan}$prog ${green}--help${reset} for more information\n\n");
150 exit();
151 }
152
153 ######################
154 # CPAN Special Stuff #
155 ######################
156
157 my $GentooCPAN = Gentoo->new();
158
159 # Don't do autointalls via ExtUtils::AutoInstall
160 $ENV{PERL_EXTUTILS_AUTOINSTALL} = "--skipdeps";
161 $ENV{PERL_MM_USE_DEFAULT} = 1;
162
163 # Do we need to generate a config ?
164 eval "use CPAN::Config;";
165 my $needs_cpan_stub = $@ ? 1 : 0;
166
167 # Test Replacement - ((A&B)or(C&B)) should be the same as ((A or C) and B)
168 if (($needs_cpan_stub || $> > 0) && !-f "$ENV{HOME}/.cpan/CPAN/MyConfig.pm")
169 {
170
171 # In case match comes from the UID test
172 $needs_cpan_stub = 1;
173
174 print_warn("No CPAN Config found, auto-generating a basic one");
175
176 # Generate a fake config for CPAN
177 $GentooCPAN->makeCPANstub();
178 }
179 else
180 {
181 $needs_cpan_stub = 0;
182 }
183
184 use CPAN;
185 $CPAN::Frontend = "Gentoo::CPAN::FakeFrontend";
186
187 {
188 foreach (qw[build sources])
189 {
190 if (-d "$ENV{TMPDIR}/.cpan/$_")
191 {
192 my $test_file = $ENV{TMPDIR} . "/.cpan/$_/test";
193 my $test_tmp = IO::File->new($test_file, '>');
194 if (defined($test_tmp))
195 {
196 undef $test_tmp;
197 unlink($test_file);
198 }
199 else
200 {
201 print_err("No WRITE permissions in $ENV{TMPDIR}/.cpan/$_!!");
202 print_err("Please run $prog as a user with sufficient permissions");
203 print_err("or correct permissions in $ENV{TMPDIR}");
204 exit;
205 }
206 }
207 }
208 }
209 ##########
210 # main() #
211 ##########
212
213 # Confirm that there is an /etc/portage/categories file
214 # and that we have an entry for perl-gcpan in it.
215 my $cat_file = "/etc/portage/categories";
216 if (-f "$cat_file")
217 {
218
219 #
220 # Use braces to localize the $/ assignment, so we don't get bitten later.
221 #
222 local $/ = undef;
223 my $cat_read = IO::File->new($cat_file, '<');
224 if (defined $cat_read)
225 {
226 my $data = <$cat_read>;
227 undef $cat_read;
228 autoflush STDOUT 1;
229 unless ($data =~ m{gcpan}gmxi)
230 {
231 my $cat_write = IO::File->new($cat_file, '>>');
232 if (defined $cat_write)
233 {
234 print $cat_write "perl-gcpan\n";
235 undef $cat_write;
236 autoflush STDOUT 1;
237 }
238 else
239 {
240 print_err("Insufficient permissions to edit /etc/portage/categories");
241 print_err("Please run $prog as a user with sufficient permissions");
242 exit;
243 }
244 }
245 }
246 }
247 else
248 {
249 my $cat_write = IO::File->new($cat_file, '>');
250 if (defined $cat_write)
251 {
252 print $cat_write "perl-gcpan";
253 }
254 else
255 {
256 print_err("Insufficient permissions to edit /etc/portage/categories");
257 print_err("Please run $prog as a user with sufficient permissions");
258 exit;
259 }
260 }
261
262 my $gcpan_run = Gentoo->new(
263 'cpan_reload' => $cpan_reload,
264 'DEBUG' => $debug,
265 );
266
267 # Get the main portdir
268 my $PORTAGE_DIR = $gcpan_run->getEnv('PORTDIR');
269 $gcpan_run->{portage_bases}{$PORTAGE_DIR} = 1;
270
271 # Grab the keywords - we'll need these when we build the ebuild
272 my $keywords = $gcpan_run->getEnv('ACCEPT_KEYWORDS');
273 if ($keywords =~ m{ACCEPT_KEYWORDS}) { $keywords="" }
274 $keywords ||= do
275 {
276 open my $tmp, '<', "$PORTAGE_DIR/profiles/arch.list"
277 or fatal(print_err("ERROR READING $PORTAGE_DIR/profiles/arch.list: $!"));
278 join ' ', map { chomp; $_ } <$tmp>;
279 };
280
281 $ENV{ACCEPT_KEYWORDS} = $keywords;
282 # Get the overlays
283 my $overlay = $gcpan_run->getEnv('PORTDIR_OVERLAY') || undef;
284 # Get the DISTDIR - we'd like store the tarballs in here the one time
285 $gcpan_run->{sources} = ($gcpan_run->getEnv('DISTDIR'));
286
287 # Make sure we have write access to the DISTDIR
288 if ( $generate
289 || $install
290 || $pretend
291 || $buildpkg
292 || $buildpkgonly
293 || $ask
294 || $upgrade)
295 {
296 my $test_dist_writes = $gcpan_run->{sources} . '/test-gcpan';
297 my $test_distdir = IO::File->new($test_dist_writes, '>');
298 if ($test_distdir)
299 {
300 undef $test_distdir;
301 unlink $test_dist_writes;
302 }
303 else
304 {
305 undef $test_distdir;
306 fatal(print_err("No write access to DISTDIR: $!"));
307 }
308 }
309
310 if ($overlay)
311 {
312 if ($overlay =~ m{\S*\s+\S*}x)
313 {
314 my @overlays = split ' ', $overlay;
315 foreach (@overlays)
316 {
317 $gcpan_run->{portage_bases}{$_} = 1 if (-d $_);
318 }
319 }
320 else
321 {
322 if (-d $overlay) { $gcpan_run->{portage_bases}{$overlay} = 1 }
323 }
324 unless (keys %{$gcpan_run->{portage_bases}} > 1)
325 {
326 fatal(print_err("DEFINED OVERLAYS DON'T EXIST!"));
327 }
328
329 }
330 elsif ($generate || $pretend)
331 {
332 print_err("The option you have chosen isn't supported without a configured overlay.\n");
333 exit();
334 }
335
336 # Set portage_categories to our defined list of perl_dirs
337 $gcpan_run->{portage_categories} = \@perl_dirs;
338
339 # Taking care of Searches.
340 if ($search)
341 {
342 foreach my $expr (@ARGV)
343 {
344 my $tree_expr = $expr;
345 $tree_expr =~ s/::/-/gxms;
346 scanTree(lc($tree_expr));
347 if (defined($gcpan_run->{portage}{lc($tree_expr)}{found}))
348 {
349 print_info("$gcpan_run->{portage}{lc($tree_expr)}{category}/$gcpan_run->{portage}{lc($tree_expr)}{name}");
350 my $tdesc = strip_ends($gcpan_run->{portage}{lc($tree_expr)}{DESCRIPTION});
351 my $thp = strip_ends($gcpan_run->{portage}{lc($tree_expr)}{HOMEPAGE});
352 print_info("DESCRIPTION: $tdesc");
353 print_info("HOMEPAGE: $thp");
354 }
355 else
356 {
357 print_info("No ebuild exists, pulling up CPAN listings for $expr");
358 my @search_results;
359
360 # Assume they gave us module-name instead of module::name
361 # which is bad, because CPAN can't convert it ;p
362
363 $verbose and print_info("Searching for $expr on CPAN");
364
365 # Let's define a CPAN::Frontend to use our printing methods
366
367 spinner_start();
368 if (!@search_results)
369 {
370 $expr =~ s{-}{::}gx;
371 my @hold = CPAN::Shell->i("/$expr/");
372 if (grep { /\S/ } @hold)
373 {
374 push @search_results, @hold;
375 }
376 }
377
378 # remove the spin
379 spinner_stop();
380
381 # now, @search_results should contain the matching modules strings, if any
382 if (@search_results)
383 {
384 print_info("Result(s) found :");
385 foreach (@search_results)
386 {
387 print_out("$_\n");
388 }
389 }
390 else
391 {
392 print_warn('no result found.');
393 }
394
395 }
396 }
397
398 exit;
399 }
400
401 if ($list || $upgrade)
402 {
403 if ($upgrade && @ARGV > 0)
404 {
405 %passed_to_install = map { $_ => 1 } @ARGV;
406 }
407 else
408 {
409 my @overlays = split ' ', $overlay;
410 foreach my $overlay_dir (@overlays)
411 {
412 my $gcpan_dir = File::Spec->catdir($overlay_dir, 'perl-gcpan');
413
414 #$list and print_info("OVERLAY: $gcpan_dir");
415 print_info("OVERLAY: $gcpan_dir");
416 if (opendir PDIR, $gcpan_dir)
417 {
418 while (my $file = readdir PDIR)
419 {
420 next if ($file eq '.' || $file eq '..');
421 $list and print_info("perl-gcpan/$file");
422 $upgrade and $passed_to_install{$file} = 1;
423 }
424 closedir PDIR;
425 }
426 else
427 {
428 print_warn("Couldn't open folder $gcpan_dir: $!");
429 }
430 }
431 }
432 }
433
434 if ( $generate
435 || $install
436 || $pretend
437 || $buildpkg
438 || $buildpkgonly
439 || $ask
440 || $upgrade)
441 {
442 generatePackageInfo($_) foreach (keys %passed_to_install);
443 }
444
445 if (($install || $pretend || $buildpkg || $buildpkgonly || $upgrade || $ask)
446 && !( $generate))
447 {
448 if (keys %really_install)
449 {
450
451 my @ebuilds = (keys %really_install);
452 $verbose and print_info("Calling emerge for @ebuilds\n");
453 my @flags;
454 if ($pretend && $pretend > 0) { push @flags, '--pretend' }
455 if ($ask && $ask > 0) { push @flags, '--ask' }
456 if ($buildpkg && $buildpkg > 0) { push @flags, '--buildpkg' }
457 if ($buildpkgonly && $buildpkgonly > 0) { push @flags, '--buildpkgonly' }
458
459 $verbose and print_info("Calling: emerge @flags @ebuilds");
460 $gcpan_run->emerge_ebuild(@ebuilds, @flags);
461
462 }
463 else
464 {
465 if ($upgrade)
466 {
467 print_info('Everything was up to date, nothing to do!');
468 }
469 else
470 {
471 print_err('Nothing to install!!');
472 }
473 }
474 }
475
476 sub generatePackageInfo
477 {
478
479 # Since all we are concerned with is the final name of the package, this
480 # should be a safe substitution
481 my ($ebuild_wanted) = @_;
482 $ebuild_wanted =~ m{ExtUtils(::|-)MakeMaker}ix
483 and print_info('Skipping ExtUtils::MakeMaker dependency'), next;
484
485 #In the event this is an upgrade, go ahead and do the lame s/-/::/
486 $upgrade and $ebuild_wanted =~ s/-/::/gxms;
487
488 # Grab specific info for this module
489 spinner_start();
490 unless (defined($gcpan_run->{portage}{lc($ebuild_wanted)}{found}))
491 {
492
493 # First, check to see if this came with the core perl install
494 my $pkgdbdir = "/var/db/pkg/dev-lang/";
495 my $s_perl = new DirHandle($pkgdbdir);
496 my $eb = $ebuild_wanted;
497 $eb =~ s{::}{/}gxs;
498 while (defined(my $read = $s_perl->read))
499 {
500 if ((-d $pkgdbdir . "/" . $read) and ($read =~ m{^perl}x))
501 {
502 open(FH, "<$pkgdbdir/$read/CONTENTS") || die("Cannot open $read\'s CONTENTS");
503 my @data = <FH>;
504 close(FH);
505 foreach (@data)
506 {
507 my $thisfile = (split(/ /, $_))[1];
508 $thisfile =~ s{\.([A-Za-z]{1,3})$}{};
509 if ($thisfile =~ m{$eb}x)
510 {
511 print_info("$ebuild_wanted is part of the core perl install");
512 return;
513 }
514 }
515 last;
516 }
517 }
518
519 unless (defined($upgrade) or defined($passed_to_install{$ebuild_wanted}))
520 {
521
522 # If we're still here, then we didn't come with perl
523 $gcpan_run->getCPANInfo($ebuild_wanted);
524 }
525 }
526 spinner_stop();
527 if (!$gcpan_run->{cpan}{lc($ebuild_wanted)} && !defined($gcpan_run->{portage}{lc($ebuild_wanted)}{found}))
528 {
529
530 # Fallback to trying the /-/::/ trick - we avoid this the first time
531 # in case the module actually employs a - in its name
532 $ebuild_wanted =~ s/-/::/gxms;
533 $verbose and print_info("Getting CPAN Info for $ebuild_wanted");
534 spinner_start();
535 $gcpan_run->getCPANInfo($ebuild_wanted);
536 spinner_stop();
537 }
538
539 # If we found something on cpan, transform the portage_name
540 # It's possible to not find something on cpan at this point - we're just
541 # trying to pre-seed the portage_name
542 if ($gcpan_run->{cpan}{lc($ebuild_wanted)})
543 {
544 spinner_start();
545 $gcpan_run->{cpan}{lc($ebuild_wanted)}{portage_name} = $gcpan_run->transformCPAN($gcpan_run->{cpan}{lc($ebuild_wanted)}{src_uri}, 'n');
546 $gcpan_run->{cpan}{lc($ebuild_wanted)}{portage_version} = $gcpan_run->transformCPAN($gcpan_run->{cpan}{lc($ebuild_wanted)}{src_uri}, 'v');
547 spinner_stop();
548 }
549 else
550 {
551 print_err("$ebuild_wanted is not a CPAN module!");
552 }
553
554 # Save a copy of the originally requested name for later use
555 my $original_ebuild = $ebuild_wanted;
556
557 # Simple transform of name to something portage friendly
558 $ebuild_wanted =~ s/::/-/gxms;
559
560 # Scan portage for the ebuild name
561 if ( ($upgrade && !defined($passed_to_install{$ebuild_wanted}))
562 || (!$upgrade && defined($passed_to_install{$ebuild_wanted}))
563 || (!$upgrade && !defined($gcpan_run->{portage}{lc($ebuild_wanted)}{found})))
564 {
565
566 # Ebuild wasn't found - scan for the nice version of the module name
567 if (lc($gcpan_run->{cpan}{lc($original_ebuild)}{portage_name}) eq 'perl') { return }
568 scanTree($gcpan_run->{cpan}{lc($original_ebuild)}{portage_name});
569
570 # We had success in finding this module under a different name
571 if (defined($gcpan_run->{portage}{lc($gcpan_run->{cpan}{lc($original_ebuild)}{portage_name})}{found}))
572 {
573 $verbose and print_info('Found ebuild under CPAN name (' . $gcpan_run->{cpan}{lc($original_ebuild)}{portage_name} . ')');
574 $ebuild_wanted = $gcpan_run->{cpan}{lc($original_ebuild)}{portage_name};
575 }
576 }
577 else
578 {
579 $gcpan_run->{cpan}{lc($original_ebuild)}{portage_name} = $ebuild_wanted;
580 }
581
582 # Second round - we've looked for the package in portage two different
583 # ways now, time to get serious and create it ourselves
584 if (!defined($gcpan_run->{portage}{lc($ebuild_wanted)}{found}))
585 {
586
587 # Generate info - nothing found currently in the tree
588 $debug and $gcpan_run->debug;
589 if ($gcpan_run->{cpan}{lc($original_ebuild)}{portage_name}
590 && lc($gcpan_run->{cpan}{lc($original_ebuild)}{portage_name}) ne 'perl')
591 {
592
593 # We have a cpan package that matches the request.
594 # Let's unpack it and get all the deps out of it.
595 spinner_start();
596 $gcpan_run->unpackModule($gcpan_run->{cpan}{lc($original_ebuild)}{name});
597 spinner_stop();
598
599 foreach my $dep (keys %{$gcpan_run->{cpan}{lc($original_ebuild)}{depends}})
600 {
601 defined $dep && $dep ne '' or next;
602 #next if (defined $dep && $dep ne '');
603 $dep eq 'perl' and delete $gcpan_run->{cpan}{lc($original_ebuild)}{depends}{$dep};
604
605 $dep =~ m{ExtUtils(::|-)MakeMaker}ix and print_info("Skipping ExtUtils::MakeMaker dependency"), next;
606
607 # Make sure we have information relevant to each of the deps
608 $verbose and print_info("Checking on dependency $dep for $original_ebuild");
609 $passed_to_install{$dep} or generatePackageInfo($dep);
610
611 # Remove dep from list of modules to install later on - no
612 # more dup'd installs!
613 defined $passed_to_install{$dep} and delete $really_install{$dep};
614
615 # Reindex one last time for anything we build after the fact
616 scanTree($gcpan_run->{cpan}{lc($dep)}{portage_name});
617 }
618
619 # Write ebuild here?
620 $debug and $gcpan_run->debug;
621 my @overlays = [];
622 if ($overlay) { @overlays = split ' ', $overlay }
623 else
624 {
625 push @overlays, "/var/tmp/g-cpan"
626 and $ENV{PORTDIR_OVERLAY} = "/var/tmp/g-cpan";
627 }
628 foreach my $target_dir (@overlays)
629 {
630 if (-d $target_dir)
631 {
632 my $gcpan_dir = File::Spec->catdir($target_dir, 'perl-gcpan');
633 if (!-d $gcpan_dir)
634 {
635 $verbose and print_info("Create directory '$gcpan_dir'");
636 mkdir($gcpan_dir, 0755)
637 or fatal(print_err("Couldn't create folder $gcpan_dir: $!"));
638 }
639 my $ebuild_dir = File::Spec->catdir($gcpan_dir, $gcpan_run->{cpan}{lc($original_ebuild)}{portage_name});
640 if (!-d $ebuild_dir)
641 {
642 $verbose and print_info("Create directory '$ebuild_dir'");
643 mkdir($ebuild_dir, 0755)
644 or fatal(print_err("Couldn't create folder $gcpan_dir: $!"));
645 }
646 my $files_dir = File::Spec->catdir($ebuild_dir, 'files');
647 if (!-d $files_dir)
648 {
649 $verbose and print_info("Create directory '$files_dir'");
650 mkdir($files_dir, 0755)
651 or fatal(print_err("Couldn't create folder $gcpan_dir: $!"));
652 }
653 my $ebuild = File::Spec->catdir($ebuild_dir,
654 $gcpan_run->{cpan}{lc($original_ebuild)}{portage_name} . '-' . $gcpan_run->{cpan}{lc($original_ebuild)}{portage_version} . '.ebuild');
655
656 # Break out if we already have an ebuild (upgrade or
657 # mistake in the code)
658 if (!-f $ebuild)
659 {
660 print_info('Generating ebuild for ' . $gcpan_run->{cpan}{lc($original_ebuild)}{name});
661 my $EBUILD = IO::File->new($ebuild, '>')
662 or fatal(print_err("Couldn't open(write) file $ebuild: $!"));
663 print $EBUILD <<"HERE";
664 # Copyright 1999-2006 Gentoo Foundation
665 # Distributed under the terms of the GNU General Public License v2
666 # This ebuild generated by $prog $VERSION
667
668 inherit perl-module
669
670 S=\${WORKDIR}/$gcpan_run->{'cpan'}{lc($original_ebuild)}{'portage_sdir'}
671
672 DESCRIPTION="$gcpan_run->{'cpan'}{lc($original_ebuild)}{'description'}"
673 HOMEPAGE="http://search.cpan.org/search?query=$gcpan_run->{cpan}{lc($original_ebuild)}{portage_name}\&mode=dist"
674 SRC_URI="mirror://cpan/authors/id/$gcpan_run->{'cpan'}{lc($original_ebuild)}{'src_uri'}"
675
676
677 IUSE=""
678
679 SLOT="0"
680 LICENSE="|| ( Artistic GPL-2 )"
681 KEYWORDS="$keywords"
682
683 HERE
684
685 if (my @deps = keys %{$gcpan_run->{cpan}{lc($original_ebuild)}{depends}})
686 {
687 print $EBUILD "DEPEND=\"";
688 my %seen_deps;
689 foreach my $dep (@deps)
690 {
691 defined $dep && $dep ne '' or next;
692 my $portage_name = lc($gcpan_run->{cpan}{lc($dep)}{portage_name});
693 $portage_name =~ m{\S}x or next;
694
695 # Last ditch call to scanTree to make sure we
696 # have info
697 scanTree($portage_name);
698 next if ( defined($seen_deps{$portage_name}) && $seen_deps{$portage_name} > 0 );
699 $seen_deps{$portage_name} = 1;
700 next
701 unless (defined($gcpan_run->{portage}{$portage_name}{category})
702 && defined($gcpan_run->{portage}{$portage_name}{name}) && ($gcpan_run->{portage}{$portage_name}{name} =~ m/\S/));
703 $portage_name eq 'perl' || lc($portage_name) eq lc($gcpan_run->{cpan}{lc($original_ebuild)}{portage_name})
704 and next;
705 my ($eb_version, $cpan_version) =
706 stripdown($gcpan_run->{portage}{lc($portage_name)}{version}, $gcpan_run->{cpan}{lc($dep)}{portage_version});
707
708 #my $eb_version = stripdown($gcpan_run->{portage}{lc($portage_name)}{version});
709 #my $cpan_version = defined($gcpan_run->{cpan}{lc($dep)}{portage_version})? stripdown($gcpan_run->{cpan}{lc($dep)}{portage_version}): "0";
710 if ( defined($gcpan_run->{cpan}{lc($dep)}{portage_version})
711 && $gcpan_run->{cpan}{lc($original_ebuild)}{depends}{$dep} ne '0'
712 && int($eb_version) >= int($cpan_version)
713 && $gcpan_run->{cpan}{lc($original_ebuild)}{depends}{$dep} =~ m{\d}gx
714 && $gcpan_run->{portage}{$portage_name}{name} ne "module-build")
715 {
716 print $EBUILD "\>\="
717 . $gcpan_run->{portage}{$portage_name}{category} . '/'
718 . $gcpan_run->{portage}{$portage_name}{name} . '-';
719 if (defined($eb_version))
720 {
721 print $EBUILD $gcpan_run->{portage}{lc($portage_name)}{version};
722 }
723 else
724 {
725 print $EBUILD $gcpan_run->{cpan}{lc($dep)}{portage_version};
726 }
727 print $EBUILD "\n\t";
728 }
729 else
730 {
731 print $EBUILD ""
732 . $gcpan_run->{portage}{$portage_name}{category} . "/"
733 . $gcpan_run->{portage}{$portage_name}{name} . "\n\t";
734 }
735 }
736 print $EBUILD "dev-lang/perl\"\n";
737 if (defined($buildpkg) or defined($buildpkgonly)) {
738 print $EBUILD "\npkg_postinst() {\n";
739 print $EBUILD "elog \"If you redistribute this package, please remember to\"\n";
740 print $EBUILD "elog \"update /etc/portage/packages with an entry for perl-gpcan\"\n";
741
742 print $EBUILD "}\n";
743 }
744 undef $EBUILD;
745 autoflush STDOUT 1;
746 }
747 if (-f $gcpan_run->{cpan}{lc($original_ebuild)}{cpan_tarball})
748 {
749 $verbose and print_ok("Copying $gcpan_run->{cpan}{lc($original_ebuild)}{cpan_tarball} to $gcpan_run->{sources}");
750 copy($gcpan_run->{cpan}{lc($original_ebuild)}{cpan_tarball}, $gcpan_run->{sources});
751 }
752 print_info("Ebuild generated for $ebuild_wanted");
753 $gcpan_run->generate_digest($ebuild);
754 if (
755 !$upgrade
756 || ($upgrade
757 && defined($passed_to_install{$gcpan_run->{'cpan'}->{lc($original_ebuild)}->{'name'}}))
758 )
759 {
760 my $portage_name = $gcpan_run->{'cpan'}->{lc($original_ebuild)}->{'portage_name'};
761 $really_install{$portage_name} = 1;
762 }
763 last;
764 }
765 else
766 {
767 $upgrade and print_info("$ebuild_wanted already up to date") and last;
768 my $portage_name = $gcpan_run->{'cpan'}->{lc($original_ebuild)}->{'portage_name'};
769 $really_install{$portage_name} = 1;
770 }
771 }
772 }
773 }
774 }
775 else
776 {
777 print_ok("Ebuild already exists for $ebuild_wanted");
778 if ( defined $passed_to_install{$ebuild_wanted} || defined $passed_to_install{$original_ebuild} )
779 { $really_install{$gcpan_run->{portage}{lc($ebuild_wanted)}{'name'}} = 1 }
780 }
781 return;
782 }
783
784 sub scanTree
785 {
786 my ($module) = @_;
787 $module or return;
788
789 if ($module =~ /pathtools/gimx) { $module = "File-Spec" }
790 foreach my $portage_root (keys %{$gcpan_run->{portage_bases}})
791 {
792 if (-d $portage_root)
793 {
794 $verbose and print_ok("Scanning $portage_root for $module");
795 $gcpan_run->getAvailableVersions($portage_root, $module);
796 }
797
798 # Pop out of the loop if we've found the module
799 defined($gcpan_run->{portage}{lc($module)}{found}) and last;
800 }
801 return;
802 }
803
804 sub strip_ends
805 {
806 my $key = shift;
807 if (defined($ENV{$key}))
808 {
809 $ENV{$key} =~ s{\\n}{ }gxms;
810 $ENV{$key} =~ s{\\|\'|\\'|\$|\s*$}{}gmxs;
811
812 #$ENV{$key} =~ s{\'|^\\|\$|\s*\\.\s*|\\\n$}{}gmxs;
813 return $ENV{$key};
814 }
815 else
816 {
817 $key =~ s{\\n}{ }gxms;
818
819 #$key =~ s{\'|^\\|\$|\s*\\.\s*|\\\n$}{}gmxs;
820 $key =~ s{(\'|\\|\\'|\$|\s*$)}{}gmxs;
821
822 return $key;
823 }
824 }
825
826 sub stripdown
827 {
828 my ($eb, $mod) = @_;
829 $eb =~ s{_|-|\D+}{}gmxi;
830 $mod =~ s{_|-|\D+}{}gmxi;
831
832 if ($eb =~ m{^\.}x) { $eb = "00$eb" }
833 if ($mod =~ m{^\.}x) { $mod = "00$mod" }
834 my $e_in = "";
835 my $m_in = "";
836
837 my (@eb_ver) = split(/\./, $eb);
838 my (@mod_ver) = split(/\./, $mod);
839
840 my $num_e = @eb_ver;
841 my $num_m = @mod_ver;
842
843 if ($num_e == $num_m)
844 {
845 for (my $x = 0; $x <= ($num_e - 1); $x++)
846 {
847 if (length($eb_ver[$x]) > length($mod_ver[$x]))
848 {
849 while (length($eb_ver[$x]) > length($mod_ver[$x]))
850 {
851 $mod_ver[$x] .= "0";
852 }
853 }
854 if (length($mod_ver[$x]) > length($eb_ver[$x]))
855 {
856 while (length($mod_ver[$x]) > length($eb_ver[$x]))
857 {
858 $eb_ver[$x] .= "0";
859 }
860 }
861 $e_in .= "$eb_ver[$x]";
862 $m_in .= "$mod_ver[$x]";
863 }
864 }
865 elsif ($num_e > $num_m)
866 {
867 for (my $x = 0; $x <= ($num_e - 1); $x++)
868 {
869 unless ($mod_ver[$x])
870 {
871 $mod_ver[$x] = "00";
872 }
873 if (length($eb_ver[$x]) > length($mod_ver[$x]))
874 {
875 while (length($eb_ver[$x]) > length($mod_ver[$x]))
876 {
877 $mod_ver[$x] .= "0";
878 }
879 }
880 if (length($mod_ver[$x]) > length($eb_ver[$x]))
881 {
882 while (length($mod_ver[$x]) > length($eb_ver[$x]))
883 {
884 $eb_ver[$x] .= "0";
885 }
886 }
887 $e_in .= "$eb_ver[$x]";
888 $m_in .= "$mod_ver[$x]";
889 }
890 }
891 elsif ($num_e < $num_m)
892 {
893 for (my $x = 0; $x <= ($num_m - 1); $x++)
894 {
895 unless ($eb_ver[$x])
896 {
897 $eb_ver[$x] = "00";
898 }
899 if (length($eb_ver[$x]) > length($mod_ver[$x]))
900 {
901 while (length($eb_ver[$x]) > length($mod_ver[$x]))
902 {
903 $mod_ver[$x] .= "0";
904 }
905 }
906 if (length($mod_ver[$x]) > length($eb_ver[$x]))
907 {
908 while (length($mod_ver[$x]) > length($eb_ver[$x]))
909 {
910 $eb_ver[$x] .= "0";
911 }
912 }
913 $e_in .= "$eb_ver[$x]";
914 $m_in .= "$mod_ver[$x]";
915 }
916 }
917 $e_in =~ s{\.$}{}x;
918 $m_in =~ s{\.$}{}x;
919 return ($eb, $mod);
920 }
921
922 # cab - Takes care of system's sanity
923 END
924 {
925
926 #Clean out the /tmp tree we were using
927 #I know this looks weird, but since clean_up is invoked on a search, where OVERLAYS isn't ever defined,
928 # we first need to see if it exists, then need to remove only if it has content (the old exists vs. defined)
929
930 if (defined($ENV{TMPDIR}))
931 {
932 $verbose and print_ok('Cleaning temporary space');
933 my ($startdir) = cwd();
934 chdir("$ENV{TMPDIR}/.cpan");
935 opendir(CURD, '.');
936 my @dirs = readdir(CURD);
937 closedir(CURD);
938 foreach my $dir (@dirs)
939 {
940 $dir eq '.' and next;
941 $dir eq '..' and next;
942 $dir eq 'sources' and next;
943 -d $dir and rmtree(["$ENV{TMPDIR}/.cpan/$dir"]);
944 }
945 if (-d "$ENV{TMPDIR}/perl-gcpan") { rmtree(["$ENV{TMPDIR}/perl-gcpan"]) }
946 }
947 }
948
949 # cab - nice help message ! ;)
950 sub exit_usage
951 {
952 print <<"USAGE";
953 ${white}Usage : ${cyan}$prog ${green}<Switch(es)> ${cyan}Module Name(s)${reset}
954
955 ${green}--generate,-g${reset}
956 Generate ebuilds only (Requires working overlays)
957
958 ${green}--install,-i${reset}
959 Try to generate ebuild for the given module name
960 and, if successful, emerge it. Important : installation
961 requires exact CPAN Module Name.
962
963 ${green}--list,-l${reset}
964 This command generates a list of the Perl modules and ebuilds
965 handled by $prog.
966
967 ${green}--log,-L${reset}
968 Log the output of $prog.
969
970 ${green}--search,-s${reset}
971 Search CPAN for the given expression (similar to
972 the "m /EXPR/" from the CPAN Shell). Searches are
973 case insensitive.
974
975 ${green}--upgrade,-u${reset}
976 Try to list and upgrade all Perl modules managed by $prog.
977 It generate up-to-date ebuilds, then emerge then.
978
979 ${green}--verbose,-v${reset}
980 Enable (some) verbose output.
981
982 ${green}--cpan_reload${reset}
983 Reload the CPAN index
984
985 ${white}Portage related options${reset}
986
987 ${green}--ask,-a${reset}
988 Ask before installing
989
990 ${green}--buildpkg,-b${reset}
991 Tells emerge to build binary packages for all ebuilds processed
992 in addition to actually merging the packages.
993
994 ${green}--buildpkgonly,-B${reset}
995 Creates binary packages for all ebuilds processed without actu-
996 ally merging the packages.
997
998 ${green}--pretend,-p${reset}
999 Pretend (show actions, but don't emerge). This still generates
1000 new ebuilds.
1001
1002
1003 USAGE
1004
1005 exit;
1006 }
1007
1008 exit;
1009
1010 ##############
1011
1012 __END__
1013
1014 =pod
1015
1016 =head1 NAME
1017
1018 g-cpan - install CPAN-provided Perl modules using Gentoo's Portage
1019
1020 =head1 SYNOPSIS
1021
1022 B<g-cpan> [B<-a>| B<--ask>] [B<-g>| B<--generate>] [B<-i>| B<--install>] [B<-l>| B<--list >] [B<-p>| B<--pretend >] [B<-s>| B<--search>] [B<-u>| B<--upgrade >] [B<-v>| B<--verbose>] <I<module-name>>
1023
1024 =head1 DESCRIPTION
1025
1026 B<g-cpan> is a perl script that installs a CPAN module (including its dependencies) using Gentoo's Portage. It saves dependency information and stored files as if they were installed through a regular ebuild.
1027
1028 =head1 CPAN Configuration
1029
1030 B<~/.cpan/CPAN/MyConfig.pm>
1031 B</path/to/perl/CPAN/Config.pm>
1032
1033 When you run B<g-cpan>, it will check for two configuration files. If you are root, it will check for the presense of an already configured CPAN under your perl install path. If CPAN is not configured, or you are not root, g-cpan will create a generic configuration for CPAN in ~/.cpan/CPAN/ called MyConfig.pm. You can modify this file as needed at any time.
1034
1035 The CPAN configuration file is used for interacting with CPAN, determining what modules are available, what modules are needed, and performing all basic CPAN functions.
1036
1037 =head1 g-cpan and Overlays
1038
1039 B<g-cpan> is now overlay "friendly." B<g-cpan> will scan both the overlays provided in your make.conf as well as any you have set via environment variables, to help determine its course of action. If you have defined overlays, B<g-cpan> will use the first overlay in your list that the user running it can write to. Any ebuilds generated by B<g-cpan> will be stored in this overlay for future use (such as upgrading).
1040
1041 If no overlays are defined, or the user operating B<g-cpan> cannot write to an overlay, then anything generated will be written to a temporary space and wiped on exit.
1042
1043 =head1 Arguments
1044
1045 The following arguments are accepted by g-cpan.
1046
1047 =over 4
1048
1049 =item B<-g,--generate>
1050
1051 Generate ebuilds and drop them in the overlay, but never call portage. Useful for generating a tree of ebuilds without having permissions to portage.
1052
1053 =item B<-i,--install>
1054
1055 Install the (list of) modules provided.
1056
1057 =item B<-l,--list>
1058
1059 List ebuilds that have been generated by g-cpan and reside in your overlay.
1060
1061 =item B<-L,--log>
1062
1063 Log all output to /var/log/g-cpan/g-cpan.log and g-cpan.err
1064
1065 =item B<-s,--search>
1066
1067 Search CPAN for the provided module.
1068
1069 =item B<--cpan_reload>
1070
1071 Reload CPAN's index online
1072
1073 =item B<-u,--upgrade>
1074
1075 Attempt to upgrade any ebuilds generated by g-cpan to newer versions. This option will create new ebuilds for those that exist in your overlay already. If a module name is given, it will attempt to only upgrade the requested module. If no arguments are given, all modules in your g-cpan overlay will be checked.
1076
1077 =item B<-v,--verbose>
1078
1079 Enable verbose mode for more feedback on the step by step processes that g-cpan is running
1080
1081 =back
1082
1083 =head1 Portage Arguments
1084
1085 The following portage arguments can be passed to g-cpan. Please read the portage documentation for more information on how they work.
1086
1087 =over 4
1088
1089 =item B<-a,--ask>
1090
1091 Pass the "ask" argument to portage. This will cause portage to prompt you to confirm your installation prior to issuing an emerge
1092
1093 =item B<-b,--buildpkg>
1094
1095 Tells emerge to build binary packages for all ebuilds processed in addition to actually merging the packages.
1096
1097 =item B<-B,--buildpkgonly>
1098
1099 Creates binary packages for all ebuilds processed without actually merging the packages.
1100
1101 =item B<-p,--pretend>
1102
1103 Create ebuilds as needed for the (list of) modules provided, but don't perform the actual emerge.
1104
1105
1106 =back
1107
1108 =head1 Usage
1109
1110
1111 =head2 Here we install Jabber::RPC
1112
1113 # g-cpan -i Jabber::RPC
1114
1115 =head2 Performing a search
1116
1117 # g-cpan -s Clone::Any
1118
1119 =head2 Upgrading overlay from g-cpan
1120
1121 # g-cpan -u
1122
1123 =head2 Upgrading specifc ebuild in overlay from g-cpan
1124
1125 # g-cpan -u Mickey-Mouse
1126
1127 =head1 Todo
1128
1129 =head1 See Also
1130
1131 L<B<emerge>(1)>, L<B<ebuild>(5)>, L<B<make.conf>(5)>, L<B<perl>(1)>
1132
1133 =head1 Authors
1134
1135 mcummings <mcummings@gentoo.org> cab <cab@dragou.net> sniper <sniper@mongueurs.net> beu <beu@gentoo.org> J Robert Ray <jrray@gentoo.org> (g-cpan) RAC <rac@gentoo.org> Sven Vermeulen <swift@gentoo.org> (Original manpage) Damien Krotkine <dams@gentoo.org>
1136
1137 =head1 Reporting Bugs
1138
1139 Please report bugs via http://bugs.gentoo.org/ or https://bugs.gentoo.org/
1140
1141 =head1 svn Id $Id$
1142
1143 =cut

Properties

Name Value
svn:executable *
svn:keywords Id

  ViewVC Help
Powered by ViewVC 1.1.20