File Coverage

blib/lib/App/hopen/Gen/Ninja.pm
Criterion Covered Total %
statement 57 65 87.6
branch 3 6 50.0
condition n/a
subroutine 17 21 80.9
pod 2 2 100.0
total 79 94 84.0


line stmt bran cond sub pod time code
1             # App::hopen::Gen::Ninja - generator for ninja(1).
2             package App::hopen::Gen::Ninja;
3 1     1   752 use strict; use warnings;
  1     1   2  
  1         33  
  1         5  
  1         2  
  1         31  
4 1     1   5 use Data::Hopen::Base;
  1         2  
  1         8  
5              
6             # TODO reduce code duplication between this and Gen::Make
7              
8             our $VERSION = '0.000013'; # TRIAL
9              
10 1     1   1457 use parent 'App::hopen::Gen';
  1         2  
  1         10  
11 1     1   71 use Class::Tiny;
  1         2  
  1         6  
12              
13 1     1   39 use App::hopen::BuildSystemGlobals;
  1         2  
  1         113  
14 1     1   7 use App::hopen::Phases qw(is_last_phase);
  1         3  
  1         48  
15 1     1   6 use Data::Hopen qw(:default getparameters *QUIET);
  1         3  
  1         188  
16 1     1   9 use Data::Hopen::Scope::Hash;
  1         2  
  1         39  
17 1     1   6 use Data::Hopen::Util::Data qw(forward_opts);
  1         2  
  1         45  
18 1     1   5 use File::Which;
  1         2  
  1         68  
19 1     1   6 use Path::Class;
  1         4  
  1         46  
20 1     1   24 use Quote::Code;
  1         3  
  1         11  
21              
22 1     1   600 use App::hopen::Gen::Ninja::AssetGraphNode; # for $OUTPUT
  1         3  
  1         492  
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     2 1 11 my ($self, %args) = getparameters('self', [qw(dag; data)], @_);
52 2     0   285 hlog { Finalizing => __PACKAGE__ , '- phase', $Phase };
  0         0  
53 2 100       24 return unless is_last_phase $Phase;
54              
55 1     0   7 hlog { __PACKAGE__, 'Asset graph', '' . $self->_assets->_graph } 3;
  0         0  
56              
57             # During the Gen phase, create the Ninja file
58 1 50       31 open my $fh, '>', $self->dest_dir->file('build.ninja')
59             or die "Couldn't create Ninja file";
60             print $fh qc_to <<"EOT";
61 1         13 # Ninja file generated by hopen (https://github.com/hopenbuild/App-hopen)
62 1         275 # at #{gmtime} GMT
  1         27  
  1         158  
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         207 my $context = Data::Hopen::Scope::Hash->new;
71 1         24 $context->put(App::hopen::Gen::Ninja::AssetGraphNode::OUTPUT, $fh);
72              
73             # Write the Ninja file. TODO? flip the order?
74              
75 1         65 $self->_assets->run(-context => $context);
76              
77 1         3379 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     2 1 9 sub default_toolset { 'Gnu' }
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     4   10 sub _assetop_class { 'App::hopen::Gen::Ninja::AssetGraphNode' }
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     0     my $path = File::Which::which('ninja');
109 0 0         if(defined $path) {
110 0     0     hlog { Running => $path };
  0            
111 0           system $path, ();
112             } else {
113 0           warn "Could not find the 'ninja' program";
114             }
115             } #_run_build()
116              
117             1;
118             __END__
119             # vi: set fdm=marker: #