9 perl Porting/sync-with-cpan <module>
11 where <module> is the name it appears in the C<%Modules> hash
12 of F<Porting/Maintainers.pl>
16 Script to help out with syncing cpan distros.
24 Fetches the package list from CPAN. Finds the current version of the given
29 Downloads the relevant tarball; unpacks the tarball. [1]
33 Clean out the old directory (C<git clean -dfx>)
37 Moves the old directory out of the way, moves the new directory in place.
41 Restores any F<.gitignore> file.
45 Removes files from C<@IGNORE> and C<EXCLUDED>
49 C<git add> any new files.
53 C<git rm> any files that are gone.
57 Remove the +x bit on files in F<t/>
61 Remove the +x bit on files that don't have it enabled in the current dir
65 Restore files mentioned in C<CUSTOMIZED>
69 Adds new files to F<MANIFEST>
73 Runs a C<make> (assumes a configure has been run)
81 Runs tests for the package
85 Runs the porting tests
89 [1] If the C<--tarball> option is given, then CPAN is not consulted.
90 C<--tarball> should be the path to the tarball; the version is extracted
91 from the filename -- but can be overwritten by the C<--version> option.
99 Delete files from F<MANIFEST>
103 Update F<Porting/Maintainers.pl>
107 Optional, run a full test suite
111 Handle complicated C<FILES>
115 This is an initial version; no attempt has been made yet to make this
116 portable. It shells out instead of trying to find a Perl solution.
117 In particular, it assumes wget, git, tar, chmod, perl, make, and rm
133 die "This does not look like a top level directory"
134 unless -d "cpan" && -d "Porting";
141 require "Porting/Maintainers.pl";
143 my %IGNORABLE = map {$_ => 1} @IGNORABLE;
145 my $package = "02packages.details.txt";
146 my $package_url = "http://www.cpan.org/modules/$package";
147 my $package_file = "/tmp/$package";
150 GetOptions ('tarball=s' => \my $tarball,
151 'version=s' => \my $version,
152 force => \my $force,)
153 or die "Failed to parse arguments";
155 die "Usage: $0 module [args] [cpan package]" unless @ARGV == 1 || @ARGV == 2;
157 my ($module) = shift;
158 my $cpan_mod = @ARGV ? shift : $module;
161 my $info = $Modules {$module} or die "Cannot find module $module";
162 my $distribution = $$info {DISTRIBUTION};
164 my @files = glob $$info {FILES};
165 if (@files != 1 || !-d $files [0] || $$info {MAP}) {
166 say "This looks like a setup $0 cannot handle (yet)";
168 say "Will not continue without a --force option";
171 say "--force is in effect, so we'll soldier on. Wish me luck!";
177 my $pkg_dir = $$info {FILES};
180 my ($old_version) = $distribution =~ /-([0-9.]+)\.tar\.gz/;
182 my $o_module = $module;
183 if ($cpan_mod =~ /-/ && $cpan_mod !~ /::/) {
184 $cpan_mod =~ s/-/::/g;
188 # Find the information from CPAN.
196 unless (-f $package_file && -M $package_file < 1) {
197 system wget => $package_url, '-qO', $package_file;
200 my $new_line = `grep '^$cpan_mod ' $package_file`
201 or die "Cannot find $cpan_mod on CPAN\n";
203 (undef, $new_version, my $new_path) = split ' ', $new_line;
204 if (defined $version) {
205 $new_path =~ s/-$new_version\./-$version\./;
206 $new_version = $version;
208 $new_file = (split '/', $new_path) [-1];
210 my $url = "http://search.cpan.org/CPAN/authors/id/$new_path";
213 # Fetch the new distro
215 system wget => $url, '-qO', $new_file;
218 $new_file = $tarball;
219 $new_version = $version // ($new_file =~ /-([0-9._]+)\.tar\.gz/) [0];
222 my $old_dir = "$pkg_dir-$old_version";
223 my $new_dir = "$pkg_dir-$new_version";
225 say "Cleaning out old directory";
226 system git => 'clean', '-dfxq', $pkg_dir;
228 say "Unpacking $new_file";
230 system tar => 'xfz', $new_file;
232 say "Renaming directories";
233 rename $pkg_dir => $old_dir;
234 rename $new_dir => $pkg_dir;
237 if (-f "$old_dir/.gitignore") {
238 say "Restoring .gitignore";
239 system git => 'checkout', "$pkg_dir/.gitignore";
242 my @new_files = `find $pkg_dir -type f`;
244 @new_files = grep {$_ ne $pkg_dir} @new_files;
245 s!^[^/]+/!! for @new_files;
246 my %new_files = map {$_ => 1} @new_files;
248 my @old_files = `find $old_dir -type f`;
250 @old_files = grep {$_ ne $old_dir} @old_files;
251 s!^[^/]+/!! for @old_files;
252 my %old_files = map {$_ => 1} @old_files;
255 # Find files that can be deleted.
259 if ($$info {EXCLUDED}) {
260 foreach my $entry (@{$$info {EXCLUDED}}) {
261 if (ref $entry) {push @EXCLUDED_QR => $entry}
262 else {$EXCLUDED_QQ {$entry} = 1}
270 foreach my $file (@new_files) {
271 next if -d "$pkg_dir/$file"; # Ignore directories.
272 next if $old_files {$file}; # It's already there.
273 if ($IGNORABLE {$file}) {
274 push @delete => $file;
277 if ($EXCLUDED_QQ {$file}) {
278 push @delete => $file;
281 foreach my $pattern (@EXCLUDED_QR) {
282 if ($file =~ /$pattern/) {
283 push @delete => $file;
287 push @commit => $file;
289 foreach my $file (@old_files) {
290 next if -d "$old_dir/$file";
291 next if $new_files {$file};
296 # Find all files with an exec bit
298 my @exec = `find $pkg_dir -type f -perm +111`;
301 foreach my $file (@exec) {
303 $file =~ s!^[^/]+/!!;
304 if ($file =~ m!^t/!) {
305 push @de_exec => $file;
308 # Check to see if the file exists; if it doesn't and doesn't have
309 # the exec bit, remove it.
310 if ($old_files {$file}) {
311 unless (-x "$old_dir/$file") {
312 push @de_exec => $file;
318 # No need to change the +x bit on files that will be deleted.
320 if (@de_exec && @delete) {
321 my %delete = map {+"$pkg_dir/$_" => 1} @delete;
322 @de_exec = grep {!$delete {$_}} @de_exec;
325 say "unlink $pkg_dir/$_" for @delete;
326 say "git add $pkg_dir/$_" for @commit;
327 say "git rm -f $pkg_dir/$_" for @gone;
328 say "chmod a-x $pkg_dir/$_" for @de_exec;
330 print "Hit return to continue; ^C to abort "; <STDIN>;
332 unlink "$pkg_dir/$_" for @delete;
333 system git => 'add', "$pkg_dir/$_" for @commit;
334 system git => 'rm', '-f', "$pkg_dir/$_" for @gone;
335 system chmod => 'a-x', "$pkg_dir/$_" for @de_exec;
338 # Restore anything that is customized.
339 # We don't really care whether we've deleted the file - since we
340 # do a git restore, it's going to be resurrected if necessary.
342 if ($$info {CUSTOMIZED}) {
343 say "Restoring customized files";
344 foreach my $file (@{$$info {CUSTOMIZED}}) {
345 system git => "checkout", "$pkg_dir/$file";
351 say "Fixing MANIFEST";
352 my $MANIFEST = "MANIFEST";
353 my $MANIFEST_SORT = "$MANIFEST.sorted";
354 open my $fh, ">>", $MANIFEST;
355 say $fh "cpan/$pkg_dir/$_" for @commit;
357 system perl => "Porting/manisort", '--output', $MANIFEST_SORT;
358 rename $MANIFEST_SORT => $MANIFEST;
362 print "Running a make ... ";
363 system "make > make.log 2>&1" and die "Running make failed, see make.log";
367 # Must clean up, or else t/porting/FindExt.t will fail.
368 # Note that we can always retrieve the orginal directory with a git checkout.
370 print "About to clean up; hit return or abort (^C) "; <STDIN>;
373 system rm => '-r', $old_dir;
374 unlink $new_file unless $tarball;
378 # Run the tests. First the test belonging to the module, followed by the
379 # the tests in t/porting
382 say "Running module tests";
383 my @test_files = `find ../cpan/$pkg_dir -name '*.t' -type f`;
385 my $output = `./perl TEST @test_files`;
386 unless ($output =~ /All tests successful/) {
391 print "Running tests in t/porting ";
392 my @tests = `ls porting/*.t`;
395 foreach my $t (@tests) {
396 my @not = `./perl -I../lib -I.. $t | grep ^not | grep -v "# TODO"`;
397 print @not ? '!' : '.';
398 push @failed => $t if @not;
401 say "Failed tests: @failed" if @failed;
404 print "Now you ought to run a make; make test ...\n";
406 say "Do not forget to update Porting/Maintainers.pl before committing";
407 say "$o_module is now version $new_version";