diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-06-06 17:50:16 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-06-06 17:50:16 +0000 |
commit | 5ac2026f7eed78958d69d051e7a8e993dcf51205 (patch) | |
tree | 298c3d2f08bdfe5689998b11892d72a897985be1 /inc/Clean.pm | |
download | Moose-tarball-5ac2026f7eed78958d69d051e7a8e993dcf51205.tar.gz |
Moose-2.1405HEADMoose-2.1405master
Diffstat (limited to 'inc/Clean.pm')
-rw-r--r-- | inc/Clean.pm | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/inc/Clean.pm b/inc/Clean.pm new file mode 100644 index 0000000..a2a5563 --- /dev/null +++ b/inc/Clean.pm @@ -0,0 +1,50 @@ +package inc::Clean; +use Moose; + +with 'Dist::Zilla::Role::BeforeBuild', + 'Dist::Zilla::Role::AfterBuild'; +use Path::Tiny; +use File::pushd 'pushd'; +use Config; + +sub before_build { shift->_clean('.') } + +sub after_build { + my ($self, $opts) = @_; + + $self->_clean($opts->{build_root}); + + my $iter = path($opts->{build_root})->iterator({ recurse => 1 }); + my %found_files; + while (my $found_file = $iter->()) { + next if -d $found_file; + ++$found_files{ $found_file->relative($opts->{build_root}) }; + } + delete $found_files{$_->name} foreach @{ $self->zilla->files }; + + $self->log(join("\n", + "WARNING: Files were left behind in $opts->{build_root} that were not explicitly added:", + sort keys %found_files, + )) if keys %found_files; +} + +sub _clean { + my ($self, $build_dir) = @_; + + my $cwd = pushd $build_dir; + if (-e 'Makefile') { + + my $make = $Config{make} || 'make'; + + $self->log("Running $make distclean in $build_dir to clear out build cruft"); + my $pid = fork; + unless ($pid) { + close(STDIN); + close(STDOUT); + close(STDERR); + { exec("$^X Makefile.PL && $make distclean") } + die "couldn't exec: $!"; + } + waitpid($pid, 0) if $pid; + } +} |