source: LMDZ6/branches/Amaury_dev/tools/fcm/lib/FCM/Context/Make/Extract.pm

Last change on this file was 5129, checked in by abarral, 4 months ago

Re-add removed by mistake fcm

File size: 12.1 KB
Line 
1# ------------------------------------------------------------------------------
2# Copyright (C) 2006-2021 British Crown (Met Office) & Contributors.
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::Extract;
24use base qw{FCM::Class::HASH};
25
26use FCM::Context::Make;
27
28use constant {
29    CTX_PROJECT => 'FCM::Context::Make::Extract::Project',
30    CTX_SOURCE  => 'FCM::Context::Make::Extract::Source',
31    CTX_TARGET  => 'FCM::Context::Make::Extract::Target',
32    CTX_TREE    => 'FCM::Context::Make::Extract::Tree',
33    ID_OF_CLASS => 'extract',
34    MIRROR      => 1,
35};
36
37__PACKAGE__->class({
38    dest         => '$',
39    id           => {isa => '$', default => ID_OF_CLASS},
40    id_of_class  => {isa => '$', default => ID_OF_CLASS},
41    ns_list      => '@',
42    project_of   => '%',
43    status       => {isa => '$', default => FCM::Context::Make->ST_UNKNOWN},
44    target_of    => '%',
45    prop_of      => '%',
46});
47
48# ------------------------------------------------------------------------------
49package FCM::Context::Make::Extract::Project;
50use base qw{FCM::Class::HASH};
51
52__PACKAGE__->class({
53    cache     => '$',
54    inherited => '$',
55    locator   => 'FCM::Context::Locator',
56    ns        => '$',
57    path_excl => '@',
58    path_incl => '@',
59    path_root => {isa => '$', default => q{}},
60    trees     => '@',
61});
62
63# ------------------------------------------------------------------------------
64package FCM::Context::Make::Extract::Tree;
65use base qw{FCM::Class::HASH};
66
67__PACKAGE__->class({
68    cache     => '$',
69    inherited => '$',
70    key       => '$',
71    locator   => 'FCM::Context::Locator',
72    ns        => '$',
73    sources   => '@',
74});
75
76# ------------------------------------------------------------------------------
77package FCM::Context::Make::Extract::Source;
78use base qw{FCM::Class::HASH};
79
80use constant {
81    ST_NORMAL    => 'ST_NORMAL',
82    ST_UNCHANGED => 'ST_UNCHANGED',
83    ST_MISSING   => 'ST_MISSING',
84};
85
86__PACKAGE__->class({
87    cache       => '$',
88    key_of_tree => '$',
89    locator     => 'FCM::Context::Locator',
90    ns          => '$',
91    ns_in_tree  => '$',
92    status      => {isa => '$', default => ST_NORMAL},
93});
94
95# Shorthand for $source->get_status() eq $source->ST_MISSING.
96sub is_missing {
97    $_[0]->get_status() eq ST_MISSING;
98}
99
100# Shorthand for $source->get_status() eq $source->ST_UNCHANGED.
101sub is_unchanged {
102    $_[0]->get_status() eq ST_UNCHANGED;
103}
104
105# ------------------------------------------------------------------------------
106package FCM::Context::Make::Extract::Target;
107use base qw{FCM::Class::HASH};
108
109use constant {
110    ST_ADDED      => 'ST_ADDED',
111    ST_DELETED    => 'ST_DELETED',
112    ST_MERGED     => 'ST_MERGED',
113    ST_MODIFIED   => 'ST_MODIFIED',
114    ST_O_ADDED    => 'ST_O_ADDED',
115    ST_O_DELETED  => 'ST_O_DELETED',
116    ST_UNCHANGED  => 'ST_UNCHANGED',
117    ST_UNKNOWN    => 'ST_UNKNOWN',
118    can_be_source => 1,
119};
120
121__PACKAGE__->class({
122    dests            => '@',
123    ns               => '$',
124    path             => '$',
125    source_of        => '%',
126    status           => {isa => '$', default => ST_UNKNOWN},
127    status_of_source => {isa => '$', default => ST_UNKNOWN},
128});
129
130# Returns true if target has an OK status.
131sub is_ok {
132    my ($self) = @_;
133    my $status = $self->get_status();
134    grep {$_ eq $status}
135        (ST_ADDED, ST_MERGED, ST_MODIFIED, ST_O_ADDED, ST_UNCHANGED);
136}
137
138# Shorthand for $target->get_status() eq $target->ST_UNCHANGED.
139sub is_unchanged {
140    $_[0]->get_status() eq ST_UNCHANGED;
141}
142
143# ------------------------------------------------------------------------------
1441;
145__END__
146
147=head1 NAME
148
149FCM::Context::Make::Extract
150
151=head1 SYNOPSIS
152
153    use FCM::Context::Make::Extract;
154    my $ctx = FCM::Context::Make::Extract->new();
155
156=head1 DESCRIPTION
157
158Provides a context object for the FCM extract system. All the classes described
159below are sub-classes of L<FCM::Class::HASH|FCM::Class::HASH>.
160
161=head1 OBJECTS
162
163=head2 FCM::Context::Make::Extract
164
165An instance of this class represents an extract. It has the following
166attributes:
167
168=over 4
169
170=item dest
171
172The destination of the extract.
173
174=item id
175
176The ID of the current context. (default="extract")
177
178=item id_of_class
179
180The class ID of the current context. (default="extract")
181
182=item ns_list
183
184An ARRAY of name-spaces of the projects to extract.
185
186=item project_of
187
188A HASH to map (key) the name-spaces of the projects in this extract to (value)
189their corresponding contexts.
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 status
198
199The status of the extract. See L<FCM::Context::Make|FCM::Context::Make> for the
200status constants.
201
202=item target_of
203
204A HASH to map (key) the name-spaces of the targets in this extract to (value)
205their corresponding contexts.
206
207=back
208
209=head2 FCM::Context::Make::Extract::Project
210
211An instance of this class represents a project in an extract. It has the
212following attributes:
213
214=over 4
215
216=item cache
217
218The file system location (cache) of this project.
219
220=item inherited
221
222This project is inherited?
223
224=item locator
225
226An instance of L<FCM::Context::Locator|FCM::Context::Locator> that represents
227the locator of this project.
228
229=item ns
230
231The name-space of this project.
232
233=item path_excl
234
235An ARRAY of patterns to match the names of the paths that will be excluded in
236this project.
237
238=item path_incl
239
240An ARRAY of patterns to match the names of the paths that will always be
241included in this project.
242
243=item path_root
244
245The relative path in a project tree for the root name-space. If this is
246specified, the system will extract only files under this path, and their
247name-spaces will be adjusted to be relative to this path.
248
249=item trees
250
251An ARRAY of the tree contexts in this project. By convention, the 0th element is
252the base tree.
253
254=back
255
256=head2 FCM::Context::Make::Extract::Tree
257
258An instance of this class represents a tree in a project. It has the following
259attributes:
260
261=over 4
262
263=item cache
264
265The file system location (cache) of this tree.
266
267=item inherited
268
269A flag to indicate whether this tree is provided by an inherited extract.
270
271=item key
272
273The key of this tree. By convention, the base tree is the 0th key.
274
275=item locator
276
277An instance of L<FCM::Context::Locator|FCM::Context::Locator> that represents
278the locator of this tree.
279
280=item ns
281
282The name-space of the project in which this tree belongs.
283
284=item sources
285
286An ARRAY of source file contexts provided by this tree.
287
288=back
289
290=head2 FCM::Context::Make::Extract::Source
291
292An instance of this class represents a source file provided by a project tree.
293It has the following attributes:
294
295=over 4
296
297=item cache
298
299The file system location (cache) of this source file.
300
301=item key_of_tree
302
303The key of the tree that provides this source file.
304
305=item locator
306
307An instance of L<FCM::Context::Locator|FCM::Context::Locator> that represents
308the locator of the source file.
309
310=item ns
311
312The full (mapped) name-space of the source file, (including the leading project
313name-space).
314
315=item ns_in_tree
316
317The original name-space of the source file, relative to its path in the tree.
318
319=item status
320
321The status of the source file. It can take the value of one of the
322FCM::Context::Make::Extract::Source->ST_* constants. See </CONSTANTS> for detail.
323
324=back
325
326In addition, an instance of FCM::Context::Make::Extract::Source has the
327following methods:
328
329=over 4
330
331=item $source->is_missing()
332
333Shorthand for $source->get_status() eq $source->ST_MISSING.
334
335=item $source->is_unchanged()
336
337Shorthand for $source->get_status() eq $source->ST_UNCHANGED.
338
339=back
340
341=head2 FCM::Context::Make::Extract::Target
342
343An instance of this class represents an extract target. It has the following
344attributes:
345
346=over 4
347
348=item dests
349
350An ARRAY containing the destination search path of this target. The first
351element is the path to the destination of the current extract, and the rest are
352destinations to inherited extracts.
353
354=item ns
355
356The full name-space of this target.
357
358=item path
359
360Returns the actual destination path of this target.
361
362=item source_of
363
364A HASH for mapping (key) the keys of the trees to (value) the corresponding
365contexts of the source files provided by the trees to this target.
366
367=item status
368
369The status of the target destination. It can take the value of one of the
370FCM::Context::Make::Extract::Target->ST_* constants. See </CONSTANTS> for detail.
371
372=item status_of_source
373
374The status of the target, with respect to its sources. It can take the value of
375one of the FCM::Context::Make::Extract::Target->ST_* constants. See </CONSTANTS>
376for detail.
377
378=back
379
380In addition, an instance of FCM::Context::Make::Extract::Target has the
381following methods:
382
383=over 4
384
385=item $target->can_be_source()
386
387Returns true if the destination status indicates that the target is usable as a
388source file of a subsequent a make (step).
389
390=item $target->is_ok()
391
392Returns true if the target has a OK destination status.
393
394=item $target->is_unchanged()
395
396Shorthand for $target->get_status() eq $target->ST_UNCHANGED.
397
398=back
399
400=head1 CONSTANTS
401
402The following is a list of constants:
403
404=over 4
405
406=item FCM::Context::Make::Extract->CTX_PROJECT
407
408An alias to FCM::Context::Make::Extract::Project.
409
410=item FCM::Context::Make::Extract->CTX_SOURCE
411
412An alias to FCM::Context::Make::Extract::Source.
413
414=item FCM::Context::Make::Extract->CTX_TARGET
415
416An alias to FCM::Context::Make::Extract::Target.
417
418=item FCM::Context::Make::Extract->CTX_TREE
419
420An alias to FCM::Context::Make::Extract::Tree.
421
422=item FCM::Context::Make::Extract->ID_OF_CLASS
423
424The default value of the "id" attribute (of an instance), and the ID of the
425functional class. ("extract")
426
427=item FCM::Context::Make::Extract->MIRROR
428
429A flag to tell the mirror sub-system that the targets of this context can be
430used as inputs sources to subsequent steps for the configuration file in the
431mirror destination.
432
433=item FCM::Context::Make::Extract::Source->ST_NORMAL
434
435Source status: normal.
436
437=item FCM::Context::Make::Extract::Source->ST_UNCHANGED
438
439Source status: source is unchanged (against base).
440
441=item FCM::Context::Make::Extract::Source->ST_MISSING
442
443Source status: source is a placeholder in a target. It does not actually exist
444in the source tree.
445
446=item FCM::Context::Make::Extract::Target->ST_ADDED
447
448As destination status: new file in the target destination. As source status:
449added by a source in a diff tree.
450
451=item FCM::Context::Make::Extract::Target->ST_DELETED
452
453As destination status: file removed from the target destination. As source
454status: target removed by a diff tree.
455
456=item FCM::Context::Make::Extract::Target->ST_MERGED
457
458As source status: modified by 2 or more diff trees.
459
460=item FCM::Context::Make::Extract::Target->ST_MODIFIED
461
462As destination status: target destination is modified. As source status:
463modified by 1 diff tree.
464
465=item FCM::Context::Make::Extract::Target->ST_O_ADDED
466
467As destination status: new file in the target destination, overriding a file in
468an inherited destination.
469
470=item FCM::Context::Make::Extract::Target->ST_O_DELETED
471
472As destination status: target destination should be removed, but there is still
473a file in an inherited destination.
474
475=item FCM::Context::Make::Extract::Target->ST_UNCHANGED
476
477As destination status: target destination is unchanged. As source status:
478unchanged by a diff tree.
479
480=item FCM::Context::Make::Extract::Target->ST_UNKNOWN
481
482Status is unknown.
483
484=back
485
486=head1 SEE ALSO
487
488L<FCM::System::Make::Extract|FCM::System::Make::Extract>
489
490=head1 COPYRIGHT
491
492Copyright (C) 2006-2021 British Crown (Met Office) & Contributors.
493
494=cut
Note: See TracBrowser for help on using the repository browser.