File Coverage

blib/lib/App/hopen/T/Gnu/C/LinkCmd.pm
Criterion Covered Total %
statement 44 45 97.7
branch 2 4 50.0
condition n/a
subroutine 12 13 92.3
pod n/a
total 58 62 93.5


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