ArduinoBuilder/DepCheck.pm

filter: Statementstmt 36.5% 23 / 63 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 1 totaltotal 28.3% 30 / 106 CC 15 SCAR 51.0
CC
15
Cov
25%
check_dep
240.0
BEGIN
1.0
BEGIN
1.0
CRAP 164.0
« ArduinoBuilder.pm ↑ Summary ArduinoBuilder/Monitor.pm »
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
BranchTrueFalseTotal
unless -f $source 0 0 0
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
BranchTrueFalseTotal
unless (-f $target) 0 0 0
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
BranchTrueFalseTotal
if (-z _) 0 0 0
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
BranchTrueFalseTotal
if ($source_time < $target_time) 0 0 0
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
BranchTrueFalseTotal
unless (-f $d_file) 0 0 0
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
BranchTrueFalseTotal
if ($source_time < -M _) 0 0 0
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
BranchTrueFalseTotal
open my $fh, "<:crlf", $d_file or fatal("Can\x{2019}t open dependency file '${d_file}': $!") 0 0 0
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
BranchTrueFalseTotal
unless ($l =~ /^\s*(.*?)\s*:\s+(.*?)?\s*\\?$/) 0 0 0
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
BranchTrueFalseTotal
if ($2 and -M $1 < $target_time) 0 0 0
Condition0%0/3
$2 and -M $1 < $target_time
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
59 0 trace "Rebuilding ${source} because of ${2}";
60 0 return 1;
61 }
62  
63 0 ▶ while (my $l = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $l = readline $fh)) 0 0 0
64 0 ▶ if ($l !~ m/^\s*(.*?)?\s*\\?$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($l =~ /^\s*(.*?)?\s*\\?$/) 0 0 0
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
BranchTrueFalseTotal
if ($1 and -M $1 < $target_time) 0 0 0
Condition0%0/3
$1 and -M $1 < $target_time
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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;
« ArduinoBuilder.pm ↑ Summary ArduinoBuilder/Monitor.pm »