From b78ac7159b42a0e0bd59ab07411d2f5ef09e1d7e Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Wed, 12 Jun 2013 14:42:15 +0200 Subject: write_buildcustomize.pl no longer writes to STDOUT write_buildcustomize.pl now opens lib/buildcustomize.pl itself, instead of writing to STDOUT and relying on the Makefile to set up redirection. This means that an empty lib/buildcustomize.pl is not created if write_buildcustomize.pl fails to compile (for whatever reason), and permits write_buildcustomize.pl to delete (or attempt to delete) the output file if it detects an error. Hard code the output file name (lib/buildcustomize.pl), as it's the same on all platforms, and @ARGV is already used to optionally pass a directory for write_buildcustomize.pl to change to before running. Experimentation suggests that various make utilities don't delete a file created by redirection even if an error occurs. Hence this should be more robust. Add -f to the miniperl commandline when running write_buildcustomize.pl to avoid reading in any existing lib/buildcustomize.pl. write_buildcustomize.pl doesn't need the setup provided by lib/buildcustomize.pl, and running it might cause errors which prevents writing out a correct version, making an incomplete build harder to recover from. --- write_buildcustomize.pl | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'write_buildcustomize.pl') diff --git a/write_buildcustomize.pl b/write_buildcustomize.pl index 018e60e1fd..709923baa2 100644 --- a/write_buildcustomize.pl +++ b/write_buildcustomize.pl @@ -10,6 +10,8 @@ if (@ARGV) { unshift @INC, ('dist/Cwd', 'dist/Cwd/lib'); require File::Spec::Functions; +my $file = 'lib/buildcustomize.pl'; + # To clarify, this isn't the entire suite of modules considered "toolchain" # It's not even all modules needed to build ext/ # It's just the source paths of the (minimum complete set of) modules in ext/ @@ -42,10 +44,15 @@ my $inc = join ",\n ", map { "q\0$_\0" } (map {File::Spec::Functions::rel2abs($_)} @toolchain, 'lib'), '.'; +open my $fh, '>', $file + or die "Can't open $file: $!"; + +my $error; + # If any of the system's build tools are written in Perl, then this module # may well be loaded by a much older version than we are building. So keep it # as backwards compatible as is easy. -print <<"EOT"; +print $fh <<"EOT" or $error = "Can't print to $file: $!"; #!perl # We are miniperl, building extensions @@ -53,3 +60,24 @@ print <<"EOT"; # installed directories (which we don't need to read, and may confuse us) \@INC = ($inc); EOT + +if ($error) { + close $fh + or warn "Can't unlink $file after error: $!"; +} else { + close $fh and exit; + $error = "Can't close $file: $!"; +} + +# It's going very wrong, so try to remove the botched file. + +unlink $file + or warn "Can't unlink $file after error: $!"; +die $error; + +# Local variables: +# cperl-indent-level: 4 +# indent-tabs-mode: nil +# End: +# +# ex: set ts=8 sts=4 sw=4 et: -- cgit v1.2.1