1 |
Author: cab |
2 |
Date: 2005-05-12 19:47:09 +0200 (Thu, 12 May 2005) |
3 |
New Revision: 22 |
4 |
|
5 |
Added: |
6 |
tags/ |
7 |
tags/g-cpan-0.12/ |
8 |
tags/g-cpan-0.12/bin/ |
9 |
tags/g-cpan-0.12/bin/g-cpan |
10 |
tags/g-cpan-0.12/bin/g-cpan.pl |
11 |
tags/g-cpan-0.12/doc/ |
12 |
tags/g-cpan-0.12/doc/Changes.gz |
13 |
tags/g-cpan-0.12/man/ |
14 |
tags/g-cpan-0.12/man/g-cpan.pl.1.gz |
15 |
Log: |
16 |
reorg-3 |
17 |
|
18 |
|
19 |
Added: tags/g-cpan-0.12/bin/g-cpan |
20 |
=================================================================== |
21 |
--- tags/g-cpan-0.12/bin/g-cpan 2005-05-12 17:36:48 UTC (rev 21) |
22 |
+++ tags/g-cpan-0.12/bin/g-cpan 2005-05-12 17:47:09 UTC (rev 22) |
23 |
@@ -0,0 +1 @@ |
24 |
+link g-cpan.pl |
25 |
\ No newline at end of file |
26 |
|
27 |
|
28 |
Property changes on: tags/g-cpan-0.12/bin/g-cpan |
29 |
___________________________________________________________________ |
30 |
Name: svn:special |
31 |
+ * |
32 |
|
33 |
Added: tags/g-cpan-0.12/bin/g-cpan.pl |
34 |
=================================================================== |
35 |
--- tags/g-cpan-0.12/bin/g-cpan.pl 2005-05-12 17:36:48 UTC (rev 21) |
36 |
+++ tags/g-cpan-0.12/bin/g-cpan.pl 2005-05-12 17:47:09 UTC (rev 22) |
37 |
@@ -0,0 +1,359 @@ |
38 |
+#!/usr/bin/perl -w |
39 |
+# Copyright 1999-2004 Gentoo Foundation |
40 |
+# Distributed under the terms of the GNU General Public License v2 |
41 |
+# $Header: /var/cvsroot/gentoo/users/mcummings/g-cpan/g-cpan-0.12/bin/g-cpan.pl,v 1.1 2005/04/30 21:44:15 mcummings Exp $ |
42 |
+# |
43 |
+ |
44 |
+# modules to use - these will need to be marked as |
45 |
+# dependencies, and installable by portage |
46 |
+use strict; |
47 |
+use File::Spec; |
48 |
+use File::Path; |
49 |
+use List::Util qw(first); |
50 |
+use CPAN; |
51 |
+eval 'use Digest::MD5;'; |
52 |
+my $have_digestmd5 = $@ ? 0 : 1; |
53 |
+ |
54 |
+my $VERSION="0.12"; |
55 |
+ |
56 |
+# output error if no arguments |
57 |
+unless (@ARGV) { |
58 |
+ print "Usage: g-cpan.pl [-v] MODULENAME ...\n"; |
59 |
+ exit; |
60 |
+} |
61 |
+my $VERBOSE = 0; |
62 |
+if ($ARGV[0] eq '-v') { |
63 |
+ shift @ARGV; |
64 |
+ $VERBOSE = 1; |
65 |
+} |
66 |
+# Set our temporary overlay directory for the scope of this run. By setting an overlay directory, |
67 |
+# we bypass the predefined portage directory and allow portage to build a package outside of its |
68 |
+# normal tree. |
69 |
+my $tmp_overlay_dir = "/tmp/perl-modules_$$"; |
70 |
+my @ebuild_list; |
71 |
+ |
72 |
+# Set up global paths |
73 |
+my $TMP_DEV_PERL_DIR = '/var/db/pkg/dev-perl'; |
74 |
+my $MAKECONF = '/etc/make.conf'; |
75 |
+my ( $OVERLAY_DIR, $PORTAGE_DIR, $PORTAGE_DEV_PERL, $PORTAGE_DISTDIR ) = get_globals(); |
76 |
+ |
77 |
+# Create the ebuild in PORTDIR_OVERLAY, if it is defined and exists |
78 |
+$tmp_overlay_dir = $OVERLAY_DIR unless $OVERLAY_DIR eq ""; |
79 |
+ |
80 |
+my $arches = join( ' ', map { chomp; $_ } `cat $PORTAGE_DIR/profiles/arch.list` ); |
81 |
+ |
82 |
+#this should never find the dir, but just to be safe |
83 |
+unless ( -d $tmp_overlay_dir ) { |
84 |
+ mkpath( [$tmp_overlay_dir], 1, 0755 ) |
85 |
+ or die "Couldn't create '$tmp_overlay_dir': $|"; |
86 |
+} |
87 |
+ |
88 |
+# Now we cat our dev-perl directory onto our overlay directory. |
89 |
+# This is done so that portage records the appropriate path, i.e. dev-perl/package |
90 |
+my $perldev_overlay = File::Spec->catfile( $tmp_overlay_dir, 'dev-perl' ); |
91 |
+ |
92 |
+unless ( -d $perldev_overlay ) { |
93 |
+ # create perldev overlay dir if not present |
94 |
+ mkpath( [$perldev_overlay], 1, 0755 ) |
95 |
+ or die "Couldn't create '$perldev_overlay': $|"; |
96 |
+} |
97 |
+ |
98 |
+# Now we export our overlay directory into the session's env vars |
99 |
+$ENV{'PORTDIR_OVERLAY'} = $tmp_overlay_dir; |
100 |
+ |
101 |
+# jrray printing functions |
102 |
+sub printbig { |
103 |
+ print '*' x 72, "\n"; |
104 |
+ print '*', "\n"; |
105 |
+ print '*', "\n"; |
106 |
+ print '* ', @_; |
107 |
+ print '*', "\n"; |
108 |
+ print '*', "\n"; |
109 |
+ print '*' x 72, "\n"; |
110 |
+} |
111 |
+ |
112 |
+sub ebuild_exists { |
113 |
+ my ($dir) = @_; |
114 |
+ |
115 |
+ # need to try harder here - see &portage_dir comments. |
116 |
+ # should return an ebuild name from this, as case matters. |
117 |
+ |
118 |
+ # see if an ebuild for $dir exists already. If so, return its name. |
119 |
+ my $found = ''; |
120 |
+ |
121 |
+ foreach my $sdir (grep {-d $_} ($PORTAGE_DEV_PERL, $perldev_overlay, $TMP_DEV_PERL_DIR)) { |
122 |
+ opendir PDIR,$sdir; |
123 |
+ my @dirs = readdir(PDIR); |
124 |
+ closedir PDIR; |
125 |
+ $found ||= first {lc($_) eq lc($dir)} (@dirs); |
126 |
+ if (($found)&&($VERBOSE)) { |
127 |
+ print "$0: Looking for ebuilds in $sdir, found $found so far.\n"; } |
128 |
+ } |
129 |
+ |
130 |
+ # check for ebuilds that have been created by g-cpan.pl |
131 |
+ for my $ebuild ( @ebuild_list ) { |
132 |
+ $found = $ebuild if ( $ebuild eq $dir ); |
133 |
+ } |
134 |
+ |
135 |
+ return $found; |
136 |
+} |
137 |
+ |
138 |
+sub module_check { |
139 |
+ |
140 |
+ # module_check evaluates whether a module can be loaded from @INC. |
141 |
+ # This allows us to assure that if a module has been manually installed, we know about it. |
142 |
+ my $check = shift; |
143 |
+ eval "use $check;"; |
144 |
+ return $@ ? 0 : 1; |
145 |
+} |
146 |
+ |
147 |
+sub portage_dir { |
148 |
+ my $obj = shift; |
149 |
+ my $file = $obj->cpan_file; |
150 |
+ |
151 |
+ # need to try harder here than before (bugs 64403 74149 69464 23951 +more?) |
152 |
+ |
153 |
+ # remove ebuild-incompatible characters |
154 |
+ $file =~ tr/a-zA-Z0-9\.\//-/c; |
155 |
+ |
156 |
+ $file =~ s/\.pm//; # e.g. CGI.pm |
157 |
+ |
158 |
+ # turn this into a directory name suitable for portage tree |
159 |
+ # at least one module omits the hyphen between name and version. |
160 |
+ # these two regexps are 'better' matches than previously. |
161 |
+ if ( $file =~ m|.*/(.*)-[0-9]+\.| ) { return $1; } |
162 |
+ if ( $file =~ m|.*/([a-zA-Z-]*)[0-9]+\.| ) { return $1; } |
163 |
+ if ( $file =~ m|.*/([^.]*)\.| ) { return $1; } |
164 |
+ |
165 |
+ warn "$0: Unable to coerce $file into a portage dir name"; |
166 |
+ |
167 |
+ return; |
168 |
+} |
169 |
+ |
170 |
+sub create_ebuild { |
171 |
+ my ( $module, $dir, $file, $build_dir, $prereq_pm, $md5 ) = @_; |
172 |
+ |
173 |
+ # First, make the directory |
174 |
+ my $fulldir = File::Spec->catdir( $perldev_overlay, $dir ); |
175 |
+ my $filesdir = File::Spec->catdir( $fulldir, 'files' ); |
176 |
+ mkdir $fulldir, 0755 or die "Couldn't create '$fulldir': $!"; |
177 |
+ mkdir $filesdir, 0755 or die "Couldn't create '$filesdir': $!"; |
178 |
+ |
179 |
+ unless ( -d $fulldir ) { die "$fulldir not created!!\n" } |
180 |
+ unless ( -d $filesdir ) { die "$fulldir not created!!\n" } |
181 |
+ # What to call this ebuild? |
182 |
+ # CGI::Builder's '1.26+' version breaks portage |
183 |
+ unless ( $file =~ m/(.*)\/(.*?)(-?)([0-9\.]+).*\.(?:tar|tgz|zip|bz2|gz)/ ) { |
184 |
+ warn("Couldn't turn '$file' into an ebuild name\n"); |
185 |
+ return; |
186 |
+ } |
187 |
+ |
188 |
+ my ( $modpath, $filename, $filenamever ) = ( $1, $2, $4 ); |
189 |
+ |
190 |
+ # remove underscores |
191 |
+ $filename =~ tr/A-Za-z0-9\./-/c; |
192 |
+ $filename =~ s/\.pm//; # e.g. CGI.pm |
193 |
+ |
194 |
+ # Remove double .'s - happens on occasion with odd packages |
195 |
+ $filenamever =~ s/\.$//; |
196 |
+ |
197 |
+ my $ebuild = File::Spec->catdir( $fulldir, "$filename-$filenamever.ebuild" ); |
198 |
+ my $digest = File::Spec->catdir( $filesdir, "digest-$filename-$filenamever" ); |
199 |
+ |
200 |
+ my $desc = $module->description || 'No description available.'; |
201 |
+ |
202 |
+ print "Writing to $ebuild\n" if ($VERBOSE); |
203 |
+ open EBUILD, ">$ebuild" or die "Could not write to '$ebuild': $!"; |
204 |
+ print EBUILD <<"HERE"; |
205 |
+ |
206 |
+ |
207 |
+# Copyright 1999-2004 Gentoo Foundation |
208 |
+# Distributed under the terms of the GNU General Public License v2 |
209 |
+ |
210 |
+inherit perl-module |
211 |
+ |
212 |
+S=\${WORKDIR}/$build_dir |
213 |
+DESCRIPTION="$desc" |
214 |
+SRC_URI="mirror://cpan/authors/id/$file" |
215 |
+HOMEPAGE="http://www.cpan.org/modules/by-authors/id/$modpath/\${P}.readme" |
216 |
+ |
217 |
+IUSE="" |
218 |
+ |
219 |
+SLOT="0" |
220 |
+LICENSE="|| ( Artistic GPL-2 )" |
221 |
+KEYWORDS="$arches" |
222 |
+ |
223 |
+HERE |
224 |
+ |
225 |
+ if ( $prereq_pm && keys %$prereq_pm ) { |
226 |
+ |
227 |
+ print EBUILD q|DEPEND="|; |
228 |
+ #MPC print EBUILD q|DEPEND="dev-perl/module-build |; |
229 |
+ |
230 |
+ my $first = 1; |
231 |
+ my %dup_check; |
232 |
+ for ( keys %$prereq_pm ) { |
233 |
+ |
234 |
+ my $obj = CPAN::Shell->expandany($_); |
235 |
+ my $dir = portage_dir($obj); |
236 |
+ if ( $dir eq "Module-Build" ) { $dir = "module-build" } |
237 |
+ next if $dir eq "perl"; |
238 |
+ if ( ( !$dup_check{$dir} ) && ( !module_check($dir) ) ) { |
239 |
+ $dup_check{$dir} = 1; |
240 |
+ # remove trailing .pm to fix emerge breakage. |
241 |
+ $dir =~ s/.pm$//; |
242 |
+ print EBUILD "\n\t" unless $first; |
243 |
+ print EBUILD "dev-perl/$dir"; |
244 |
+ } |
245 |
+ $first = 0; |
246 |
+ } |
247 |
+ print EBUILD qq|"\n\n|; |
248 |
+ } |
249 |
+ |
250 |
+ close EBUILD; |
251 |
+ |
252 |
+ # write the digest too |
253 |
+ open DIGEST, ">$digest" or die "Could not write to '$digest': $!"; |
254 |
+ print DIGEST $md5, "\n"; |
255 |
+ close DIGEST; |
256 |
+} |
257 |
+ |
258 |
+sub install_module { |
259 |
+ my ($module_name, $recursive) = @_; |
260 |
+ |
261 |
+ my $obj = CPAN::Shell->expandany($module_name); |
262 |
+ unless (( ref $obj eq "CPAN::Module" ) || ( ref $obj eq "CPAN::Bundle" )) { |
263 |
+ warn("Don't know what '$module_name' is\n"); |
264 |
+ return; |
265 |
+ } |
266 |
+ |
267 |
+ my $file = $obj->cpan_file; |
268 |
+ my $dir = portage_dir($obj); |
269 |
+ print "$0: portage_dir returned $dir\n" if ($VERBOSE); |
270 |
+ unless ($dir) { |
271 |
+ warn("Couldn't turn '$file' into a directory name\n"); |
272 |
+ return; |
273 |
+ } |
274 |
+ |
275 |
+ if ( ebuild_exists($dir) ) { |
276 |
+ printbig "Ebuild already exists for '$module_name': ".&ebuild_exists($dir)."\n"; |
277 |
+ return; |
278 |
+ |
279 |
+ } |
280 |
+ elsif ( !defined $recursive && module_check($module_name) ) { |
281 |
+ printbig "Module already installed for '$module_name'\n"; |
282 |
+ return; |
283 |
+ } |
284 |
+ elsif ( $dir eq 'perl' ) { |
285 |
+ printbig "Module '$module_name' is part of the base perl install\n"; |
286 |
+ return; |
287 |
+ } |
288 |
+ |
289 |
+ printbig "Need to create ebuild for '$module_name': $dir\n"; |
290 |
+ |
291 |
+ # check depends ... with CPAN have to make the module |
292 |
+ # before it can tell us what the depends are, this stinks |
293 |
+ |
294 |
+ $CPAN::Config->{prerequisites_policy} = ""; |
295 |
+ $CPAN::Config->{inactivity_timeout} = 30; |
296 |
+ |
297 |
+ my $pack = $CPAN::META->instance( 'CPAN::Distribution', $file ); |
298 |
+ $pack->called_for( $obj->id ); |
299 |
+ $pack->make; |
300 |
+ # A cheap ploy, but this lets us add module-build as needed instead of forcing it on everyone |
301 |
+ my $add_mb = 0; |
302 |
+ if (-f "Build.PL") { $add_mb = 1 } |
303 |
+ $pack->unforce if $pack->can("unforce") && exists $obj->{'force_update'}; |
304 |
+ delete $obj->{'force_update'}; |
305 |
+ |
306 |
+ # grab the MD5 checksum for the source file now |
307 |
+ |
308 |
+ my $localfile = $pack->{localfile}; |
309 |
+ ( my $base = $file ) =~ s/.*\/(.*)/$1/; |
310 |
+ |
311 |
+ my $md5digest; |
312 |
+ if ($have_digestmd5) { |
313 |
+ open( DIGIFILE, $localfile ) or die "Can't open '$file': $!"; |
314 |
+ binmode(DIGIFILE); |
315 |
+ $md5digest = Digest::MD5->new->addfile(*DIGIFILE)->hexdigest; |
316 |
+ close(DIGIFILE); |
317 |
+ } else { |
318 |
+ ($md5digest = qx(/usr/bin/md5sum $localfile)) =~ s/^(.*?)\s.*$/$1/s; |
319 |
+ } |
320 |
+ |
321 |
+ my $md5string = sprintf "MD5 %s %s %d", $md5digest, $base, |
322 |
+ -s $localfile; |
323 |
+ |
324 |
+ # make ebuilds for all the prereqs |
325 |
+ my $prereq_pm = $pack->prereq_pm; |
326 |
+ if ($add_mb) {$prereq_pm->{'Module::Build'} = "0" } |
327 |
+ install_module($_, 1) for ( keys %$prereq_pm ); |
328 |
+ |
329 |
+ # get the build dir from CPAN, this will tell us definitively |
330 |
+ # what we should set S to in the ebuild |
331 |
+ # strip off the path element |
332 |
+ (my $build_dir = $pack->{build_dir}) =~ s|.*/||; |
333 |
+ |
334 |
+ create_ebuild( $obj, $dir, $file, $build_dir, $prereq_pm, $md5string ); |
335 |
+ |
336 |
+ system('/bin/mv', '-f', $localfile, $PORTAGE_DISTDIR); |
337 |
+ |
338 |
+ push @ebuild_list, $dir; |
339 |
+} |
340 |
+ |
341 |
+sub clean_up { |
342 |
+ |
343 |
+ #Probably don't need to do this, but for sanity's sake, we reset this var |
344 |
+ $ENV{'PORTDIR_OVERLAY'} = $OVERLAY_DIR; |
345 |
+ |
346 |
+ #Clean out the /tmp tree we were using |
347 |
+ rmtree( ["$tmp_overlay_dir"] ) if $OVERLAY_DIR eq ""; |
348 |
+} |
349 |
+ |
350 |
+sub emerge_module { |
351 |
+ foreach my $ebuild_name (@ebuild_list) { |
352 |
+ $ebuild_name =~ m/.*\/(.*)-[^-]+\./; |
353 |
+ print "$0: emerging $ebuild_name\n"; |
354 |
+# system("emerge $ebuild_name"); |
355 |
+ system( "emerge", "--oneshot", "--digest", $ebuild_name ); |
356 |
+ |
357 |
+ } |
358 |
+} |
359 |
+ |
360 |
+sub get_globals { |
361 |
+ |
362 |
+ my ( $OVERLAY_DIR, $PORTAGE_DIR, $PORTAGE_DEV_PERL, $PORTAGE_DISTDIR ); |
363 |
+ |
364 |
+ # let's not beat around the bush here, make.conf isn't the |
365 |
+ # only place these variables can be defined |
366 |
+ |
367 |
+ $OVERLAY_DIR=qx(/usr/lib/portage/bin/portageq portdir_overlay); |
368 |
+ $PORTAGE_DIR=qx(/usr/lib/portage/bin/portageq portdir); |
369 |
+ $PORTAGE_DISTDIR=qx(/usr/lib/portage/bin/portageq distdir); |
370 |
+ |
371 |
+ chomp $OVERLAY_DIR; |
372 |
+ chomp $PORTAGE_DIR; |
373 |
+ chomp $PORTAGE_DISTDIR; |
374 |
+ |
375 |
+ unless ( length $OVERLAY_DIR && -d $OVERLAY_DIR ) { |
376 |
+ $OVERLAY_DIR = ""; |
377 |
+ } |
378 |
+ |
379 |
+ unless ( length $PORTAGE_DIR && -d $PORTAGE_DIR ) { |
380 |
+ $PORTAGE_DIR = "/usr/portage"; |
381 |
+ } |
382 |
+ |
383 |
+ unless ( length $PORTAGE_DISTDIR && -d $PORTAGE_DISTDIR ) { |
384 |
+ $PORTAGE_DISTDIR = "/usr/portage/distfiles"; |
385 |
+ } |
386 |
+ |
387 |
+ # Finally, set the dev-perl dir explicitly |
388 |
+ $PORTAGE_DEV_PERL = "$PORTAGE_DIR/dev-perl"; |
389 |
+ |
390 |
+ return ( $OVERLAY_DIR, $PORTAGE_DIR, $PORTAGE_DEV_PERL, $PORTAGE_DISTDIR ); |
391 |
+ |
392 |
+} |
393 |
+ |
394 |
+install_module($_) for (@ARGV); |
395 |
+emerge_module($_) for (@ARGV); |
396 |
+clean_up(); |
397 |
|
398 |
|
399 |
Property changes on: tags/g-cpan-0.12/bin/g-cpan.pl |
400 |
___________________________________________________________________ |
401 |
Name: svn:executable |
402 |
+ * |
403 |
|
404 |
Added: tags/g-cpan-0.12/doc/Changes.gz |
405 |
=================================================================== |
406 |
(Binary files differ) |
407 |
|
408 |
|
409 |
Property changes on: tags/g-cpan-0.12/doc/Changes.gz |
410 |
___________________________________________________________________ |
411 |
Name: svn:mime-type |
412 |
+ application/octet-stream |
413 |
|
414 |
Added: tags/g-cpan-0.12/man/g-cpan.pl.1.gz |
415 |
=================================================================== |
416 |
(Binary files differ) |
417 |
|
418 |
|
419 |
Property changes on: tags/g-cpan-0.12/man/g-cpan.pl.1.gz |
420 |
___________________________________________________________________ |
421 |
Name: svn:mime-type |
422 |
+ application/octet-stream |
423 |
|
424 |
|
425 |
-- |
426 |
gentoo-perl@g.o mailing list |