blib/lib/App/hopen/Gen/Ninja.pm

filter: Statementstmt 88.0% 59 / 67 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.9% 17 / 21 Podpod 100% 2 / 2 totaltotal 84.3% 81 / 96 CC 4 SCAR 5.4
CC
4
Cov
85%
_run_build
6.0
finalize
3.0
__ANON__
2.0
CRAP 1.7
« blib/lib/App/hopen/T/Gnu/C.pm ↑ Summary blib/lib/App/hopen/G/FilesCmd.pm »
1 # App::hopen::Gen::Ninja - generator for ninja(1).
2 package App::hopen::Gen::Ninja;
3 1 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Data::Hopen::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # TODO reduce code duplication between this and Gen::Make
7  
8 1 our $VERSION = '0.000013'; # TRIAL
9  
10 1 ▶use parent 'App::hopen::Gen';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Class::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use App::hopen::BuildSystemGlobals;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use App::hopen::Phases qw(is_last_phase);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Data::Hopen qw(:default getparameters *QUIET);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Data::Hopen::Scope::Hash;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Data::Hopen::Util::Data qw(forward_opts);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use File::Which;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Quote::Code;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶use App::hopen::Gen::Ninja::AssetGraphNode; # for $OUTPUT
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 # Docs {{{1
25  
26 =head1 NAME
27  
28 App::hopen::Gen::Ninja - hopen generator for simple Ninja files
29  
30 =head1 SYNOPSIS
31  
32 This generator makes a build.ninja file.
33  
34 =head1 FUNCTIONS
35  
36 =cut
37  
38 # }}}1
39  
40 =head2 finalize
41  
42 Write out the Ninja file. Usage:
43  
44 $Generator->finalize($dag); # $data parameter unused
45  
46 C<$dag> is the build graph.
47  
48 =cut
49  
50 sub finalize {
51 2 ▶ my ($self, %args) = getparameters('self', [qw(dag; data)], @_);
Subroutine finalize: called CC=3 SCAR=11.1
Pod documented
52 2 ▶ hlog { Finalizing => __PACKAGE__ , '- phase', $Phase };
Subroutine __ANON__: not called CC=1 SCAR=1.2
53 2 ▶ return unless is_last_phase $Phase;
Branch: 1 branch
BranchTrueFalseTotal
unless is_last_phase($App::hopen::Gen::Ninja::Phase) 1 1 2
54  
55 1 ▶ hlog { __PACKAGE__, 'Asset graph', '' . $self->_assets->_graph } 3;
Subroutine __ANON__: not called CC=1 SCAR=1.2
56  
57 # During the Gen phase, create the Ninja file
58 1 ▶ open my $fh, '>', $self->dest_dir->file('build.ninja')
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $self->dest_dir->file("build.ninja") or die "Couldn't create Ninja file" 0 1 1
59 or die "Couldn't create Ninja file";
60 print $fh qc_to <<"EOT";
61 1 # Ninja file generated by hopen (https://github.com/hopenbuild/App-hopen)
62 1 # at #{gmtime} GMT
63 # From ``#{$self->proj_dir->absolute}'' into ``#{$self->dest_dir->absolute}''
64  
65 EOT
66  
67 # # Make sure the first goal is 'all' regardless of order.
68 # say $fh qc'first__goal__: {$args{dag}->default_goal->name}\n';
69  
70 1 my $context = Data::Hopen::Scope::Hash->new;
71 1 $context->put(App::hopen::Gen::Ninja::AssetGraphNode::OUTPUT, $fh);
72  
73 # Write the Ninja file. TODO? flip the order?
74  
75 1 $self->_assets->run(-context => $context);
76  
77 1 close $fh;
78 } #finalize()
79  
80 =head2 default_toolset
81  
82 Returns the package name of the default toolset for this generator,
83 which is C<Gnu> (i.e., L<App::hopen::T::Gnu>).
84  
85 =cut
86  
87 2 ▶sub default_toolset { 'Gnu' }
Subroutine default_toolset: called CC=1 SCAR=0.0
Pod documented
88  
89 =head2 _assetop_class
90  
91 The class of asset-graph operations, which in this case is
92 L<App::hopen::Gen::Ninja::AssetGraphNode>.
93  
94 =cut
95  
96 4 ▶sub _assetop_class { 'App::hopen::Gen::Ninja::AssetGraphNode' }
Subroutine _assetop_class: called CC=1 SCAR=0.0
97  
98 =head2 _run_build
99  
100 Implementation of L<App::hopen::Gen/run_build>.
101  
102 =cut
103  
104 sub _run_build {
105 # Look for the make(1) executable. Listing make before gmake since a
106 # system with both Cygwin and Strawberry Perl installed has cygwin's
107 # make(1) and Strawberry's gmake(1).
108 0 ▶ my $path = File::Which::which('ninja');
Subroutine _run_build: not called CC=2 SCAR=17.9
109 0 ▶ if(defined $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $path) { } 0 0 0
110 0 ▶ hlog { Running => $path };
Subroutine __ANON__: not called CC=1 SCAR=6.9
111 0 system $path, ();
112 } else {
113 0 warn "Could not find the 'ninja' program";
114 }
115 } #_run_build()
116  
117 1 1;
118 __END__
119 # vi: set fdm=marker: #
« blib/lib/App/hopen/T/Gnu/C.pm ↑ Summary blib/lib/App/hopen/G/FilesCmd.pm »