/home/cpancover/.cpan/build/Makefile-Parser-0.215-0/script/makesimple

filter: Statementstmt 58.5% 65 / 111 Branchbran 34.3% 11 / 32 Conditioncond 33.3% 5 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 81.8% 9 / 11 Podpod n/a totaltotal 50.5% 90 / 178 SCAR 20.7
CC
5
Cov
51%
__ANON__
30.0
__ANON__
2.0
BEGIN
1.0
CRAP 7.9
« blib/lib/Makefile/AST/StemMatch.pm ↑ Summary blib/lib/Makefile/AST/Command.pm »
1 #!/usr/bin/env perl
2  
3 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 28 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 #use lib qw(/home/agentz/gmake-db/lib /home/agentz/mdom-gmake/lib);
6  
7 #use Smart::Comments;
8 #use Smart::Comments '####';
9 28 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 28 ▶use Makefile::Parser::GmakeDB;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 28 ▶use IPC::Run3;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 28 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 28 ▶use Makefile::AST::Evaluator;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 28 ▶use List::Util 'first';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 28 my $VERSION = $Makefile::Parser::GmakeDB::VERSION;
17  
18 28 my @DefaultMakefile = (
19 'GNUmakefile',
20 'makefile',
21 'Makefile'
22 );
23  
24 28 my $user_makefile;
25 my $print_version;
26 28 my ($makefile, $njobs, @goals);
27 28 Getopt::Long::Configure ("bundling");
28 28 ▶GetOptions(
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("f|file|makefile=s", \$user_makefile, "v|version", \$print_version) or die "Usage: $0 [-f makefile] goals...\n" 0 28 28
29 'f|file|makefile=s' => \$user_makefile,
30 'v|version' => \$print_version,
31 ) or die "Usage: $0 [-f makefile] goals...\n";
32 ### $makefile
33 ### @ARGV
34  
35 28 $Makefile::AST::Evaluator::JustPrint = 0;
36 28 $Makefile::AST::Evaluator::Quiet = 1;
37 28 $Makefile::AST::Evaluator::IgnoreErrors = 1;
38 28 $Makefile::AST::Evaluator::AlwaysMake = 1;
39 28 $Makefile::AST::Evaluator::Question = 1;
40  
41 28 ▶if ($print_version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($print_version) 0 28 28
42 0 print <<"_EOC_";
43 makesimple $VERSION
44 _EOC_
45 0 exit 0;
46 }
47  
48 28 our $MAKE;
49 28 my @var_defs;
50 28 for my $arg (@ARGV) {
51 5 ▶ if ($arg =~ /(.*?)=(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /(.*?)=(.*)/) { } 4 1 5
52 4 my ($var, $value) = ($1, $2);
53 4 ▶ if ($var eq 'MAKE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($var eq "MAKE") 0 4 4
54 0 $MAKE = $value;
55 }
56 4 push @var_defs, $arg;
57 } else {
58 1 push @goals, $arg;
59 }
60 }
61 28 ▶if (!defined $MAKE) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $main::MAKE) 28 0 28
62 28 ($MAKE = $0) =~ s/.*[\\\/]//;
63 }
64  
65 28 $makefile = $user_makefile;
66 28 ▶if (!defined $makefile) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $makefile) { } 0 28 28
elsif ($makefile ne '-' and not -f $makefile) { } 0 28 28
67 0 ▶ $makefile = first { -f $_ } @DefaultMakefile;
Subroutine __ANON__: not called CC=1 SCAR=6.9
68 ▶} elsif ($makefile ne '-' and !-f $makefile) {
Condition33%1/3
$makefile ne "-" and not -f $makefile
!ll&&!rl&&r
0280
MC/DC0%0/2
$makefile ne "-" and not -f $makefile
$makefile ne "-" not -f $makefile
Truth table33%1/3
A and not(B)
A= $makefile ne "-"B= not -f $makefile
ABresult
0X0
100
111
69 0 warn "$MAKE: $makefile: No such file or directory\n";
70 0 push @goals, $makefile; # This is required
71 }
72  
73 ### var defs via command line: @var_defs
74  
75 28 my $level = $ENV{MAKESIMPLE_LEVEL};
76 28 ▶if (!defined $level) { $level = 0; }
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $level) { } 28 0 28
77 0 else { $level++ }
78 #### %ENV
79 28 $ENV{MAKELEVEL} = $level;
80 28 $ENV{MAKESIMPLE_LEVEL} = $level;
81  
82 28 my ($stdout, $stderr);
83 28 run3 ['make', '-pqRrs', '-f', $makefile, @var_defs], undef, \$stdout, \$stderr;
84 ## $stderr
85 28 my $exit_code = $? >> 8;
86 28 ▶if ($stderr and $exit_code == 2 and $stderr !~ /^make:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stderr and $exit_code == 2 and not $stderr =~ /^make:/) 0 28 28
Condition66%4/6
$stderr and $exit_code == 2 and not $stderr =~ /^make:/
!ll&&!rl&&r
1990
$stderr and $exit_code == 2
!ll&&!rl&&r
1909
MC/DC0%0/3
$stderr and $exit_code == 2 and not $stderr =~ /^make:/
$stderr $exit_code == 2 not $stderr =~ /^make:/
Truth table0%0/4
A and B and not(C)
A= $stderrB= $exit_code == 2C= not $stderr =~ /^make:/
ABCresult
0XX0
10X0
1100
1111
87 0 $stderr =~ s/^make:/$MAKE:/msg;
88 0 warn $stderr;
89 0 exit $exit_code;
90 }
91 28 ▶if ($stderr =~ /warning: (overriding|ignoring old) commands for target/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stderr =~ /warning: (overriding|ignoring old) commands for target/) 0 28 28
92 0 warn $stderr;
93 }
94  
95 #die "GNU make stdout: $stdout\n";
96  
97 # XXX debug only
98 #write_file('/home/agentz/mdom-gmake/make.db', $stdout);
99  
100 # patch the database output to work around gmake bugs
101 28 patch_database(\$stdout);
102  
103 # XXX debug only
104 #write_file('/home/agentz/mdom-gmake/make.db.patched', $stdout);
105  
106 #if ($stdout =~ m{^\s*\./Makefile_\S+\s*:\s*[^\n]*$}ms) {
107 # die $&;
108 #}
109 #print $stdout;
110 #exit 0;
111  
112 28 $Makefile::AST::Runtime = 0;
113  
114 28 my $ast = Makefile::Parser::GmakeDB->parse(\$stdout);
115 0 $ast->{makefile} = $makefile;
116 ## $ast
117 ## var a: $ast->get_var('a')
118 ## var b: $ast->get_var('b')
119 #die;
120  
121 0 my $default_goal = $ast->default_goal;
122 0 ▶push @goals, $ast->default_goal
Branch: 1 branch
BranchTrueFalseTotal
if not @goals and defined $default_goal 0 0 0
Condition0%0/3
not @goals and defined $default_goal
!ll&&!rl&&r
000
MC/DC0%0/2
not @goals and defined $default_goal
not @goals defined $default_goal
Truth table0%0/3
not(A) and B
A= not @goalsB= defined $default_goal
ABresult
0X0
100
111
123 if !@goals && defined $default_goal;
124 ### @goals
125  
126 0 ▶if (!@goals && !defined $makefile) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@goals or defined $makefile) 0 0 0
Condition0%0/3
@goals or defined $makefile
l!l&&r!l&&!r
000
MC/DC0%0/2
@goals or defined $makefile
@goals defined $makefile
Truth table0%0/3
A or B
A= @goalsB= defined $makefile
ABresult
1X1
011
000
127 0 warn "$MAKE: *** No targets specified and no makefile found. Stop.\n";
128 0 exit(2);
129 }
130  
131 # XXX uniq @goals?
132 0 push @goals, keys %{ $ast->targets }, keys %{ $ast->prereqs };
133  
134 0 $ast->add_var(Makefile::AST::Variable->new({
135 name => 'MAKE',
136 flavor => 'simple',
137 value => ['$(MAKE)'],
138 origin => 'default',
139 }));
140 0 my $eval = Makefile::AST::Evaluator->new($ast);
141  
142 0 my @simple_rules;
143 my @str_for_default;
144 0 my @str_for_others;
145 Makefile::AST::Evaluator->add_trigger(
146 firing_rule => sub {
147 0 ▶ my ($self, $rule, $ast_cmds) = @_;
Subroutine __ANON__: not called CC=5 SCAR=34.0
148 ### $rule
149 ### $ast_cmds
150 0 my $str;
151 0 my $target = $rule->target;
152 0 my $colon = $rule->colon;
153 0 my @normal_prereqs = @{ $rule->normal_prereqs };
154 0 ▶ my $normal_prereqs =
Branch: 1 branch
BranchTrueFalseTotal
@normal_prereqs ? : 0 0 0
155 @normal_prereqs ? " @normal_prereqs" : '';
156 0 my @order_prereqs = @{ $rule->order_prereqs };
157 0 ▶ my $order_prereqs =
Branch: 1 branch
BranchTrueFalseTotal
@order_prereqs ? : 0 0 0
158 @order_prereqs ? " | @order_prereqs" : '';
159 0 $str .= $target.$colon.$normal_prereqs.$order_prereqs."\n";
160 0 for my $cmd (@$ast_cmds) {
161 0 $str .= "\t" . $cmd->as_str . "\n";
162 }
163 0 ▶ if ($target eq $default_goal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target eq $default_goal) { } 0 0 0
164 0 push @str_for_default, $str;
165 } else {
166 0 push @str_for_others, $str;
167 }
168 }
169 0 );
170 0 ▶$eval->set_required_target($user_makefile)
Branch: 1 branch
BranchTrueFalseTotal
if defined $user_makefile 0 0 0
171 if defined $user_makefile;
172 #warn "Default goal: $default_goal\n";
173 0 for my $goal (@goals) {
174 ### goal: $goal
175 0 $eval->make($goal);
176 }
177  
178 0 print join "\n", @str_for_default, @str_for_others;
179  
180 # XXX promote the fixes on the GNU make side
181 sub patch_database {
182 28 ▶ my $ref = shift;
Subroutine patch_database: called CC=1 SCAR=0.0
183 #$$ref =~ s/(\n\S+)#/$1\\#$2/gsm;
184 28 $$ref =~ s/^([^\n]*)(?<!\\)\\(\S[^\n]*\n# Implicit rule search has)/$1\\\\$2/msg;
185 28 $$ref =~ s/^([^\n]*)(?<!\\)#(\S[^\n]*\n# Implicit rule search has)/$1\\#$2/msg;
186 28 $$ref =~ s/^([^\n]*)(?<!\\):(\S[^\n]*:\n# Implicit rule search has)/$1\\:$2/msg;
187 }
188 __END__
« blib/lib/Makefile/AST/StemMatch.pm ↑ Summary blib/lib/Makefile/AST/Command.pm »