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.
NS.pm in vendors/FCM-2017.10.0/lib/FCM/System/Make/Build/FileType – NEMO

source: vendors/FCM-2017.10.0/lib/FCM/System/Make/Build/FileType/NS.pm @ 10672

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

Reimport latest FCM release

File size: 6.9 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#-------------------------------------------------------------------------------
22
23package FCM::System::Make::Build::FileType::NS;
24use base qw{FCM::Class::CODE};
25
26use FCM::Context::Make::Build;    # for FCM::Context::Make::Build::Target
27use FCM::System::Make::Build::Task::Archive;
28use FCM::System::Make::Build::Task::Install;
29use File::Spec::Functions qw{catfile};
30
31my $ID = '/';
32
33my %TARGET_FILE_EXT_OF = (a => '.a', etc => '.etc');
34
35my %TASK_CLASS_OF = (
36    'archive' => 'FCM::System::Make::Build::Task::Archive',
37    'install' => 'FCM::System::Make::Build::Task::Install',
38);
39
40# Creates the class.
41__PACKAGE__->class(
42    {   id                 => {isa => '$', default => $ID},
43        target_file_ext_of => {isa => '%', default => {%TARGET_FILE_EXT_OF}},
44        target_file_name_option_of => '%',
45        task_class_of      => {isa => '%', default => {%TASK_CLASS_OF}},
46        shared_util_of     => '%',
47        task_of            => '%',
48        util               => '&',
49    },
50    {   init => \&_init,
51        action_of => {
52            (map {my $key = $_; ($key => sub {$_[0]->{$key}})}
53                qw{id target_file_ext_of target_file_name_option_of task_of}
54            ),
55            ns_targets_deps => sub {('o')},
56            ns_targets      => \&_ns_targets,
57        },
58    },
59);
60
61# Initialises some attributes.
62sub _init {
63    my ($attrib_ref) = @_;
64    while (my ($key, $class) = each(%{$attrib_ref->{task_class_of}})) {
65        $attrib_ref->{util}->class_load($class);
66        $attrib_ref->{task_of}{$key}
67            = $class->new({util => $attrib_ref->{util}});
68    }
69}
70
71# Returns a list of targets for a given build source.
72sub _ns_targets {
73    my ($attrib_ref, $targets_ref, $prop_hash_ref) = @_;
74    my %target_of;
75    TARGET:
76    for my $target (@{$targets_ref}) {
77        my @ns_targets;
78        for (
79            [sub {!$_[0]->get_type()}          , \&_ns_target_new_etc],
80            [sub {$_[0]->get_category() eq 'o'}, \&_ns_target_new_lib],
81        ) {
82            my ($test, $new) = @{$_};
83            if ($test->($target)) {
84                my $ns_iter = $attrib_ref->{util}->ns_iter(
85                    $target->get_ns(), $attrib_ref->{util}->NS_ITER_UP,
86                );
87                $ns_iter->(); # discard
88                while (defined(my $ns = $ns_iter->())) {
89                    my $ns_target = $new->($ns, $prop_hash_ref);
90                    my $key = $ns_target->get_key();
91                    if (!exists($target_of{$key})) {
92                        $target_of{$key} = $ns_target;
93                    }
94                    push(
95                        @{$target_of{$key}->get_deps()},
96                        [$target->get_key(), $target->get_category()],
97                    );
98                }
99                next TARGET;
100            }
101        }
102    }
103    values(%target_of);
104}
105
106# Returns a new etc target for building data files in a namespace.
107sub _ns_target_new_etc {
108    my ($ns, $prop_hash_ref) = @_;
109    my $DOT_ETC = $prop_hash_ref->{etc};
110    my $TARGET = 'FCM::Context::Make::Build::Target';
111    $TARGET->new(
112        {   category      => $TARGET->CT_ETC,
113            dep_policy_of => {'etc' => $TARGET->POLICY_CAPTURE},
114            key           => ($ns ? catfile($ns, $DOT_ETC) : $DOT_ETC),
115            ns            => $ns,
116            task          => 'install',
117        }
118    );
119}
120
121# Returns a new archive target for building an object library for a namespace.
122sub _ns_target_new_lib {
123    my ($ns, $prop_hash_ref) = @_;
124    my $NAME = 'libo' . $prop_hash_ref->{a}; # FIXME: libo hard-coded
125    my $TARGET = 'FCM::Context::Make::Build::Target';
126    $TARGET->new(
127        {   category      => $TARGET->CT_LIB,
128            dep_policy_of => {'o' => $TARGET->POLICY_CAPTURE},
129            info_of       => {paths => [], deps => {o => []}},
130            key           => ($ns ? catfile($ns, $NAME) : $NAME),
131            ns            => $ns,
132            task          => 'archive',
133        }
134    );
135}
136
137#-------------------------------------------------------------------------------
1381;
139__END__
140
141=head1 NAME
142
143FCM::System::Make::Build::FileType::NS
144
145=head1 SYNOPSIS
146
147    use FCM::System::Make::Build::FileType::NS;
148    my $file_type_util = FCM::System::Make::Build::FileType->new(\%attrib);
149    $file_type_util->ns_targets($m_ctx, $ctx, @targets);
150
151=head1 DESCRIPTION
152
153Generates name space level targets.
154
155=head1 METHODS
156
157=over 4
158
159=item $class->new(\%attrib)
160
161Creates and returns a new instance.
162
163=item $instance->id()
164
165Returns the recommended ID of this file type.
166
167=item $instance->ns_targets(\@targets,\%prop_of)
168
169Using the information in the original list of targets, creates and returns the
170contexts of a list of extra targets based on the name spaces of the original
171list. In the current settings, a target with no type (i.e. a data file target)
172will generate a C<.etc> target for the container name spaces; a target in the
173C<o> category will generate a C<libo.a> target for the container name spaces.
174
175=item $instance->ns_targets_deps()
176
177Returns a list of dependency types used by
178$instance->ns_targets(\@targets,\%prop_of).
179
180=item $instance->target_file_ext_of()
181
182Returns a HASH reference containing a map between the named types of file
183extensions used by the $instance->ns_targets(\@targets,\%prop_of) method
184and their default values.
185
186=item $instance->target_file_name_option_of()
187
188Returns a HASH reference containing a map between the named types of files
189used by the $instance->source_to_targets($source,\%prop_of) method
190and their default settings for other file naming options.
191
192=item $instance->task_of()
193
194Returns a HASH reference containing a map between the named tasks for this file
195type and their implementation objects. Each task should have a
196$task->main($target) method to update a target and optionally a $task->prop_of()
197method to return a HASH reference containing a map between the named properties
198used by the task and their default values.
199
200=back
201
202=head1 TODO
203
204The configuration in this module is a bit hard coded. It can do with a refactor.
205
206=head1 COPYRIGHT
207
208(C) Crown copyright Met Office. All rights reserved.
209
210=cut
Note: See TracBrowser for help on using the repository browser.