Alien-IUP
view release on metacpan or search on metacpan
inc/My/Builder.pm view on Meta::CPAN
my $rv1 = run3("$Config{cc} -c -o $obj $src $cflags", \undef, \$output, \$output, { return_if_system_error => 1 } );
unless ($rv1 == 1 && $? == 0) {
#print STDERR "OUTPUT(compile):\n$output\n" if $output;
return 0
}
my $rv2 = run3("$Config{ld} $obj -o $exe $lflags $liblist", \undef, \$output, \$output, { return_if_system_error => 1 } );
unless ($rv2 == 1 && $? == 0) {
#print STDERR "OUTPUT(link):\n$output\n" if $output;
return 0
}
return 1;
}
# 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');
if (open(SRC, $k)) {
$src = <SRC>;
close(SRC);
$src =~ s/\r\n/\n/g; #normalise newlines
}
else {
$src = '';
}
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: $@";
}
}
}
sub run_output_tail {
my ($self, $limit, @cmd) = @_;
my $output;
print STDERR "CMD: " . join(' ',@cmd) . "\n";
print STDERR "- running (stdout+stderr redirected)...\n";
my $rv = run3(\@cmd, \undef, \$output, \$output, { return_if_system_error => 1 } );
my $success = ($rv == 1 && $? == 0) ? 1 : 0;
$output = substr $output, -$limit if defined $limit; # we want just last N chars
if (!defined($limit)) {
print STDERR "OUTPUT:\n", $output, "\n";
}
elsif ($limit>0) {
print STDERR "OUTPUT: (only last $limit chars)\n", $output, "\n";
}
return $success;
}
sub run_output_on_error {
my ($self, $limit, @cmd) = @_;
my $output;
print STDERR "CMD: " . join(' ',@cmd) . "\n";
print STDERR "- running (stdout+stderr redirected)...\n";
my $rv = run3(\@cmd, \undef, \$output, \$output, { return_if_system_error => 1 } );
my $success = ($rv == 1 && $? == 0) ? 1 : 0;
if ($success) {
print STDERR "- finished successfully (output suppressed)\n";
}
else {
$output = substr $output, -$limit if defined $limit; # we want just last N chars
if (!defined($limit)) {
print STDERR "OUTPUT:\n", $output, "\n";
}
elsif ($limit>0) {
print STDERR "OUTPUT: (only last $limit chars)\n", $output, "\n";
}
}
return $success;
}
sub run_output_std {
my ($self, @cmd) = @_;
print STDERR "CMD: " . join(' ',@cmd) . "\n";
my $rv = run3(\@cmd, undef, undef, undef, { return_if_system_error => 1 } );
my $success = ($rv == 1 && $? == 0) ? 1 : 0;
print STDERR "- finished successfully\n" if ($success);
return $success;
}
sub run_stdout2str {
my ($self, @cmd) = @_;
my $output;
my $rv = run3(\@cmd, \undef, \$output, \undef, { return_if_system_error => 1 } );
$output =~ s/[\r\n]*$//;
return $output;
}
sub run_bothout2str {
my ($self, @cmd) = @_;
my $output;
my $rv = run3(\@cmd, \undef, \$output, \$output, { return_if_system_error => 1 } );
$output =~ s/[\r\n]*$//;
return $output;
}
sub run_custom {
my ($self, @cmd) = @_;
my $rv;
if ($self->notes('build_msgs')) {
$rv = $self->run_output_std(@cmd);
}
else {
$rv = $self->run_output_on_error($self->notes('build_msgs_limit'), @cmd);
}
warn "###WARN### error during run_custom()" unless $rv;
return $rv;
}
sub find_file {
my ($self, $dir, $re) = @_;
my @files;
$re ||= qr/.*/;
{
( run in 0.449 second using v1.01-cache-2.11-cpan-85f18b9d64f )