1 | # ------------------------------------------------------------------------------ |
---|
2 | # (C) British Crown Copyright 2006-17 Met Office. |
---|
3 | # |
---|
4 | # This file is part of FCM, tools for managing and building source code. |
---|
5 | # |
---|
6 | # FCM is free software: you can redistribute it and/or modify |
---|
7 | # it under the terms of the GNU General Public License as published by |
---|
8 | # the Free Software Foundation, either version 3 of the License, or |
---|
9 | # (at your option) any later version. |
---|
10 | # |
---|
11 | # FCM is distributed in the hope that it will be useful, |
---|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | # GNU General Public License for more details. |
---|
15 | # |
---|
16 | # You should have received a copy of the GNU General Public License |
---|
17 | # along with FCM. If not, see <http://www.gnu.org/licenses/>. |
---|
18 | # ------------------------------------------------------------------------------ |
---|
19 | use strict; |
---|
20 | use warnings; |
---|
21 | # ------------------------------------------------------------------------------ |
---|
22 | package FCM::System::Make::Build::Task::Archive; |
---|
23 | use base qw{FCM::Class::CODE}; |
---|
24 | |
---|
25 | use FCM::Context::Event; |
---|
26 | use FCM::System::Exception; |
---|
27 | use File::Spec::Functions qw{abs2rel catfile}; |
---|
28 | use List::Util qw{first}; |
---|
29 | use Text::ParseWords qw{shellwords}; |
---|
30 | |
---|
31 | our %PROP_OF = (ar => 'ar', 'ar.flags' => 'rs'); |
---|
32 | my $E = 'FCM::System::Exception'; |
---|
33 | |
---|
34 | __PACKAGE__->class( |
---|
35 | {prop_of => {isa => '%', default => {%PROP_OF}}, util => '&'}, |
---|
36 | {action_of => {main => \&_main, prop_of => sub {\%PROP_OF}}}, |
---|
37 | ); |
---|
38 | |
---|
39 | sub _main { |
---|
40 | my ($attrib_ref, $target) = @_; |
---|
41 | # Selects the correct dependent objects |
---|
42 | my @paths = @{$target->get_info_of('paths')}; |
---|
43 | my %dep_keys_of = %{$target->get_info_of('deps')}; |
---|
44 | my @paths_of_o = (); |
---|
45 | my $abs2rel_func |
---|
46 | = sub {index($_[0], $paths[0]) == 0 ? abs2rel($_[0], $paths[0]) : $_[0]}; |
---|
47 | while (my ($type, $key_list_ref) = each(%dep_keys_of)) { |
---|
48 | for my $key (@{$key_list_ref}) { |
---|
49 | my $path = first {-e} map {catfile($_, 'o', $key)} @paths; |
---|
50 | if ($path) { |
---|
51 | push(@paths_of_o, $abs2rel_func->($path)); |
---|
52 | } |
---|
53 | } |
---|
54 | } |
---|
55 | my @command_list = ( |
---|
56 | (map {shellwords($target->get_prop_of($_))} qw{ar ar.flags}), |
---|
57 | $target->get_path(), |
---|
58 | @paths_of_o, |
---|
59 | ); |
---|
60 | my %value_of = %{$attrib_ref->{util}->shell_simple(\@command_list)}; |
---|
61 | if ($value_of{rc}) { |
---|
62 | return $E->throw( |
---|
63 | $E->SHELL, {command_list => \@command_list, %value_of}, $value_of{e}, |
---|
64 | ); |
---|
65 | } |
---|
66 | $attrib_ref->{util}->event( |
---|
67 | FCM::Context::Event->MAKE_BUILD_SHELL_OUT, @value_of{qw{o e}}, |
---|
68 | ); |
---|
69 | $target; |
---|
70 | } |
---|
71 | |
---|
72 | # ------------------------------------------------------------------------------ |
---|
73 | 1; |
---|
74 | __END__ |
---|
75 | |
---|
76 | =head1 NAME |
---|
77 | |
---|
78 | FCM::System::Make::Build::Task::Archive |
---|
79 | |
---|
80 | =head1 SYNOPSIS |
---|
81 | |
---|
82 | use FCM::System::Make::Build::Task::Archive; |
---|
83 | my $build_task = FCM::System::Make::Build::Task::Archive->new(\%attrib); |
---|
84 | $build_task->main($target); |
---|
85 | |
---|
86 | =head1 DESCRIPTION |
---|
87 | |
---|
88 | Invokes the archive to create the target archive library. |
---|
89 | |
---|
90 | =head1 METHODS |
---|
91 | |
---|
92 | =over 4 |
---|
93 | |
---|
94 | =item $class->new(\%attrib) |
---|
95 | |
---|
96 | Creates and returns a new instance. %attrib should contain: |
---|
97 | |
---|
98 | =over 4 |
---|
99 | |
---|
100 | =item {prop_of} |
---|
101 | |
---|
102 | A HASH that maps the property names (used by this task) to their default values. |
---|
103 | |
---|
104 | =item {util} |
---|
105 | |
---|
106 | An instance of L<FCM::Util|FCM::Util>. |
---|
107 | |
---|
108 | =back |
---|
109 | |
---|
110 | =item $instance->main($target) |
---|
111 | |
---|
112 | Invokes the "ar" command to create the $target object archive. It uses the |
---|
113 | $target->get_info_of('deps')->{o} ARRAY. All "o" dependency items are placed in |
---|
114 | the archive. |
---|
115 | |
---|
116 | =item $instance->prop_of() |
---|
117 | |
---|
118 | Returns the HASH that maps the property names (used by this task) to their |
---|
119 | default values. |
---|
120 | |
---|
121 | =back |
---|
122 | |
---|
123 | =head1 CONSTANTS |
---|
124 | |
---|
125 | =item %FCM::System::Make::Build::Task::Archive::PROP_OF |
---|
126 | |
---|
127 | A map containing the property names and their default values. |
---|
128 | |
---|
129 | =head1 COPYRIGHT |
---|
130 | |
---|
131 | (C) Crown copyright Met Office. All rights reserved. |
---|
132 | |
---|
133 | =cut |
---|