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

source: vendors/lib/FCM/System/Make/Build/Task/Preprocess.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.6 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::Preprocess;
23use base qw{FCM::Class::CODE};
24
25use FCM::Context::Event;
26use FCM::System::Exception;
27use FCM::System::Make::Build::Task::Share qw{_props_to_opts};
28use File::Spec::Functions qw{catfile};
29use Text::ParseWords qw{shellwords};
30
31use FCM::System::Exception;
32
33my $E = 'FCM::System::Exception';
34
35__PACKAGE__->class(
36    {name => '$', prop_of => '%', util => '&'},
37    {action_of => {main => \&_main, prop_of => sub {$_[0]->{prop_of}}}},
38);
39
40sub _main {
41    my ($attrib_ref, $target) = @_;
42    my $NAME = $attrib_ref->{name};
43    my $P     = sub {$target->get_prop_of($_[0])};
44    my @paths = @{$target->get_info_of('paths')};
45    my @include_paths
46        = map {catfile(($_ eq $paths[0] ? q{.} : $_), 'include')} @paths;
47    my %opt_of = (
48        D => $P->($NAME . '.flag-define'),
49        I => $P->($NAME . '.flag-include'),
50    );
51    my @command = (
52        shellwords($P->($NAME)),
53        shellwords($P->($NAME . '.flags')),
54        _props_to_opts($opt_of{D}, shellwords($P->($NAME .  '.defs'))),
55        _props_to_opts($opt_of{I}, @include_paths),
56        _props_to_opts($opt_of{I}, shellwords($P->($NAME .  '.include-paths'))),
57        $target->get_path_of_source(),
58    );
59    my %value_of = %{$attrib_ref->{util}->shell_simple(\@command)};
60    if ($value_of{rc}) {
61        return $E->throw(
62            $E->SHELL, {command_list => \@command, %value_of}, $value_of{e},
63        );
64    }
65    $attrib_ref->{util}->event(
66        FCM::Context::Event->MAKE_BUILD_SHELL_OUT, undef, $value_of{e},
67    );
68    $value_of{o} ||= q{};
69    $attrib_ref->{util}->file_save($target->get_path(), $value_of{o});
70    $target;
71}
72
73# ------------------------------------------------------------------------------
741;
75__END__
76
77=head1 NAME
78
79FCM::System::Make::Build::Task::Preprocess
80
81=head1 SYNOPSIS
82
83    use FCM::System::Make::Build::Task::Preprocess;
84    my $build_task = FCM::System::Make::Build::Task::Preprocess->new(\%attrib);
85    $build_task->main($target);
86
87=head1 DESCRIPTION
88
89Invokes the preprocessor on the target source to generate the target.
90
91=head1 METHODS
92
93=over 4
94
95=item $class->new(\%attrib)
96
97Creates and returns a new instance. %attrib should contain:
98
99=over 4
100
101=item {name}
102
103The property name of the preprocessor.
104
105=item {prop_of}
106
107A HASH to map the property names and their default values.
108
109=item {util}
110
111An instance of L<FCM::Util|FCM::Util>.
112
113=back
114
115=item $instance->main($target)
116
117Invokes the preprocessor shell command on the target source to generate the
118target.
119
120=item $instance->prop_of()
121
122Returns the HASH that maps the property names (used by this task) to their
123default values.
124
125=back
126
127=head1 COPYRIGHT
128
129(C) Crown copyright Met Office. All rights reserved.
130
131=cut
Note: See TracBrowser for help on using the repository browser.