New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Archive.pm in vendors/lib/FCM/System/Make/Build/Task – NEMO

source: vendors/lib/FCM/System/Make/Build/Task/Archive.pm @ 10669

Last change on this file since 10669 was 10669, checked in by nicolasmartin, 5 years ago

Import latest FCM release from Github into the repository for testing

File size: 3.7 KB
Line 
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# ------------------------------------------------------------------------------
19use strict;
20use warnings;
21# ------------------------------------------------------------------------------
22package FCM::System::Make::Build::Task::Archive;
23use base qw{FCM::Class::CODE};
24
25use FCM::Context::Event;
26use FCM::System::Exception;
27use File::Spec::Functions qw{abs2rel catfile};
28use List::Util qw{first};
29use Text::ParseWords qw{shellwords};
30
31our %PROP_OF = (ar => 'ar', 'ar.flags' => 'rs');
32my $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
39sub _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# ------------------------------------------------------------------------------
731;
74__END__
75
76=head1 NAME
77
78FCM::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
88Invokes the archive to create the target archive library.
89
90=head1 METHODS
91
92=over 4
93
94=item $class->new(\%attrib)
95
96Creates and returns a new instance. %attrib should contain:
97
98=over 4
99
100=item {prop_of}
101
102A HASH that maps the property names (used by this task) to their default values.
103
104=item {util}
105
106An instance of L<FCM::Util|FCM::Util>.
107
108=back
109
110=item $instance->main($target)
111
112Invokes 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
114the archive.
115
116=item $instance->prop_of()
117
118Returns the HASH that maps the property names (used by this task) to their
119default values.
120
121=back
122
123=head1 CONSTANTS
124
125=item %FCM::System::Make::Build::Task::Archive::PROP_OF
126
127A 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
Note: See TracBrowser for help on using the repository browser.