| 1 | package App::ArduinoBuilder::DepCheck; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use File::Spec::Functions; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Log::Any::Simple ':default'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | our @EXPORT_OK = qw(check_dep); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # Returns true if the target needs to be rebuilt. | ||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub check_dep { | ||||||||||||||||||||||||||
|
Subroutine
check_dep: not called CC=15 SCAR=54.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | 0 | my ($source, $target) = @_; | |||||||||||||||||||||||||||
| 17 | 0 | ▶ | fatal "Can’t find source file: ${source}" unless -f $source; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 0 | my $source_time = -M _; # Note: this is negated mtime due to a weird Perl quirk. | |||||||||||||||||||||||||||
| 19 | 0 | ▶ | unless (-f $target) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 0 | trace "Rebuilding ${source} because ${target} does not exist"; | |||||||||||||||||||||||||||
| 21 | 0 | return 1; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | # In some error situation a 0 byte .o file is written, let’s assume that a valid output is | ||||||||||||||||||||||||||||
| 24 | # never empty (which would not be true in the general case for a build system). | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if (-z _) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 0 | trace "Rebuilding ${source} because ${target} is empty"; | |||||||||||||||||||||||||||
| 27 | 0 | return 1; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | 0 | my $target_time = -M _; | |||||||||||||||||||||||||||
| 30 | 0 | ▶ | if ($source_time < $target_time) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 0 | trace "Rebuilding ${source} because of ${target}"; | |||||||||||||||||||||||||||
| 32 | 0 | return 1; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | my $d_file = catfile(dirname($target), basename($source).'.d'); | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | unless (-f $d_file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | warning "Dependency file does not exist: ${d_file}"; | |||||||||||||||||||||||||||
| 38 | 0 | return 0; # We assume that there is no other dependency. | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if ($source_time < -M _) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | trace "Rebuilding ${source} because it’s newer than dependency file ${d_file}"; | |||||||||||||||||||||||||||
| 42 | 0 | return 1; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | # If we don’ use the crlf layer our regex can fail on Cygwin when reading | ||||||||||||||||||||||||||||
| 46 | # files generated by a Windows toolchain. | ||||||||||||||||||||||||||||
| 47 | # BUG: one line of the dependency file can contain several file names, | ||||||||||||||||||||||||||||
| 48 | # separated by spaces (but we need to catch spaces in the name of files too). | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | open my $fh, '<:crlf', $d_file or fatal "Can’t open dependency file '${d_file}': $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | my $l = <$fh>; | |||||||||||||||||||||||||||
| 51 | # We force a space after the colon to avoid matching $1 to C in C:\foo\... | ||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ($l !~ m/^\s*(.*?)\s*:\s+(.*?)?\s*\\?$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | error "Can’t parse dependency file: ${d_file}"; | |||||||||||||||||||||||||||
| 54 | 0 | debug "Unparsable line: $l"; | |||||||||||||||||||||||||||
| 55 | 0 | return 1; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | # we could test that rel2abs($1) eq rel2abs($target) | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ($2 && -M $1 < $target_time) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$2 and -M $1 < $target_time
MC/DC0%0/2
$2 and -M $1 < $target_time
$2
-M $1 < $target_time
Truth table0%0/3
A and B
A= $2B= -M $1 < $target_time
| |||||||||||||||||||||||||||||
| 59 | 0 | trace "Rebuilding ${source} because of ${2}"; | |||||||||||||||||||||||||||
| 60 | 0 | return 1; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | while (my $l = <$fh>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ($l !~ m/^\s*(.*?)?\s*\\?$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | error "Can’t parse dependency file: ${d_file}"; | |||||||||||||||||||||||||||
| 66 | 0 | debug "Unparsable line: $l"; | |||||||||||||||||||||||||||
| 67 | 0 | return 1; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if ($1 && -M $1 < $target_time) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$1 and -M $1 < $target_time
MC/DC0%0/2
$1 and -M $1 < $target_time
$1
-M $1 < $target_time
Truth table0%0/3
A and B
A= $1B= -M $1 < $target_time
| |||||||||||||||||||||||||||||
| 70 | 0 | trace "Rebuilding ${source} because of ${1}"; | |||||||||||||||||||||||||||
| 71 | 0 | return 1; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 0 | trace "Not rebuilding ${target}, it is up-to-date"; | |||||||||||||||||||||||||||
| 75 | 0 | close $fh; | |||||||||||||||||||||||||||
| 76 | 0 | return 0; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 1 | 1; | |||||||||||||||||||||||||||