Alien-AntTweakBar
view release on metacpan or search on metacpan
inc/My/Builder.pm view on Meta::CPAN
$archive = $self->fetch_file([$url], $sha1, $download)
|| die "###ERROR### Download failed\n";
}
print STDERR "Checking checksum '$archive'...\n";
#extract source codes
my $extract_src = 'y';
if (lc($extract_src) eq 'y') {
my $ae = Archive::Extract->new( archive => $archive );
$ae->extract(to => $build_src) || die "###ERROR### Cannot extract tarball ", $ae->error;
die "###ERROR### Cannot find expected dir='",$self->notes('src_dir'),"'"
unless -d $self->notes('src_dir');
}
$self->prebuild if $self->can('prebuild');
$self->build_binaries if $self->can('build_binaries');
$self->preinstall_binaries($build_out);
$self->config_data('share_subdir', $self->{properties}->{dist_version});
$self->config_data('config', {
PREFIX => '@PrEfIx@',
libs => '-L' . $self->quote_literal('@PrEfIx@/lib') . ' -lAntTweakBar',
cflags => '-I' . $self->quote_literal('@PrEfIx@/include'),
});
}
# mark sucessfully finished build
local @ARGV = ('build_done');
ExtUtils::Command::touch;
}
$self->SUPER::ACTION_code;
}
sub fetch_file {
my ($self, $url_list, $sha1sum, $download) = @_;
die "###ERROR### _fetch_file undefined url\n" unless $url_list;
die "###ERROR### _fetch_file undefined sha1sum\n" unless $sha1sum;
for my $url (@$url_list) {
my $ff = File::Fetch->new(uri => $url);
my $fn = catfile($download, $ff->file);
if (-e $fn) {
print STDERR "Checking checksum for already existing '$fn'...\n";
return $fn if $self->check_sha1sum($fn, $sha1sum);
unlink $fn; #exists but wrong checksum
}
print STDERR "Fetching '$url' ...\n";
my $fullpath = $ff->fetch(to => $download);
if ($fullpath && -e $fullpath && $self->check_sha1sum($fullpath, $sha1sum)) {
print STDERR "Download OK (filesize=".(-s $fullpath).")\n";
return $fullpath;
}
warn "###WARNING### Unable to fetch '$url'\n";
}
return;
}
sub check_sha1sum {
my ($self, $file, $sha1sum) = @_;
my $sha1 = Digest::SHA->new;
my $fh;
open($fh, $file) or die "###ERROR## Cannot check checksum for '$file'\n";
binmode($fh);
$sha1->addfile($fh);
close($fh);
my $rv = ($sha1->hexdigest eq $sha1sum) ? 1 : 0;
warn "###WARN## sha1 mismatch: got '", $sha1->hexdigest , "'\n",
"###WARN## sha1 mismatch: expected '", $sha1sum, "'\n",
"###WARN## sha1 mismatch: filesize '", (-s $file), "'\n", unless $rv;
return $rv;
}
sub clean_dir {
my( $self, $dir ) = @_;
if (-d $dir) {
File::Path::rmtree($dir);
File::Path::mkpath($dir);
}
}
sub quote_literal {
# this can be be overriden in My::Builder::<platform>
my ($self, $path) = @_;
return $path;
}
# pure perl implementation of patch functionality
sub apply_patch {
my ($self, $dir_to_be_patched, $patch_file) = @_;
my ($src, $diff);
undef local $/;
open(DAT, $patch_file) or die "###ERROR### Cannot open file: '$patch_file'\n";
$diff = <DAT>;
close(DAT);
$diff =~ s/\r\n/\n/g; #normalise newlines
$diff =~ s/\ndiff /\nSpLiTmArKeRdiff /g;
my @patches = split('SpLiTmArKeR', $diff);
print STDERR "Applying patch file: '$patch_file'\n";
foreach my $p (@patches) {
my ($k) = map{$_ =~ /\n---\s*([\S]+)/} $p;
# doing the same like -p1 for 'patch'
$k =~ s|\\|/|g;
$k =~ s|^[^/]*/(.*)$|$1|;
$k = catfile($dir_to_be_patched, $k);
print STDERR "- gonna patch '$k'\n" if $self->notes('build_debug_info');
open(SRC, $k) or die "###ERROR### Cannot open file: '$k'\n";
$src = <SRC>;
close(SRC);
$src =~ s/\r\n/\n/g; #normalise newlines
my $out = eval { Text::Patch::patch( $src, $p, { STYLE => "Unified" } ) };
if ($out) {
open(OUT, ">", $k) or die "###ERROR### Cannot open file for writing: '$k'\n";
print(OUT $out);
close(OUT);
}
else {
warn "###WARN### Patching '$k' failed: $@";
}
}
( run in 0.845 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )