| 1 | 245 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 2 | 245 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 245 | ▶ | use MIME::Base64 qw(decode_base64); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 245 | ▶ | use File::Copy (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 245 | ▶ | use File::Path 'mkpath'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 245 | ▶ | use File::Basename 'basename', 'dirname'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 245 | ▶ | use Carp 'confess'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | # Get arguments | ||||||||||||||
| 10 | 245 | my @argv = split("\0", decode_base64($ARGV[0])); | |||||||||||||
| 11 | 245 | my ($command_tmp_dir, $output_file, @cc_cmd) = @argv; | |||||||||||||
| 12 | |||||||||||||||
| 13 | # Define log file paths | ||||||||||||||
| 14 | 245 | my $log_stdout = "$command_tmp_dir/stdout.log"; | |||||||||||||
| 15 | 245 | my $log_stderr = "$command_tmp_dir/stderr.log"; | |||||||||||||
| 16 | |||||||||||||||
| 17 | # Redirect stdout and stderr to log files | ||||||||||||||
| 18 | 245 | ▶ | open(STDOUT, '>', $log_stdout) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 19 | or die "Can't open file '$log_stdout': $!"; | ||||||||||||||
| 20 | 245 | ▶ | open(STDERR, '>', $log_stderr) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 21 | or die "Can't open file '$log_stderr': $!"; | ||||||||||||||
| 22 | |||||||||||||||
| 23 | 245 | $cc_cmd[-1] .= $output_file; | |||||||||||||
| 24 | |||||||||||||||
| 25 | 245 | mkpath dirname $output_file; | |||||||||||||
| 26 | |||||||||||||||
| 27 | # Execute the command | ||||||||||||||
| 28 | 245 | my $system_status = system(@cc_cmd); | |||||||||||||
| 29 | |||||||||||||||
| 30 | 245 | ▶ | if ($system_status == -1) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 31 | 0 | die "Failed to execute compilation command. \$!=$!, \@cc_cmd='@cc_cmd'"; | |||||||||||||
| 32 | } | ||||||||||||||
| 33 | elsif ($system_status & 127) { | ||||||||||||||
| 34 | 0 | my $signal = $system_status & 127; | |||||||||||||
| 35 | 0 | die "Compilation command died with signal. \$signal=$signal, \@cc_cmd='@cc_cmd'"; | |||||||||||||
| 36 | } | ||||||||||||||
| 37 | else { | ||||||||||||||
| 38 | 245 | my $exit_status = $system_status >> 8; | |||||||||||||
| 39 | 245 | ▶ | if ($exit_status != 0) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 40 | 0 | die "Compilation command failed with exit code. \$exit_status=$exit_status, \@cc_cmd='@cc_cmd'"; | |||||||||||||
| 41 | } | ||||||||||||||
| 42 | } | ||||||||||||||