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 | # ------------------------------------------------------------------------------ |
---|
19 | use strict; |
---|
20 | use warnings; |
---|
21 | |
---|
22 | # ------------------------------------------------------------------------------ |
---|
23 | package FCM::System::Make::Build::FileType::Script; |
---|
24 | use base qw{FCM::System::Make::Build::FileType}; |
---|
25 | |
---|
26 | use FCM::Context::Make::Build; # for FCM::Context::Make::Build::Target |
---|
27 | use FCM::System::Make::Build::Task::Install; |
---|
28 | use File::Basename qw{basename}; |
---|
29 | |
---|
30 | # RE: file (base) name |
---|
31 | my $RE_FILE = qr{[\w\-+.]+}imsx; |
---|
32 | |
---|
33 | # Dependency types and CODE to extract them |
---|
34 | my %SOURCE_ANALYSE_DEP_OF |
---|
35 | = (bin => sub { $_[0] =~ qr{\A\s*(?:\#|;)\s*calls\s*:\s*($RE_FILE)}imsx }); |
---|
36 | |
---|
37 | # Alias |
---|
38 | my $TARGET = 'FCM::Context::Make::Build::Target'; |
---|
39 | |
---|
40 | # Handler of tasks |
---|
41 | my %TASK_CLASS_OF = (install => 'FCM::System::Make::Build::Task::Install'); |
---|
42 | |
---|
43 | sub new { |
---|
44 | my ($class, $attrib_ref) = @_; |
---|
45 | $attrib_ref->{dest_keys} ||= [$TARGET->CT_INCLUDE, 'o', 'o.special']; |
---|
46 | my $SOURCE_TO_TARGETS |
---|
47 | = sub {_source_to_targets($attrib_ref->{dest_keys}, @_)}; |
---|
48 | bless( |
---|
49 | FCM::System::Make::Build::FileType->new({ |
---|
50 | id => 'script', |
---|
51 | file_she => q{}, # Value not used, for file type match |
---|
52 | file_ext => q{}, |
---|
53 | source_analyse_dep_of => {%SOURCE_ANALYSE_DEP_OF}, |
---|
54 | source_to_targets => \&_source_to_targets, |
---|
55 | task_class_of => {%TASK_CLASS_OF}, |
---|
56 | %{$attrib_ref}, |
---|
57 | }), |
---|
58 | $class, |
---|
59 | ); |
---|
60 | } |
---|
61 | |
---|
62 | # Returns a list of targets for a given build source. |
---|
63 | sub _source_to_targets { |
---|
64 | my ($attrib_ref, $source, $prop_hash_ref) = @_; |
---|
65 | my $key = basename($source->get_path()); |
---|
66 | $TARGET->new( |
---|
67 | { category => $TARGET->CT_BIN, |
---|
68 | deps => [@{$source->get_deps()}], |
---|
69 | dep_policy_of => {'bin', $TARGET->POLICY_CAPTURE}, |
---|
70 | key => $key, |
---|
71 | task => 'install', |
---|
72 | } |
---|
73 | ); |
---|
74 | } |
---|
75 | |
---|
76 | # ------------------------------------------------------------------------------ |
---|
77 | 1; |
---|
78 | __END__ |
---|
79 | |
---|
80 | =head1 NAME |
---|
81 | |
---|
82 | FCM::System::Make::Build::FileType::Script |
---|
83 | |
---|
84 | =head1 SYNOPSIS |
---|
85 | |
---|
86 | use FCM::System::Make::Build::FileType::Script; |
---|
87 | my $helper = FCM::System::Make::Build::FileType::Script->new(); |
---|
88 | $helper->source_analyse($handle); |
---|
89 | |
---|
90 | =head1 DESCRIPTION |
---|
91 | |
---|
92 | A wrapper of |
---|
93 | L<FCM::System::Make::Build::FileType|FCM::System::Make::Build::FileType> |
---|
94 | with configurations to work with some UKMO script files. |
---|
95 | |
---|
96 | =head1 COPYRIGHT |
---|
97 | |
---|
98 | (C) Crown copyright Met Office. All rights reserved. |
---|
99 | |
---|
100 | =cut |
---|