"Ken Williams via RT" <bug-Module-Build@rt.cpan.org> writes:
Show quoted text
Show quoted text> Hi Russ, there is already a method `$m->add_to_cleanup(...)` which
> behaves very similarly to what you're proposing. Is there a distinction
> between that & what you'd like?
add_to_cleanup deletes the files on ./Build clean, which is normally what
you want. But if you create files during perl Build.PL instead of via
./Build, and then remove them on ./Build clean, you get stuck; ./Build or
./Build test would now fail (assuming the files are needed for something).
Of course, that prompts the question "why are you creating files during
perl Build.PL"? The answer is that I need to generate some Perl scripts
that are used by one of the test cases, and I couldn't figure out another
good way of using fix_shebang_line to get the proper path to Perl without
modifying a distributed file in place (which causes it to show up with
uncommitted changes in the revision control system and just seems not very
clean).
It seemed easier just add Perl code to the bottom of Build.PL to create
those files than to try to figure out the right ./Build target to override
to create them, but then I ran into this problem. Maybe I'm just doing it
wrong, though? I suppose I could override ACTION_test to create the files
in advance of running the test suite, but that also seems awkward.
The code I currently have in Build.PL looks like:
# Create a command script that will be run by remctld during the test suite.
# These scripts will be stored in the t/data directory.
#
# $build - Module::Build object
# $name - Name of command
# $code - Perl code, as a string, to put into the script
#
# Returns: undef
# Throws: Text exceptions on I/O failures
sub create_command {
my ($build, $name, $code) = @_;
my $path = File::Spec->catfile(qw(t data), $name);
# Create the file.
open(my $command, q{>}, $path)
or die "Cannot create $path: $!\n";
print {$command} "#!/usr/bin/perl\nuse strict;\nuse warnings;\n"
or die "Cannot write to $path: $!\n";
print {$command} $code, "\n"
or die "Cannot write to $path: $!\n";
close($command)
or die "Cannot write to $path: $!\n";
# Fix the shebang line.
$build->fix_shebang_line($path);
# Set permissions, which seems to be un-done by fix_shebang_line.
chmod(0755, $path)
or die "Cannot set permissions on $path: $!\n";
return;
}
# [...]
# Generate the build script.
$build->create_build_script;
# Generate the commands that will be run by remctld during the test suite.
## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
create_command($build, 'cmd-hello', 'print "hello world\n" or die "fail\n"');
create_command($build, 'cmd-sleep', 'sleep 3;');
and I then want to add t/data/cmd-hello and t/data/cmd-sleep to the files
that are deleted by the realclean target.
This is equivalent to the ExtUtils::MakeMaker realclean => { FILES => ''}
option.
--
Russ Allbery (rra@stanford.edu) <
http://www.eyrie.org/~eagle/>