/[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 137 - (show annotations) (download)
Fri Jan 5 18:43:32 2007 UTC (7 years, 6 months ago) by mcummings
File size: 31417 byte(s)
Bug 160137, strip_ends cleanup on env imports.


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 strict;
11 use File::Spec;
12 use File::Path;
13 use File::Basename;
14 use File::Copy;
15 use Term::ANSIColor;
16 use Cwd qw(getcwd abs_path cwd);
17 use YAML;
18 use YAML::Node;
19 use Carp;
20 use IO::File;
21 # Module load & configure
22 use Getopt::Long;
23 Getopt::Long::Configure("bundling");
24 use Log::Agent;
25 use Log::Agent::Driver::File;
26 use Log::Agent::Driver::Silent;
27
28 use constant PATH_PKG_VAR => '/var/db/pkg/';
29 our $VERSION = "0.15_rc2";
30 my $prog = basename($0);
31
32 ##### Establish our tmpdir
33 unless ($ENV{TMPDIR}) { $ENV{TMPDIR} = '/var/tmp/g-cpan' }
34
35
36
37
38 my %dep_list = ();
39 my @perl_dirs = ("dev-perl", "perl-core", "perl-gcpan", "perl-text", "perl-tools", "perl-xml", "perl-dev", "dev-lang",);
40
41 ###############################
42 # Command line interpretation #
43 ###############################
44
45
46 # Declare options
47 # First, the main switches
48 my @main_switches = \my ($search, $list, $install, $generate, $buildpkgonly);
49 # Then, additional switches
50 my @additional_switches = \my ($upgrade, $pretend, $buildpkg, $ask);
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 open my $log_test, q{>>}, "/var/log/$prog/$prog.err" or
84 fatal(print_err("You don't have permission to perform logging to /var/log/$prog/$prog.err: $!"));
85 close($log_test);
86
87 my $log_driver = Log::Agent::Driver::File->make(
88 -prefix => "$prog",
89 -magic_open => 0,
90 -stampfmt => 'date',
91 -channels => {
92 'error' =>"/var/log/$prog/$prog.err",
93 'output' => "/var/log/$prog/$prog.log",
94 }
95 );
96 logconfig(-driver => $log_driver);
97 } else {
98 my $log_driver = Log::Agent::Driver::Silent->make();
99 logconfig(-driver => $log_driver);
100 }
101
102 $log && $debug and
103 print_warn("*WARNING* - logging debug output can create large logs");
104
105 if ( ($install || $ask || $buildpkg || $buildpkgonly || $upgrade) && $> > 0 && !$pretend) {
106 print_err("INSUFFICIENT PERMISSIONS TO RUN EMERGE");
107 logerr("ERROR - INSUFFICIENT PERMISSIONS TO RUN EMERGE");
108 exit();
109 }
110
111 if (! $install && defined($ask))
112 {
113 $install = 1
114 }
115
116 # Array containing the original values passed for installing
117 my %passed_to_install;
118
119 @ARGV > 0 and
120 %passed_to_install = map { $_ => 1 } @ARGV;
121
122
123 # Array that will contain the portage friendly version of the values passed to install
124 my %really_install;
125
126 # Output error if more than one main switch is activated
127 #
128
129 if ( (grep { defined $$_ } @main_switches) > 1) {
130 print_err("You can't combine actions with each other.\n");
131 print_out("${white}Please consult ${cyan}$prog ${green}--help${reset} or ${cyan}man $prog${reset} for more information\n\n");
132 exit();
133 }
134
135 if ( ! grep { defined $$_ } @main_switches, @additional_switches ) {
136 print_err("You haven't told $prog what to do.\n");
137 print_out("${white}Please consult ${cyan}$prog ${green}--help${reset} or ${cyan}man $prog${reset} for more information\n\n");
138 exit();
139 }
140
141 # Output error if no arguments
142 if (@ARGV == 0 && !(defined $upgrade || defined $list )) {
143 print_err("Not even one module name or expression given!\n");
144 print_out("${white}Please consult ${cyan}$prog ${green}--help${reset} for more information\n\n");
145 exit();
146 }
147
148 ######################
149 # CPAN Special Stuff #
150 ######################
151
152 my $GentooCPAN = Gentoo->new();
153
154 # Don't do autointalls via ExtUtils::AutoInstall
155 $ENV{PERL_EXTUTILS_AUTOINSTALL} = "--skipdeps";
156 $ENV{PERL_MM_USE_DEFAULT} = 1;
157
158 # Do we need to generate a config ?
159 eval "use CPAN::Config;";
160 my $needs_cpan_stub = $@ ? 1 : 0;
161
162 # Test Replacement - ((A&B)or(C&B)) should be the same as ((A or C) and B)
163 if ( ($needs_cpan_stub || $> > 0) && ! -f "$ENV{HOME}/.cpan/CPAN/MyConfig.pm") {
164
165 # In case match comes from the UID test
166 $needs_cpan_stub = 1;
167
168 print_warn("No CPAN Config found, auto-generating a basic one");
169
170 # Generate a fake config for CPAN
171 $GentooCPAN->makeCPANstub();
172 } else {
173 $needs_cpan_stub = 0;
174 }
175
176 use CPAN;
177 $CPAN::Frontend = "Gentoo::CPAN::FakeFrontend";
178
179 {
180 foreach (qw[build sources]) {
181 if ( -d "$ENV{TMPDIR}/.cpan/$_" ) {
182 my $test_file = $ENV{TMPDIR}."/.cpan/$_/test";
183 my $test_tmp = IO::File->new($test_file, '>');
184 if ( defined($test_tmp) )
185 {
186 undef $test_tmp;
187 unlink($test_file)
188 } else {
189 print_err("No WRITE permissions in $ENV{TMPDIR}/.cpan/$_!!");
190 print_err("Please run $prog as a user with sufficient permissions");
191 print_err("or correct permissions in $ENV{TMPDIR}");
192 exit;
193 }
194 }
195 }
196 }
197 ##########
198 # main() #
199 ##########
200
201 # Confirm that there is an /etc/portage/categories file
202 # and that we have an entry for perl-gcpan in it.
203 my $cat_file = "/etc/portage/categories";
204 if (-f "$cat_file") {
205
206 #
207 # Use braces to localize the $/ assignment, so we don't get bitten later.
208 #
209 local $/ = undef;
210 my $cat_read = IO::File->new($cat_file, '<');
211 if (defined $cat_read) {
212 my $data = <$cat_read>;
213 undef $cat_read;
214 autoflush STDOUT 1;
215 unless ( $data =~ m{gcpan}gmxi ) {
216 my $cat_write = IO::File->new($cat_file, '>>');
217 if (defined $cat_write) {
218 print $cat_write "perl-gcpan\n";
219 undef $cat_write;
220 autoflush STDOUT 1;
221 } else {
222 print_err("Insufficient permissions to edit /etc/portage/categories");
223 print_err("Please run $prog as a user with sufficient permissions");
224 exit;
225 }
226 }
227 }
228 } else {
229 my $cat_write = IO::File->new($cat_file, '>');
230 if (defined $cat_write) {
231 print $cat_write "perl-gcpan";
232 } else {
233 print_err("Insufficient permissions to edit /etc/portage/categories");
234 print_err("Please run $prog as a user with sufficient permissions");
235 exit;
236 }
237 }
238
239 my $gcpan_run = Gentoo->new(
240 'cpan_reload' => $cpan_reload,
241 'DEBUG' => $debug,
242 );
243
244 # Get the main portdir
245 my $PORTAGE_DIR = strip_ends('PORTDIR');
246 $gcpan_run->{portage_bases}{$PORTAGE_DIR} = 1;
247
248 # Grab the keywords - we'll need these when we build the ebuild
249 my $keywords = strip_ends('ACCEPT_KEYWORDS');
250
251 $keywords ||= do {
252 open my $tmp, '<', "$PORTAGE_DIR/profiles/arch.list"
253 or fatal(print_err("ERROR READING $PORTAGE_DIR/profiles/arch.list: $!"));
254 join ' ', map { chomp; $_ } <$tmp>;
255 };
256
257
258 # Get the overlays
259 my $overlay = strip_ends('PORTDIR_OVERLAY') || undef;
260
261 # Get the DISTDIR - we'd like store the tarballs in here the one time
262 $gcpan_run->{sources} = (strip_ends('DISTDIR'));
263
264 # Make sure we have write access to the DISTDIR
265 if ( $generate
266 || $install
267 || $pretend
268 || $buildpkg
269 || $buildpkgonly
270 || $ask
271 || $upgrade) {
272 my $test_dist_writes = $gcpan_run->{sources} . '/test-gcpan';
273 my $test_distdir = IO::File->new($test_dist_writes, '>');
274 if ($test_distdir) {
275 undef $test_distdir;
276 unlink $test_dist_writes;
277 } else {
278 undef $test_distdir;
279 fatal(print_err("No write access to DISTDIR: $!"));
280 }
281 }
282
283 if ($overlay) {
284 if ($overlay =~ /\S+\s+\S+/) {
285 my @overlays = split ' ', $overlay;
286 foreach (@overlays) {
287 $gcpan_run->{portage_bases}{$_} = 1 if (-d $_);
288 }
289 } else {
290 if ( -d $overlay ) { $gcpan_run->{portage_bases}{$overlay} = 1 }
291 }
292 unless (keys %{$gcpan_run->{portage_bases}} > 1)
293 {
294 fatal(print_err("DEFINED OVERLAYS DON'T EXIST!"));
295 }
296
297 } elsif ($generate || $pretend) {
298 print_err("The option you have chosen isn't supported without a configured overlay.\n");
299 exit();
300 }
301
302 # Set portage_categories to our defined list of perl_dirs
303 $gcpan_run->{portage_categories} = \@perl_dirs;
304
305 # Taking care of Searches.
306 if ($search) {
307 foreach my $expr (@ARGV) {
308 my $tree_expr = $expr;
309 $tree_expr =~ s/::/-/gxms;
310 scanTree(lc($tree_expr));
311 if (defined($gcpan_run->{portage}{lc($tree_expr)}{found})) {
312 print_info("Ebuild exists for $expr");
313 } else {
314 print_info("No ebuild exists, pulling up CPAN listings for $expr");
315 my @search_results;
316
317 # Assume they gave us module-name instead of module::name
318 # which is bad, because CPAN can't convert it ;p
319
320 $verbose and print_info("Searching for $expr on CPAN");
321
322
323 # Let's define a CPAN::Frontend to use our printing methods
324
325 spinner_start();
326 if (!@search_results) {
327 $expr =~ s/-/::/g;
328 my @hold = CPAN::Shell->i("/$expr/");
329 if (grep {/\S/} @hold) { push @search_results, @hold }
330 }
331
332 # remove the spin
333 spinner_stop();
334
335
336 # now, @search_results should contain the matching modules strings, if any
337 if (@search_results) {
338 print_info( "Result(s) found :");
339 foreach (@search_results)
340 {
341 print_out("$_\n");
342 }
343 } else {
344 print_warn('no result found.');
345 }
346
347 }
348 }
349
350 exit;
351 }
352
353 if ($list || $upgrade) {
354 if ($upgrade && @ARGV > 0) {
355 %passed_to_install = map { $_ => 1 } @ARGV;
356 } else {
357 my @overlays = split ' ', $overlay;
358 foreach my $overlay_dir (@overlays) {
359 my $gcpan_dir = File::Spec->catdir($overlay_dir, 'perl-gcpan');
360 #$list and print_info("OVERLAY: $gcpan_dir");
361 print_info("OVERLAY: $gcpan_dir");
362 if (opendir PDIR, $gcpan_dir) {
363 while (my $file = readdir PDIR) {
364 $file eq '.' || $file eq '..' and next;
365 $list and print_info("perl-gcpan/$file");
366 $upgrade and $passed_to_install{$file} = 1;
367 }
368 closedir PDIR;
369 } else {
370 print_warn("Couldn't open folder $gcpan_dir: $!");
371 }
372 }
373 }
374 }
375
376 if ( $generate
377 || $install
378 || $pretend
379 || $buildpkg
380 || $buildpkgonly
381 || $ask
382 || $upgrade) {
383 generatePackageInfo($_) foreach (keys %passed_to_install)
384 }
385
386 if ($install || $pretend || $buildpkg || $buildpkgonly || $upgrade || $ask) {
387 if (keys %really_install) {
388
389 my @ebuilds = (keys %really_install);
390 $verbose and print_info("Calling emerge for @ebuilds\n");
391 my @flags;
392 if ($pretend && $pretend > 0) {push @flags, '--pretend' }
393 if ($ask && $ask > 0) { push @flags, '--ask' }
394 if ($buildpkg && $buildpkg > 0 ) {push @flags, '--buildpkg' }
395 if ($buildpkgonly && $buildpkgonly > 0 ) { push @flags, '--buildpkgonly' }
396
397 $verbose and print_info("Calling: emerge @flags @ebuilds");
398 $gcpan_run->emerge_ebuild(@ebuilds, @flags);
399
400 } else {
401 if ($upgrade) {
402 print_info('Everything was up to date, nothing to do!');
403 } else {
404 print_err('Nothing to install!!');
405 }
406 }
407 }
408
409 sub generatePackageInfo {
410
411 # Since all we are concerned with is the final name of the package, this
412 # should be a safe substitution
413 my ($ebuild_wanted) = @_;
414 $ebuild_wanted =~ /ExtUtils(::|-)MakeMaker/i and
415 print_info('Skipping ExtUtils::MakeMaker dependency'), next;
416
417 #In the event this is an upgrade, go ahead and do the lame s/-/::/
418 $upgrade and $ebuild_wanted =~ s/-/::/gxms;
419
420 # Grab specific info for this module
421 spinner_start();
422 defined($gcpan_run->{portage}{lc($ebuild_wanted)}{found}) or
423 $gcpan_run->getCPANInfo($ebuild_wanted);
424 spinner_stop();
425 if ( ! $gcpan_run->{cpan}{lc($ebuild_wanted)} && ! defined($gcpan_run->{portage}{lc($ebuild_wanted)}{found} )) {
426
427 # Fallback to trying the /-/::/ trick - we avoid this the first time
428 # in case the module actually employs a - in its name
429 $ebuild_wanted =~ s/-/::/gxms;
430 $verbose and print_info("Getting CPAN Info for $ebuild_wanted");
431 spinner_start();
432 $gcpan_run->getCPANInfo($ebuild_wanted);
433 spinner_stop();
434 }
435
436 # If we found something on cpan, transform the portage_name
437 # It's possible to not find something on cpan at this point - we're just
438 # trying to pre-seed the portage_name
439 if ($gcpan_run->{cpan}{lc($ebuild_wanted)}) {
440 spinner_start();
441 $gcpan_run->{cpan}{lc($ebuild_wanted)}{portage_name} = $gcpan_run->transformCPAN($gcpan_run->{cpan}{lc($ebuild_wanted)}{src_uri}, 'n');
442 $gcpan_run->{cpan}{lc($ebuild_wanted)}{portage_version} = $gcpan_run->transformCPAN($gcpan_run->{cpan}{lc($ebuild_wanted)}{src_uri}, 'v');
443 spinner_stop();
444 } else {
445 print_err("$ebuild_wanted is not a CPAN module!");
446 }
447
448 # Save a copy of the originally requested name for later use
449 my $original_ebuild = $ebuild_wanted;
450
451 # Simple transform of name to something portage friendly
452 $ebuild_wanted =~ s/::/-/gxms;
453
454 # Scan portage for the ebuild name
455 if (( $upgrade && !defined($passed_to_install{$ebuild_wanted}) ) ||
456 (!$upgrade && defined($passed_to_install{$ebuild_wanted})) ||
457 (!$upgrade && !defined($gcpan_run->{portage}{lc($ebuild_wanted)}{found} ) )
458 ) {
459
460 # Ebuild wasn't found - scan for the nice version of the module name
461 if (lc($gcpan_run->{cpan}{lc($original_ebuild)}{portage_name}) eq 'perl' ) { return }
462 scanTree($gcpan_run->{cpan}{lc($original_ebuild)}{portage_name});
463
464 # We had success in finding this module under a different name
465 if (defined($gcpan_run->{portage}{lc($gcpan_run->{cpan}{lc($original_ebuild)}{portage_name})}{found})) {
466 $verbose and print_info('Found ebuild under CPAN name (' . $gcpan_run->{cpan}{lc($original_ebuild)}{portage_name} . ')');
467 $ebuild_wanted = $gcpan_run->{cpan}{lc($original_ebuild)}{portage_name};
468 }
469 } else {
470 $gcpan_run->{cpan}{lc($original_ebuild)}{portage_name} = $ebuild_wanted;
471 }
472
473 # Second round - we've looked for the package in portage two different
474 # ways now, time to get serious and create it ourselves
475 if ( ! defined($gcpan_run->{portage}{lc($ebuild_wanted)}{found} ) ) {
476
477 # Generate info - nothing found currently in the tree
478 $debug and $gcpan_run->debug;
479 if ( $gcpan_run->{cpan}{lc($original_ebuild)}{portage_name} &&
480 lc($gcpan_run->{cpan}{lc($original_ebuild)}{portage_name}) ne 'perl') {
481
482 # We have a cpan package that matches the request.
483 # Let's unpack it and get all the deps out of it.
484 spinner_start();
485 $gcpan_run->unpackModule($gcpan_run->{cpan}{lc($original_ebuild)}{name});
486 spinner_stop();
487
488 foreach my $dep (keys %{$gcpan_run->{cpan}{lc($original_ebuild)}{depends}}) {
489 defined $dep && $dep ne '' or next;
490 $dep eq 'perl' and delete $gcpan_run->{cpan}{lc($original_ebuild)}{depends}{$dep};
491
492 $dep =~ /ExtUtils(::|-)MakeMaker/i and print_info("Skipping ExtUtils::MakeMaker dependency"), next;
493
494 # Make sure we have information relevant to each of the deps
495 $verbose and print_info("Checking on dependency $dep for $original_ebuild");
496 $passed_to_install{$dep} or generatePackageInfo($dep);
497
498 # Remove dep from list of modules to install later on - no
499 # more dup'd installs!
500 defined $passed_to_install{$dep} and delete $really_install{$dep};
501
502 # Reindex one last time for anything we build after the fact
503 scanTree($gcpan_run->{cpan}{lc($dep)}{portage_name});
504 }
505
506 # Write ebuild here?
507 $debug and $gcpan_run->debug;
508 my @overlays = [];
509 if ($overlay) { @overlays = split ' ', $overlay }
510 else { push @overlays, "/var/tmp/g-cpan" and
511 $ENV{PORTDIR_OVERLAY} = "/var/tmp/g-cpan" }
512 foreach my $target_dir (@overlays) {
513 if (-d $target_dir) {
514 my $gcpan_dir = File::Spec->catdir($target_dir, 'perl-gcpan');
515 if (! -d $gcpan_dir) {
516 $verbose and print_info("Create directory '$gcpan_dir'");
517 mkdir($gcpan_dir, 0755) or
518 fatal(print_err("Couldn't create folder $gcpan_dir: $!"));
519 }
520 my $ebuild_dir = File::Spec->catdir($gcpan_dir, $gcpan_run->{cpan}{lc($original_ebuild)}{portage_name});
521 if (! -d $ebuild_dir) {
522 $verbose and print_info("Create directory '$ebuild_dir'");
523 mkdir($ebuild_dir, 0755) or
524 fatal(print_err("Couldn't create folder $gcpan_dir: $!"));
525 }
526 my $files_dir = File::Spec->catdir($ebuild_dir, 'files');
527 if (! -d $files_dir) {
528 $verbose and print_info("Create directory '$files_dir'");
529 mkdir($files_dir, 0755) or
530 fatal(print_err("Couldn't create folder $gcpan_dir: $!"));
531 }
532 my $ebuild = File::Spec->catdir($ebuild_dir,
533 $gcpan_run->{cpan}{lc($original_ebuild)}{portage_name} . '-'
534 . $gcpan_run->{cpan}{lc($original_ebuild)}{portage_version}
535 . '.ebuild');
536
537 # Break out if we already have an ebuild (upgrade or
538 # mistake in the code)
539 if ( ! -f $ebuild) {
540 print_info('Generating ebuild for ' . $gcpan_run->{cpan}{lc($original_ebuild)}{name});
541 my $EBUILD = IO::File->new($ebuild, '>') or
542 fatal(print_err("Couldn't open(write) file $ebuild: $!"));
543 print $EBUILD <<"HERE";
544 # Copyright 1999-2006 Gentoo Foundation
545 # Distributed under the terms of the GNU General Public License v2
546 # This ebuild generated by $prog $VERSION
547
548 inherit perl-module
549
550 S=\${WORKDIR}/$gcpan_run->{'cpan'}{lc($original_ebuild)}{'portage_sdir'}
551
552 DESCRIPTION="$gcpan_run->{'cpan'}{lc($original_ebuild)}{'description'}"
553 HOMEPAGE="http://search.cpan.org/search?query=\${PN}"
554 SRC_URI="mirror://cpan/authors/id/$gcpan_run->{'cpan'}{lc($original_ebuild)}{'src_uri'}"
555
556
557 IUSE=""
558
559 SLOT="0"
560 LICENSE="|| ( Artistic GPL-2 )"
561 KEYWORDS="$keywords"
562
563 HERE
564
565 if (my @deps = keys %{$gcpan_run->{cpan}{lc($original_ebuild)}{depends}}) {
566 print $EBUILD "DEPEND=\"";
567 my %seen_deps;
568 foreach my $dep (@deps) {
569 defined $dep && $dep ne '' or next;
570 my $portage_name = lc($gcpan_run->{cpan}{lc($dep)}{portage_name});
571 $portage_name =~ /\S/ or next;
572 if ($original_ebuild =~ m/filter-simple/mgix)
573 { print_err("$portage_name is being passed");}
574
575 # Last ditch call to scanTree to make sure we
576 # have info
577 scanTree($portage_name);
578 defined($seen_deps{$portage_name}) && $seen_deps{$portage_name} > 0 and next;
579 $seen_deps{$portage_name} = 1;
580 next unless ( defined
581 ($gcpan_run->{portage}{$portage_name}{category})
582 and defined (
583 $gcpan_run->{portage}{$portage_name}{name}
584 ) && (
585 $gcpan_run->{portage}{$portage_name}{name}
586 =~ m/\S/));
587 $portage_name eq 'perl' ||
588 lc($portage_name) eq lc($gcpan_run->{cpan}{lc($original_ebuild)}{portage_name}) and next;
589 my $eb_version = stripdown($gcpan_run->{portage}{lc($portage_name)}{version});
590 my $cpan_version = defined($gcpan_run->{cpan}{lc($dep)}{portage_version})? stripdown($gcpan_run->{cpan}{lc($dep)}{portage_version}): "0";
591 if ( defined($gcpan_run->{cpan}{lc($dep)}{portage_version}) &&
592 $gcpan_run->{cpan}{lc($original_ebuild)}{depends}{$dep} ne '0' &&
593 int($eb_version) >= int($cpan_version) &&
594 $gcpan_run->{cpan}{lc($original_ebuild)}{depends}{$dep} =~ m{\d}gx &&
595 $gcpan_run->{portage}{$portage_name}{name} ne "module-build"
596 ) {
597 print $EBUILD "\>\="
598 . $gcpan_run->{portage}{$portage_name}{category} . '/'
599 . $gcpan_run->{portage}{$portage_name}{name} . '-';
600 if (defined($eb_version)) {
601 print $EBUILD $gcpan_run->{portage}{lc($portage_name)}{version}
602 } else {
603 print $EBUILD $gcpan_run->{cpan}{lc($dep)}{portage_version}
604 }
605 print $EBUILD "\n\t";
606 } else {
607 print $EBUILD ""
608 . $gcpan_run->{portage}{$portage_name}{category} . "/"
609 . $gcpan_run->{portage}{$portage_name}{name} . "\n\t";
610 }
611 }
612 print $EBUILD "dev-lang/perl\"\n";
613 undef $EBUILD;
614 autoflush STDOUT 1;
615 }
616 if (-f $gcpan_run->{cpan}{lc($original_ebuild)}{cpan_tarball}) {
617 $verbose and print_ok("Copying $gcpan_run->{cpan}{lc($original_ebuild)}{cpan_tarball} to $gcpan_run->{sources}");
618 copy($gcpan_run->{cpan}{lc($original_ebuild)}{cpan_tarball}, $gcpan_run->{sources});
619 }
620 print_info("Ebuild generated for $ebuild_wanted");
621 $gcpan_run->generate_digest($ebuild);
622 if (
623 !$upgrade
624 or ($upgrade
625 &&
626 defined($passed_to_install{$gcpan_run->{'cpan'}->{lc($original_ebuild)}->{'name'}})
627 )
628 ) {
629 my $portage_name = $gcpan_run->{'cpan'}->{lc($original_ebuild)}->{'portage_name'};
630 $really_install{ $portage_name } = 1;
631 }
632 last;
633 } else {
634 $upgrade and print_info("$ebuild_wanted already up to date") and last;
635 my $portage_name = $gcpan_run->{'cpan'}->{lc($original_ebuild)}->{'portage_name'};
636 $really_install{ $portage_name } = 1;
637 }
638 }
639 }
640 }
641 } else {
642 print_ok("Ebuild already exists for $ebuild_wanted");
643 defined $passed_to_install{$ebuild_wanted} || defined $passed_to_install{$original_ebuild} and
644 $really_install{$gcpan_run->{portage}{lc($ebuild_wanted)}{'name'}} = 1;
645 }
646 }
647
648 sub scanTree {
649 my ($module) = @_;
650 $module or return;
651
652 if ($module =~ /pathtools/gimx) { $module = "File-Spec" }
653 foreach my $portage_root (keys %{$gcpan_run->{portage_bases}}) {
654 if (-d $portage_root) {
655 $verbose and print_ok("Scanning $portage_root for $module");
656 $gcpan_run->getAvailableVersions($portage_root, $module);
657 }
658
659 # Pop out of the loop if we've found the module
660 defined($gcpan_run->{portage}{lc($module)}{found}) and last;
661 }
662 }
663
664 sub strip_ends {
665 my $key = shift;
666 $ENV{$key} =~ s{\$}{}gxms;
667 $ENV{$key} =~ s{\\n}{ }gxms;
668 $ENV{$key} =~ s{\'}{}gmxs;
669 $ENV{$key} =~ s{\s+$}{};
670 return $ENV{$key};
671 }
672
673 sub stripdown {
674 my $string = shift;
675 unless ($string =~ m{\d}) { return }
676 $string =~ s{\.|_|-|\D+}{}gmxi;
677 return $string;
678 }
679
680
681 # cab - Takes care of system's sanity
682 END {
683
684 #Clean out the /tmp tree we were using
685 #I know this looks weird, but since clean_up is invoked on a search, where OVERLAYS isn't ever defined,
686 # we first need to see if it exists, then need to remove only if it has content (the old exists vs. defined)
687
688 if (defined($ENV{TMPDIR})) {
689 $verbose and print_ok('Cleaning temporary space');
690 my ($startdir) = cwd();
691 chdir("$ENV{TMPDIR}/.cpan");
692 opendir(CURD, '.');
693 my @dirs = readdir(CURD);
694 closedir(CURD);
695 foreach my $dir (@dirs) {
696 $dir eq '.' and next;
697 $dir eq '..' and next;
698 $dir eq 'sources' and next;
699 -d $dir and rmtree(["$ENV{TMPDIR}/.cpan/$dir"]);
700 }
701 if ( -d "$ENV{TMPDIR}/perl-gcpan" ) { rmtree(["$ENV{TMPDIR}/perl-gcpan"]) }
702 }
703 }
704
705 # cab - nice help message ! ;)
706 sub exit_usage
707 {
708 print <<"USAGE";
709 ${white}Usage : ${cyan}$prog ${green}<Switch(es)> ${cyan}Module Name(s)${reset}
710
711 ${green}--generate,-g${reset}
712 Generate ebuilds only (Requires working overlays)
713
714 ${green}--install,-i${reset}
715 Try to generate ebuild for the given module name
716 and, if successful, emerge it. Important : installation
717 requires exact CPAN Module Name.
718
719 ${green}--list,-l${reset}
720 This command generates a list of the Perl modules and ebuilds
721 handled by $prog.
722
723 ${green}--log,-L${reset}
724 Log the output of $prog.
725
726 ${green}--search,-s${reset}
727 Search CPAN for the given expression (similar to
728 the "m /EXPR/" from the CPAN Shell). Searches are
729 case insensitive.
730
731 ${green}--upgrade,-u${reset}
732 Try to list and upgrade all Perl modules managed by $prog.
733 It generate up-to-date ebuilds, then emerge then.
734
735 ${green}--verbose,-v${reset}
736 Enable (some) verbose output.
737
738 ${green}--cpan_reload${reset}
739 Reload the CPAN index
740
741 ${white}Portage related options${reset}
742
743 ${green}--ask,-a${reset}
744 Ask before installing
745
746 ${green}--buildpkg,-b${reset}
747 Tells emerge to build binary packages for all ebuilds processed
748 in addition to actually merging the packages.
749
750 ${green}--buildpkgonly,-B${reset}
751 Creates binary packages for all ebuilds processed without actu-
752 ally merging the packages.
753
754 ${green}--pretend,-p${reset}
755 Pretend (show actions, but don't emerge). This still generates
756 new ebuilds.
757
758
759 USAGE
760
761 exit;
762 }
763
764 exit;
765
766 ##############
767
768 __END__
769
770 =pod
771
772 =head1 NAME
773
774 g-cpan - install CPAN-provided Perl modules using Gentoo's Portage
775
776 =head1 SYNOPSIS
777
778 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>>
779
780 =head1 DESCRIPTION
781
782 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.
783
784 =head1 CPAN Configuration
785
786 B<~/.cpan/CPAN/MyConfig.pm>
787 B</path/to/perl/CPAN/Config.pm>
788
789 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.
790
791 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.
792
793 =head1 g-cpan and Overlays
794
795 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).
796
797 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.
798
799 =head1 Arguments
800
801 The following arguments are accepted by g-cpan.
802
803 =over 4
804
805 =item B<-g,--generate>
806
807 Generate ebuilds and drop them in the overlay, but never call portage. Useful for generating a tree of ebuilds without having permissions to portage.
808
809 =item B<-i,--install>
810
811 Install the (list of) modules provided.
812
813 =item B<-l,--list>
814
815 List ebuilds that have been generated by g-cpan and reside in your overlay.
816
817 =item B<-L,--log>
818
819 Log all output to /var/log/g-cpan/g-cpan.log and g-cpan.err
820
821 =item B<-s,--search>
822
823 Search CPAN for the provided module.
824
825 =item B<--cpan_reload>
826
827 Reload CPAN's index online
828
829 =item B<-u,--upgrade>
830
831 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.
832
833 =item B<-v,--verbose>
834
835 Enable verbose mode for more feedback on the step by step processes that g-cpan is running
836
837 =back
838
839 =head1 Portage Arguments
840
841 The following portage arguments can be passed to g-cpan. Please read the portage documentation for more information on how they work.
842
843 =over 4
844
845 =item B<-a,--ask>
846
847 Pass the "ask" argument to portage. This will cause portage to prompt you to confirm your installation prior to issuing an emerge
848
849 =item B<-b,--buildpkg>
850
851 Tells emerge to build binary packages for all ebuilds processed in addition to actually merging the packages.
852
853 =item B<-B,--buildpkgonly>
854
855 Creates binary packages for all ebuilds processed without actually merging the packages.
856
857 =item B<-p,--pretend>
858
859 Create ebuilds as needed for the (list of) modules provided, but don't perform the actual emerge.
860
861
862 =back
863
864 =head1 Usage
865
866
867 =head2 Here we install Jabber::RPC
868
869 # g-cpan -i Jabber::RPC
870
871 =head2 Performing a search
872
873 # g-cpan -s Clone::Any
874
875 =head2 Upgrading overlay from g-cpan
876
877 # g-cpan -u
878
879 =head2 Upgrading specifc ebuild in overlay from g-cpan
880
881 # g-cpan -u Mickey-Mouse
882
883 =head1 Todo
884
885 =head1 See Also
886
887 L<B<emerge>(1)>, L<B<ebuild>(5)>, L<B<make.conf>(5)>, L<B<perl>(1)>
888
889 =head1 Authors
890
891 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>
892
893 =head1 Reporting Bugs
894
895 Please report bugs via http://bugs.gentoo.org/ or https://bugs.gentoo.org/
896
897 =head1 svn Id $Id$
898
899 =cut

Properties

Name Value
svn:executable *
svn:keywords Id

  ViewVC Help
Powered by ViewVC 1.1.20