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.
Build.pm in vendors/lib/FCM/Context/Make – NEMO

source: vendors/lib/FCM/Context/Make/Build.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: 12.4 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::Context::Make::Build;
24use base qw{FCM::Class::HASH};
25
26use FCM::Context::Make;
27
28use constant {
29    CTX_SOURCE  => 'FCM::Context::Make::Build::Source',
30    CTX_TARGET  => 'FCM::Context::Make::Build::Target',
31    ID_OF_CLASS => 'build',
32};
33
34my $ST_UNKNOWN = FCM::Context::Make->ST_UNKNOWN;
35
36__PACKAGE__->class(
37    {   dest             => '$',
38        dests            => '@',
39        id               => {isa => '$' , default => ID_OF_CLASS},
40        id_of_class      => {isa => '$' , default => ID_OF_CLASS},
41        input_ns_excl    => '@',
42        input_ns_incl    => '@',
43        input_source_of  => '%',
44        prop_of          => '%',
45        source_of        => '%',
46        status           => {isa => '$' , default => $ST_UNKNOWN},
47        target_of        => '%',
48        target_key_of    => '%',
49        target_select_by => '%',
50    },
51);
52
53# ------------------------------------------------------------------------------
54package FCM::Context::Make::Build::Source;
55use base qw{FCM::Class::HASH};
56
57__PACKAGE__->class({
58    checksum   => '$',
59    deps       => '@',
60    info_of    => '%',
61    ns         => '$',
62    path       => '$',
63    prop_of    => '%',
64    type       => '$',
65    up_to_date => '$',
66});
67
68# ------------------------------------------------------------------------------
69package FCM::Context::Make::Build::Target;
70use base qw{FCM::Class::HASH};
71
72use constant {
73    CT_BIN                  => 'bin',
74    CT_ETC                  => 'etc',
75    CT_INCLUDE              => 'include',
76    CT_LIB                  => 'lib',
77    CT_O                    => 'o',
78    CT_SRC                  => 'src',
79    POLICY_CAPTURE          => 'POLICY_CAPTURE',
80    POLICY_FILTER           => 'POLICY_FILTER',
81    POLICY_FILTER_IMMEDIATE => 'POLICY_FILTER_IMMEDIATE',
82    ST_FAILED               => 'ST_FAILED',
83    ST_MODIFIED             => 'ST_MODIFIED',
84    ST_OOD                  => 'ST_OOD',
85    ST_UNCHANGED            => 'ST_UNCHANGED',
86    ST_UNKNOWN              => 'ST_UNKNOWN',
87};
88
89__PACKAGE__->class(
90    {   category        => '$',
91        checksum        => '$',
92        deps            => '@',
93        dep_policy_of   => '%',
94        failed_by       => '@',
95        info_of         => '%',
96        key             => '$',
97        ns              => '$',
98        path            => '$',
99        path_of_prev    => '$',
100        path_of_source  => '$',
101        prop_of         => '%',
102        prop_of_prev_of => '%',
103        status          => {isa => '$', default => ST_UNKNOWN},
104        status_of       => '%',
105        task            => '$',
106        triggers        => '@',
107        type            => '$',
108    },
109);
110
111# Returns true if target has a usable dest status.
112sub can_be_source {
113    $_[0]->get_category() && $_[0]->get_category() eq CT_SRC;
114}
115
116# Returns true if target has an OK status.
117sub is_ok {
118    $_[0]->get_status() eq ST_MODIFIED || $_[0]->get_status() eq ST_UNCHANGED;
119}
120
121# Returns true if target has a failed status.
122sub is_failed {
123    $_[0]->get_status() eq ST_FAILED;
124}
125
126# Shorthand for $target->get_status() eq $target->ST_MODIFIED.
127sub is_modified {
128    $_[0]->get_status() eq ST_MODIFIED;
129}
130
131# Shorthand for $target->get_status() eq $target->ST_UNCHANGED.
132sub is_unchanged {
133    $_[0]->get_status() eq ST_UNCHANGED;
134}
135
136# ------------------------------------------------------------------------------
1371;
138__END__
139
140=head1 NAME
141
142FCM::Context::Make::Build
143
144=head1 SYNOPSIS
145
146    use FCM::Context::Make::Build;
147    my $ctx = FCM::Context::Make::Build->new();
148
149=head1 DESCRIPTION
150
151Provides a context object for the FCM build system. All the classes described
152below are sub-classes of L<FCM::Class::HASH|FCM::Class::HASH>.
153
154=head1 OBJECTS
155
156=head2 FCM::Context::Make::Build
157
158An instance of this class represents a build. It has the following
159attributes:
160
161=over 4
162
163=item dest
164
165The destination of the build.
166
167=item dests
168
169An ARRAY containing the path for searching items in the current build.
170
171=item id
172
173The ID of the context. (default="build")
174
175=item id_of_class
176
177The class ID of the context. (default="build")
178
179=item input_source_of
180
181A HASH to map a name space to its ARRAY of input sources.
182
183=item input_ns_excl
184
185An ARRAY of source name-spaces to exclude.
186
187=item input_ns_incl
188
189An ARRAY of source name-spaces to include.
190
191=item prop_of
192
193A HASH containing the named properties (i.e. options and settings of named
194external tools). Expects a value to be an instance of
195L<FCM::Context::Make::Share::Property|FCM::Context::Make::Share::Property>.
196
197=item prop_of_prev_of
198
199A HASH containing the named properties (i.e. options and settings of named
200external tools) in the latest successful update of this target. Expects a value
201to be an instance of
202L<FCM::Context::Make::Share::Property|FCM::Context::Make::Share::Property>.
203
204=item source_of
205
206A HASH to map the namespace to the source contexts. Each element is expected to
207be an L</FCM::Context::Make::Build::Source> object.
208
209=item status
210
211The status of this context. See L<FCM::Context::Make|FCM::Context::Make> for the
212status constants.
213
214=item target_of
215
216A HASH to map the namespace to the target contexts. Each element is expected to
217be an L</FCM::Context::Make::Build::Target> object.
218
219=item target_key_of
220
221A HASH to map the automatic key of targets to their desired key.
222
223=item target_select_by
224
225A HASH to allow users to specify how to select from all the targets. The key can
226be "category", "key", "ns" or "task". Each value should be a HASH that
227represents the set of criteria.
228
229=back
230
231=head2 FCM::Context::Make::Build::Source
232
233An instance of this class represents an actual source of the build. It has the
234following attributes:
235
236=over 4
237
238=item checksum
239
240The checksum of the source file.
241
242=item deps
243
244An ARRAY to contain the dependencies of the source file. Each element of the
245ARRAY is expected to be a reference to a two-element ARRAY [$name, $type] where
246$name is the name of the dependency and $type is its type.
247
248=item info_of
249
250A HASH to contain the extra information of the source file. E.g. If the {main}
251element is true, the source contains a main program. If the {symbols} element
252is defined, it contains a reference to an ARRAY of program unit symbols that has
253been found in the source file.
254
255=item ns
256
257The name-space of the source file.
258
259=item path
260
261The path in the file system pointing to the source file.
262
263=item prop_of
264
265A HASH containing the keys and the values of the build properties (mainly on
266dependency settings) of the source.
267
268=item type
269
270The file type of the source file.
271
272=item up_to_date
273
274A flag to indicate whether the source file is up to date, compared with a
275previous build or the nearest inherited build.
276
277=back
278
279=head2 FCM::Context::Make::Build::Target
280
281An instance of this class represents a target of the build. It has the following
282attributes:
283
284=over 4
285
286=item category
287
288The target category, e.g. bin, etc, include, lib, o, src
289
290=item checksum
291
292The checksum of the target.
293
294=item deps
295
296An ARRAY containing the dependencies of the target. Each element of the
297ARRAY is expected to be a reference to a two-element ARRAY [$name, $type] where
298$name is the name of the dependency and $type is its type.
299
300=item dep_policy_of
301
302A HASH to contain a map between each relevant dependency type of this target and
303its policy to apply to the dependency type. The policy should take the value of
304POLICY_CAPTURE, POLICY_FILTER or POLICY_FILTER_IMMEDIATE.
305
306=item failed_by
307
308On failure, set to an ARRAY containing the names of the targets that cause the
309failure of this target.
310
311=item info_of
312
313A HASH to contain the extra information of the target. E.g. The {paths} => ARRAY
314reference of include/object search paths for the compile, link and preprocess
315tasks; and {deps}{o} => ARRAY reference and {deps}{o.special} => ARRAY
316reference of object dependency for the link tasks.
317
318=item key
319
320The key (i.e. the base name) of the target.
321
322=item ns
323
324The name-space (of the source file) associated with this target.
325
326=item path
327
328The path in the file system where the target can be located.
329
330=item path_of_prev
331
332The path in the file system where the target in a previous or inherited build
333can be located.
334
335=item path_of_source
336
337The path in the file system where the source file associated with the target can
338be located.
339
340=item prop_of
341
342A HASH containing the keys and the values of the build properties of the target.
343
344=item status
345
346The status of the target.
347
348=item status_of
349
350A HASH containing the status of dependency types that may be relevant to targets
351higher up in the dependency tree.
352
353=item task
354
355The target type, (i.e. the name of the task to update with the target).
356
357=item triggers
358
359An ARRAY reference of the keys of targets that should be automatically triggered
360by this target.
361
362=item type
363
364The type of the source that gives this target.
365
366=back
367
368In addition, an instance of FCM::Context::Make::Extract::Target has the
369following methods:
370
371=over 4
372
373=item $target->can_be_source()
374
375Returns true if the destination status indicates that the target is usable as a
376source file of a subsequent a make (step).
377
378=item $target->is_ok()
379
380Returns true if the target has a OK destination status.
381
382=item $target->is_failed()
383
384Returns true if the target has a failed destination status.
385
386=item $target->is_modified()
387
388Shorthand for $target->get_status() eq $target->ST_MODIFIED.
389
390=item $target->is_unchanged()
391
392Shorthand for $target->get_status() eq $target->ST_UNCHANGED.
393
394=back
395
396=head1 CONSTANTS
397
398The following is a list of constants:
399
400=over 4
401
402=item FCM::Context::Make::Build->CTX_INPUT
403
404Alias of FCM::Context::Make::Build::Input.
405
406=item FCM::Context::Make::Build->CTX_SOURCE
407
408Alias of FCM::Context::Make::Build::Source.
409
410=item FCM::Context::Make::Build->ID_OF_CLASS
411
412The default value of the "id" attribute (of an instance), and the ID of the
413functional class. ("build")
414
415=item FCM::Context::Make::Build::Target->CT_BIN
416
417Target category, "bin", executable.
418
419=item FCM::Context::Make::Build::Target->CT_ETC
420
421Target category, "etc", data and misc file.
422
423=item FCM::Context::Make::Build::Target->CT_INCLUDE
424
425Target category, "include", include file.
426
427=item FCM::Context::Make::Build::Target->CT_LIB
428
429Target category, "lib", program library.
430
431=item FCM::Context::Make::Build::Target->CT_O
432
433Target category, "o", compiled object file.
434
435=item FCM::Context::Make::Build::Target->CT_SRC
436
437Target category, "src", generated source file.
438
439=item FCM::Context::Make::Build::Target->POLICY_CAPTURE
440
441Indicates that the dependency type is relevant to the target, and the build
442engine should stop floating the dependency target up the dependency tree.
443
444=item FCM::Context::Make::Build::Target->POLICY_FILTER
445
446Indicates that the dependency type is relevant to the target, and the build
447engine may float the dependency target up the dependency tree as well.
448
449=item FCM::Context::Make::Build::Target->POLICY_FILTER_IMMEDIATE
450
451Indicates that the dependency type is relevant to the target but only if the
452dependency target is an immediate dependency of this target, and the build
453engine may float the dependency target up the dependency tree as well.
454
455=item FCM::Context::Make::Build::Target->ST_FAILED
456
457Indicates that the build has failed to update the target.
458
459=item FCM::Context::Make::Build::Target->ST_MODIFIED
460
461Indicates that the target is out of date and has been modified by the build.
462
463=item FCM::Context::Make::Build::Target->ST_OOD
464
465Indicates that the target is out of date.
466
467=item FCM::Context::Make::Build::Target->ST_UNCHANGED
468
469Indicates that the target is up to date and unchanged by the build.
470
471=item FCM::Context::Make::Build::Target->ST_UNKNOWN
472
473Indicates an unknown target status.
474
475=back
476
477=head1 COPYRIGHT
478
479(C) Crown copyright Met Office. All rights reserved.
480
481=cut
Note: See TracBrowser for help on using the repository browser.