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