File Coverage

blib/lib/App/hopen/T/Gnu/C/LinkCmd.pm
Criterion Covered Total %
statement 41 42 97.6
branch 2 4 50.0
condition n/a
subroutine 11 12 91.6
pod n/a
total 54 58 93.1


line stmt bran cond sub pod time code
1             # App::hopen::T::Gnu::C::LinkCmd - link object files using the GNU toolset
2             package App::hopen::T::Gnu::C::LinkCmd;
3 1     1   8 use Data::Hopen;
  1         3  
  1         58  
4 1     1   6 use strict;
  1         2  
  1         22  
5 1     1   5 use Data::Hopen::Base;
  1         2  
  1         7  
6              
7             our $VERSION = '0.000011';
8              
9 1     1   1389 use parent 'App::hopen::G::Cmd';
  1         5  
  1         7  
10 1     1   75 use Class::Tiny qw(dest linker);
  1         3  
  1         7  
11              
12 1     1   344 use App::hopen::BuildSystemGlobals; # For $DestDir.
  1         6  
  1         122  
13             # TODO make the dirs available to nodes through the context.
14 1     1   8 use App::hopen::Util::BasedPath;
  1         2  
  1         47  
15             #use Config;
16 1     1   6 use Data::Hopen qw(getparameters);
  1         2  
  1         37  
17             #use Data::Hopen::G::GraphBuilder;
18 1     1   7 use Data::Hopen::Util::Filename;
  1         2  
  1         41  
19             #use Deep::Hash::Utils qw(deepvalue);
20             #use File::Which ();
21 1     1   8 use Path::Class;
  1         1  
  1         319  
22              
23             #my $FN = Data::Hopen::Util::Filename->new; # for brevity
24             #our $_CC; # Cached compiler name
25              
26             # Docs {{{1
27              
28             =head1 NAME
29              
30             App::hopen::T::Gnu::C::LinkCmd - link object files using the GNU toolset
31              
32             =head1 SYNOPSIS
33              
34             In a hopen file:
35              
36             my $cmd = App::hopen::T::Gnu::C::LinkCmd->new(
37             linker => 'gcc',
38             dest => 'foo.exe',
39             name => 'some linker node', # optional
40             );
41              
42             The inputs come from earlier in the build graph.
43             TODO support specifying linker arguments.
44              
45             =head1 ATTRIBUTES
46              
47             =head2 linker
48              
49             The linker to use. TODO is this a full path or just a name?
50              
51             =head2 dest
52              
53             The destination file to produce, as an L<App::hopen::Util::BasedPath> instance.
54             TODO? accept string or L<Path::Class::File> instance?
55              
56             =head1 MEMBER FUNCTIONS
57              
58             =cut
59              
60             # }}}1
61              
62             =head2 _run
63              
64             Create the link command line.
65              
66             =cut
67              
68             sub _run {
69 2     2   723 my ($self, %args) = getparameters('self', [qw(phase visitor ; *)], @_);
70              
71             # Currently we only do things at gen time.
72 2 50       174 return $self->passthrough(-nocontext=>1) if $args{phase} ne 'Gen';
73              
74             # Pull the inputs
75 2         12 my $lrObjFiles = $self->input_assets;
76 2     0   31 hlog { 'found object files', Dumper($lrObjFiles) } 2;
  0         0  
77              
78 2         61 my $exe = App::hopen::Asset->new(
79             target => $self->dest,
80             made_by => $self,
81             );
82 2         68 $args{visitor}->asset($exe,
83             -how => $self->linker . ' -o #out #all',
84             );
85              
86 2         12 foreach my $obj (@$lrObjFiles) {
87 2 50       10 die "Cannot link non-file $obj" unless $obj->isdisk;
88 2         15 $args{visitor}->connect($obj, $exe);
89             }
90              
91 2         3412 $self->make($exe);
92 2         8 return {};
93             } #_run()
94              
95             1;
96             __END__
97             # vi: set fdm=marker: #