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

filter: Statementstmt 85.5% 65 / 76 Branchbran 50.0% 4 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 81.8% 18 / 22 Podpod 100% 2 / 2 totaltotal 79.6% 90 / 113 CC 7 SCAR 11.0
CC
7
Cov
80%
_run_build
12.0
finalize
5.4
__ANON__
2.0
CRAP 3.0
« blib/lib/App/hopen/G/Cmd.pm ↑ Summary blib/lib/App/hopen/Gen/Make.pm »
1 # App::hopen::Gen::MSBuild - generator for msbuild
2 package App::hopen::Gen::MSBuild;
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 1 ▶use Syntax::Construct qw(/r);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '0.000013'; # TRIAL
8  
9 1 ▶use parent 'App::hopen::Gen';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Class::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use App::hopen::BuildSystemGlobals;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use App::hopen::Phases qw(is_last_phase);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use App::hopen::Util::XML::FromPerl qw(xml_from_perl);
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 Quote::Code;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use App::hopen::Gen::MSBuild::AssetGraphNode; # for $OUTPUT
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 # Docs {{{1
24  
25 =head1 NAME
26  
27 App::hopen::Gen::MSBuild - hopen generator for MSBuild
28  
29 =head1 SYNOPSIS
30  
31 This generator makes a C<.proj> file that can be run with MSBuild.
32  
33 =head1 FUNCTIONS
34  
35 =cut
36  
37 # }}}1
38  
39 =head2 finalize
40  
41 Write out the project file (for now, always called C<build.proj>). Usage:
42  
43 $Generator->finalize($dag); # $data parameter unused
44  
45 C<$dag> is the build graph.
46  
47 =cut
48  
49 sub finalize {
50 2 ▶ my ($self, %args) = getparameters('self', [qw(dag; data)], @_);
Subroutine finalize: called CC=5 SCAR=16.8
Pod documented
51 2 ▶ hlog { Finalizing => __PACKAGE__ , '- phase', $Phase };
Subroutine __ANON__: not called CC=1 SCAR=1.2
52 2 ▶ return unless is_last_phase $Phase; # Only do work during Gen
Branch: 1 branch
BranchTrueFalseTotal
unless is_last_phase($App::hopen::Gen::MSBuild::Phase) 1 1 2
53  
54 1 ▶ hlog { __PACKAGE__, 'Asset graph', '' . $self->_assets->_graph } 3;
Subroutine __ANON__: not called CC=1 SCAR=1.2
55  
56 1 my $context = Data::Hopen::Scope::Hash->new;
57 1 $context->put($App::hopen::Gen::MSBuild::AssetGraphNode::OUTPUT, undef);
58 # undef => will be ignored when making the XML
59  
60 # Generate the XML
61 1 my $hrOut = $self->_assets->run(-context => $context);
62  
63 my $lrXML = $hrOut->{$self->asset_default_goal->name}
64 1 ->{$App::hopen::Gen::MSBuild::AssetGraphNode::OUTPUT};
65 1 ▶ die "Empty XML!" unless defined $lrXML && @$lrXML;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lrXML and @$lrXML 0 1 1
Condition33%1/3
defined $lrXML and @$lrXML
!ll&&!rl&&r
001
MC/DC0%0/2
defined $lrXML and @$lrXML
defined $lrXML @$lrXML
Truth table33%1/3
A and B
A= defined $lrXMLB= @$lrXML
ABresult
0X0
100
111
66  
67 # Make the header. NOTE: no '--' allowed within a comment, so s///gr.
68 my $comment = qc_to <<"EOT";
69 MSBuild project file generated by hopen
70 1 (https://github.com/hopenbuild/App-hopen)
71 1 at #{gmtime =~ s/--/-/gr} GMT
72 1 From ``#{$self->proj_dir->absolute =~ s/--/-/gr}''
73 into ``#{$self->dest_dir->absolute =~ s/--/-/gr}''
74 EOT
75  
76 # Create the MSBuild file
77 1 my $doc = xml_from_perl(
78 ['Project',
79 { xmlns => 'http://schemas.microsoft.com/developer/msbuild/2003',
80 id => '__R_ROOT',
81 },
82 [ '!--', $comment ],
83 $lrXML # TODO @$lrXML?
84 ]);
85 1 $doc->setEncoding('utf-8');
86  
87 # Write the file
88 1 ▶ if($doc->toFile( $self->dest_dir->file('build.proj') ) == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($doc->toFile($self->dest_dir->file("build.proj")) == -1) 0 1 1
89 0 die "Couldn't create build.proj";
90 }
91  
92 } #finalize()
93  
94 =head2 default_toolset
95  
96 Returns the package name of the default toolset for this generator,
97 which is C<Gnu> (i.e., L<App::hopen::T::Gnu>).
98  
99 =cut
100  
101 2 ▶sub default_toolset { 'Gnu' } # TODO
Subroutine default_toolset: called CC=1 SCAR=0.0
Pod documented
102  
103 =head2 _assetop_class
104  
105 The class of asset-graph operations, which in this case is
106 L<App::hopen::Gen::MSBuild::AssetGraphNode>.
107  
108 =cut
109  
110 4 ▶sub _assetop_class { 'App::hopen::Gen::MSBuild::AssetGraphNode' }
Subroutine _assetop_class: called CC=1 SCAR=0.0
111  
112 =head2 _run_build
113  
114 Implementation of L<App::hopen::Gen/run_build>.
115  
116 =cut
117  
118 sub _run_build {
119 # Look for the make(1) executable. Listing make before gmake since a
120 # system with both Cygwin and Strawberry Perl installed has cygwin's
121 # make(1) and Strawberry's gmake(1).
122 0 ▶ foreach my $candidate (qw[make gmake mingw32-make dmake]) {
Subroutine _run_build: not called CC=3 SCAR=24.8
123 0 my $path = File::Which::which($candidate);
124 0 ▶ next unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 0 0
125 0 ▶ hlog { Running => $path };
Subroutine __ANON__: not called CC=1 SCAR=6.9
126 0 system $path, ();
127 0 return;
128 }
129 0 warn "Could not find a 'make' program to run";
130 } #_run_build()
131  
132 1 1;
133 __END__
134 # vi: set fdm=marker: #
« blib/lib/App/hopen/G/Cmd.pm ↑ Summary blib/lib/App/hopen/Gen/Make.pm »