| 1 | # App::hopen::Gen::Ninja::AssetGraphNode - AssetOp for Gen::Ninja | ||||||||||||
| 2 | package App::hopen::Gen::Ninja::AssetGraphNode; | ||||||||||||
| 3 | 1 | ▶ | use Data::Hopen qw(getparameters *VERBOSE); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use strict; use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 1 | ▶ | use Data::Hopen::Base; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 1 | our $VERSION = '0.000013'; # TRIAL | |||||||||||
| 8 | |||||||||||||
| 9 | 1 | ▶ | use parent 'App::hopen::G::AssetOp'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | use Class::Tiny { | ||||||||||||
| 11 | 0 | ▶ | _rules => sub { +{} }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 12 | 1 | ▶ | }; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | 1 | ▶ | use App::hopen::BuildSystemGlobals; # for $DestDir | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 1 | ▶ | use Quote::Code; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 1 | ▶ | use String::Print; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | |||||||||||||
| 18 | # Docs {{{1 | ||||||||||||
| 19 | |||||||||||||
| 20 | =head1 NAME | ||||||||||||
| 21 | |||||||||||||
| 22 | App::hopen::Gen::Ninja::AssetGraphNode - AssetOp for Gen::Ninja | ||||||||||||
| 23 | |||||||||||||
| 24 | =head1 SYNOPSIS | ||||||||||||
| 25 | |||||||||||||
| 26 | TODO | ||||||||||||
| 27 | |||||||||||||
| 28 | =head1 ATTRIBUTES | ||||||||||||
| 29 | |||||||||||||
| 30 | =head2 _rules | ||||||||||||
| 31 | |||||||||||||
| 32 | TODO? Store mapping from command lines to rules? Don't want to generate | ||||||||||||
| 33 | a separate rule for every command if we can help it. | ||||||||||||
| 34 | |||||||||||||
| 35 | =head1 FUNCTIONS | ||||||||||||
| 36 | |||||||||||||
| 37 | =cut | ||||||||||||
| 38 | |||||||||||||
| 39 | # }}}1 | ||||||||||||
| 40 | |||||||||||||
| 41 | 1 | ▶ | use vars::i '&OUTPUT' => sub { '__R_Ninjafile' }; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 42 | |||||||||||||
| 43 | =head2 _run | ||||||||||||
| 44 | |||||||||||||
| 45 | Generate a piece of a C<build.ninja> file and write it to the filehandle in | ||||||||||||
| 46 | C<__R_Ninjafile>. | ||||||||||||
| 47 | |||||||||||||
| 48 | If the `how` of a node is defined but falsy, it's a goal. | ||||||||||||
| 49 | If `how` is defined and truthy, it's a file. | ||||||||||||
| 50 | |||||||||||||
| 51 | =cut | ||||||||||||
| 52 | |||||||||||||
| 53 | sub _run { | ||||||||||||
| 54 | 4 | ▶ | state $ruleidx=0; | ||||||||||
|
Subroutine
_run: called CC=8 SCAR=21.3
| |||||||||||||
| 55 | |||||||||||||
| 56 | 4 | my ($self, %args) = getparameters('self', [qw(; phase visitor)], @_); | |||||||||||
| 57 | 4 | my $fh = $self->scope->find(OUTPUT); | |||||||||||
| 58 | # TODO deal with multiple inputs being merged in DAG::_run() | ||||||||||||
| 59 | |||||||||||||
| 60 | 4 | my @inputs = $self->input_assets; | |||||||||||
| 61 | 4 | my $output = $self->asset->target; | |||||||||||
| 62 | 4 | ▶ | $output = $output->path_wrt($DestDir) if eval { $output->DOES('App::hopen::Util::BasedPath') }; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 63 | # TODO refactor this processing into a utility module/function | ||||||||||||
| 64 | |||||||||||||
| 65 | # Debugging output | ||||||||||||
| 66 | 4 | ▶ | if($VERBOSE) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 67 | 0 | print $fh qc'\n# From node {$self->name}:\n'; | |||||||||||
| 68 | 0 | ▶ | print $fh qc' # {$self->how//"<nothing to be done>"}\n'; | ||||||||||
|
Condition0%0/2
$self->how // "<nothing to be done>"
MC/DC0%0/1
$self->how // "<nothing to be done>"
$self->how
Truth table0%0/2
A
A= $self->how
| |||||||||||||
| 69 | 0 | print $fh qc' # Depends on {$_->target}\n' foreach @inputs; | |||||||||||
| 70 | } | ||||||||||||
| 71 | |||||||||||||
| 72 | 4 | ▶ | if(defined $self->how) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 73 | 3 | my @paths = map { $_->target->path_wrt($DestDir) } @inputs; | |||||||||||
| 74 | 3 | my $recipe = $self->how; | |||||||||||
| 75 | # TODO refactor this processing into a utility module/function | ||||||||||||
| 76 | 3 | ▶ | warn "I don't yet support #first very well (in ``$recipe'')" if $recipe =~ /#first/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 77 | 3 | $recipe =~ s<#first\b><\$in>g; # first input # TODO FIXME | |||||||||||
| 78 | 3 | $recipe =~ s<#all\b><\$in>g; # all inputs | |||||||||||
| 79 | 3 | $recipe =~ s<#out\b><\$out>g; | |||||||||||
| 80 | |||||||||||||
| 81 | # Emit the entry. If the recipe is defined but falsy, | ||||||||||||
| 82 | # this is a goal, so it gets a `phony` and a `default`. | ||||||||||||
| 83 | |||||||||||||
| 84 | # TODO FIXME ugly hack: for now, each command gets its own rule. | ||||||||||||
| 85 | |||||||||||||
| 86 | 3 | ▶ | if($self->how) { # File target | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 87 | |||||||||||||
| 88 | 2 | my $rulename = 'rule_' . ++$ruleidx; | |||||||||||
| 89 | 2 | print $fh qc_to <<"EOT" | |||||||||||
| 90 | 2 | rule #{$rulename} | |||||||||||
| 91 | command = #{$recipe} | ||||||||||||
| 92 | 2 | ||||||||||||
| 93 | build #{$output}: #{$rulename} #{join(" ", @paths)} | ||||||||||||
| 94 | |||||||||||||
| 95 | EOT | ||||||||||||
| 96 | } else { # Goal target | ||||||||||||
| 97 | |||||||||||||
| 98 | 1 | print $fh qc_to <<"EOT" | |||||||||||
| 99 | 1 | build #{$output}: phony #{join(" ", @paths)} | |||||||||||
| 100 | default #{$output} | ||||||||||||
| 101 | |||||||||||||
| 102 | EOT | ||||||||||||
| 103 | } | ||||||||||||
| 104 | |||||||||||||
| 105 | } #endif defined $self->how | ||||||||||||
| 106 | |||||||||||||
| 107 | 4 | $self->make($self->asset); | |||||||||||
| 108 | 4 | return {}; | |||||||||||
| 109 | } #_run() | ||||||||||||
| 110 | |||||||||||||
| 111 | 1 | 1; | |||||||||||
| 112 | __END__ | ||||||||||||
| 113 | # vi: set fdm=marker: # | ||||||||||||