Subversion Repositories DevTools

Rev

Rev 6490 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6242 dpurdie 1
########################################################################
2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
3
#
4
# Module name   : jats.sh
5
# Module type   : Makefile system
6
# Compiler(s)   : n/a
7
# Environment(s): jats
8
#
9
# Description   : This package extends the JATS toolset at build time
10
#                 It provides additional directives to the JATS makefiles
11
#                 to simplify the directives.
12
#
13
#                 The directive matches up with a run-time tool to
14
#                 do the bulk of the work.
15
#
16
# Operation     : This package adds the JATS directive MakeRpmPackage
17
#                 When used the directive will use GenerateFiles to invoke
18
#                 a script (DebianPackager.pl) to actually do the hard work.
19
#
20
# Syntax        : MakeRpmPackage (<platforms>, Options+);
21
#                 Where Options may be one of:
22
#                   --Script=PackagerScript             - Mandatory. Name of a the packaging script
23
#                   --Name=Name                         - Redhat Package name(optional)
24
#                   --Variant=Text                      - Package Variant(optional)
25
#                   --DeployMode                        - Ignored
26
#                   --NoDeployMode                      - Ignored
27
#                                                         Default for embedded devices
28
#                   --TarFile[=TemplateName]            - Create named .tgz file, of the data area [not Debian scripts]
29
#                   --TarFile                           - Same as --TarFile=PACKAGE_VERSION_PLATFORM_TYPE or PACKAGE_VERSION_PLATFORM
30
#                   --TarOnly                           - Suppress the Debian Build
31
#                   --NoArch                            - Marks the package as having no specific architecture
32
#
33
#               Templates may contain:
34
#                   PACKAGE
35
#                   VARIANT
36
#                   VERSION
37
#                   PLATFORM
38
#                   RELEASE
39
#                   TYPE
40
#                   ARCH
41
#                       
42
#......................................................................#
43
 
44
require 5.006_001;
45
#use strict;
46
use warnings;
47
#use PackagerUtils;
48
 
49
#-------------------------------------------------------------------------------
50
# Function        : MakeRpmPackage
51
#
52
# Description     : Create a Debian Package
53
#
54
# Inputs          : See above
55
#
56
# Returns         : Nothing 
57
#
58
sub MakeRpmPackage
59
{
60
    my( $platforms, @elements ) = @_;
61
    Debug2( "MakeRpmPackage($platforms, @elements)" );
62
    return if ( ! ActivePlatform($platforms) );
63
 
64
    my $build_name =  $::ScmBuildPackage;
65
    my $build_version = $::ScmBuildVersionFull;
66
    my $build_variant = '';
67
 
68
    my $name_set=0;
69
    my $variant_set=0;
70
 
71
    my $tarOnly;
72
    my $tarFileName = '';
73
    my @outputFiles;
74
    my @optArgs;
75
    my $noArch;
76
 
77
    my $script;
78
 
79
    #
80
    #   Collect user arguments
81
    #   They are all processed within the toolset
82
    #
83
    foreach ( @elements )
84
    {
85
        if ( m/^--Script=(.+)/i ) {
86
            ReportError ("MakeRpmPackage: --Script. RPM script name already set") if $script;
87
            $script = $1;
88
 
89
        } elsif ( m/^--RpmScript=(.+)/i ) {
90
            ReportError ("MakeDebianPackage: --RpmScript. RPM script name already set") if $script;
91
            $script = $1;
92
        } elsif ( m/^--Name=(.+)/i ) {
93
            $build_name = $1;
94
            $name_set++;
95
 
96
        } elsif ( m/^--Variant=(.+)/i ) {
97
            $build_variant = $1;
98
            $variant_set++;
99
 
100
        } elsif ( m/^--(No)?DeployMode/i ) {
101
 
102
        } elsif ( m/^--NoArch$/i ) {
103
            $noArch = 1;
104
 
105
        } elsif ( m/^--TarOnly$/i ) {
106
            $tarOnly = 1;
107
 
108
        } elsif ( m/^--TarFile(=(.*))?/i ) {
109
            $tarFileName = defined($1) ? $2 : 'DEFAULT';
110
 
111
        } elsif ( m/^--/ ) {
112
            ReportError("MakeRpmPackage. Unknown option: $_");
113
 
114
        } else {
115
            ReportError("MakeRpmPackage. Unknown argument: $_");
116
        }
117
    }
118
 
119
    #
120
    #   Sanity test
121
    #
122
    ReportError ("MakeRpmPackage: Not supported on a GENERIC target") if ( $ScmPlatform eq 'GENERIC' );
123
    ReportError ("MakeRpmPackage: Script name not defined") unless ( $script );
124
    ReportError ("MakeRpmPackage: --Name option can only be used once") if ( $name_set > 1 );
125
    ReportError ("MakeRpmPackage: --Variant option can only be used once") if ( $variant_set > 1 );
126
    ErrorDoExit();
127
 
128
    #
129
    #   If the platform cannot generate a native installer then (silently) ignore the request
130
    #   unless the user has specified a --TarOnly
131
    #
132
    my $canGenerateInstaller = ActivePlatform('PKG_RPM');
133
    if ( !$canGenerateInstaller && !$tarOnly) {
134
        Verbose ("MakeRpmPackage: Installer not builadble for this platform");
135
        return;
136
    }
137
 
138
    #   Sanity check the package name and version
139
    #   RedHat has stricter requirements than JATS
140
    #       Name:    Upper and Lower case letters (a-z), digits (0-9), plus (+) and minus (-) signs, and periods (.).
141
    #                '-' is used as a field seperator, although it is allowed in names
142
    #                Release Manager does not allow '.'
143
    #       Version: alphanumerics and the characters . + - : (full stop, plus, hyphen, colon) and should start with a digit
144
    #
145
    #   Allow ( and cleanup )
146
    #       Whitespace   -> -
147
    #       _           -> -
148
    #       Remove multiple '-' characters
149
    #       Lowercase all text
150
    #
151
 
152
    $build_name = canonicalName ($build_name, 'RPM');
153
 
154
    #
155
    #   Sanity test the version information
156
    #   
157
 
158
    unless ( $::ScmBuildVersionFull =~ m/^[0-9][-+:.A-Za-z0-9]+$/ )
159
    {
160
        Error ("Package Version does not conform to RedHat Requirements",
161
               "Must only contain: (a-zA-Z) (0-9), _ and .",
162
               "Must start with a number",
163
               );
164
    }
165
 
166
    #
167
    #   Build up the build name
168
    #       Add variant to base name.
169
    #
170
    if ( $build_variant )
171
    {
172
        unless ( $build_variant =~ m/^[a-z[A-Z][_+a-zA-Z0-9]+$/ )
173
        {
174
            Error ("Build Variant does not conform to RedHat Requirements",
175
                   "Must be at least two characters long",
176
                   "Must start with an alphabetic character",
177
                   "Must only contain: (a-zA-Z) (0-9) and _",
178
                   "Provided Variant: $build_variant");
179
        }
180
        $build_name .= '-' . $build_variant;
181
    }
182
 
183
    #
184
    #   Create the name of the target package
185
    #   The form of the name is of a fixed form.
186
    #   Note: "-" used to join parts of the RedHat name
187
    #         name-version-release.architecture.rpm
188
    #
189
    #         release appears to be 'el7' - under RHEL7 and Centos
190
    #         Append P or D to it
191
    #
192
    my $PkgArch = GetGlobalOption('PACKAGE_ARCH', $::ScmPlatform);
193
 
194
    my $PkgRelease = GetGlobalOption('PACKAGE_RELEASE', '') . '$(GBE_TYPE)';
195
    push @optArgs, '-RpmRelease', $PkgRelease;
196
 
197
    if ($noArch)
198
    {
199
        $PkgArch = 'noarch';
200
        $PkgType = '';
201
        push @optArgs, "-NoArch";
202
    }
203
    my $PkgName = "${build_name}-${::ScmBuildVersionFull}-${PkgRelease}.${PkgArch}.rpm";
204
    push @optArgs, "-PkgArch=$PkgArch";
6531 dpurdie 205
    unless ($tarOnly) {
206
        push (@outputFiles, $PkgName);
207
        push @optArgs, "-Output=--GeneratedProg{$PkgName}";
208
    }
6242 dpurdie 209
 
210
    #
211
    #   Create name for the optional TGZ file
212
    #       Allow user to specify parts of the name symbolically
213
    #
214
    if ($tarFileName)
215
    {
216
        if ($tarFileName eq 'DEFAULT')
217
        {
218
            $tarFileName = 'PACKAGE_VERSION_RELEASE.PLATFORM';
219
            if ($deploy_mode && ! $noArch)
220
            {
221
                $tarFileName .= '_TYPE';
222
            }
223
        }
224
 
225
        if ($noArch) {
226
            $PkgArch = 'all';
227
        }
228
 
229
        $tarFileName =~ s~PACKAGE~${build_name}~g;
230
        $tarFileName =~ s~VERSION~${::ScmBuildVersionFull}~g;
6531 dpurdie 231
        $tarFileName =~ s~PLATFORM~${::ScmPlatform}~g;
6242 dpurdie 232
        $tarFileName =~ s~ARCH~${PkgArch}~g;
233
        $tarFileName =~ s~TYPE~\$(GBE_TYPE)~;
234
        $tarFileName =~ s~RELEASE~${PkgRelease}~g;
235
        $tarFileName .= '.tgz' unless $tarFileName =~ m~\.tgz$~;
236
        push @outputFiles,  $tarFileName;
237
 
6531 dpurdie 238
        push @optArgs, "-TarFile=--GeneratedProg{$tarFileName}";
239
#        push @optArgs, "-TarFile=$tarFileName";
6242 dpurdie 240
        push (@optArgs, '-TarOnly' ) if $tarOnly;
241
    }
242
 
243
    #
244
    #   Simply use Generate Files
245
    #       With lots of options
246
    #
247
    Src ( '*', $script );
248
    GenerateFiles ('*', "--Tool=DebianPackager.pl",               # Associated tool
249
                        "--AutoGenerate",                         # Build when needed
250
                        "--UnknownPreq",                          # Always build
251
                        "--Clean",                                # Script supports jats clean
252
                        "--Text=RPM Package",                     # Display when building
253
 
254
                        '--Var(BuildName)',                       # Target Package
255
                        '--Var(BuildVersion)',                    # Target Version
256
                        '--Var(Platform)',                        # Target platform
257
                        '--Var(Product)',                         # Target product
258
                        '--Var(Target)',                          # Underlying Target
259
                        '--Var(Type)',                            # Build Type
260
 
261
                        '--Var(Verbose)',                         # Verbose operation
262
 
263
                        '--Var(InterfaceDir)',                    # Interface Directory
264
                        '--Var(InterfaceIncDir)',
265
                        '--Var(InterfaceLibDir)',
266
                        '--Var(InterfaceBinDir)',
267
 
268
                        '--Var(LibDir)',                          # My Artifacts
269
                        '--Var(BinDir)',
270
 
271
                        '--Var(PackageDir)',                      # My Package
272
                        '--Var(PackageLibDir)',                   # My Package Library
273
                        '--Var(PackageBinDir)',                   # My Package Bin
274
                        '--Var(PackagePkgDir)',                   # My Package/pkg.target
275
 
276
                        '--Var(LocalIncDir)',                     # Installed Artifacts
277
                        '--Var(LocalLibDir)',
278
                        '--Var(LocalBinDir)',
279
 
280
                        "-genRpm",                                # Type to generate
281
                        "-Script=--Prerequisite($script)",        # Packager script
282
                        "-Name=$build_name",                      # Massaged Package Name
283
                        "-Variant=$build_variant",                # Variant Name
284
                        @optArgs,                                 # Optional args
285
                        );
286
 
287
    #
288
    #   The Packager has created a binary in the 'PROG' directory
289
    #   Lets package it as a program.
290
    #
291
    PackageFile ('*', @outputFiles );
292
}
293
 
294
1;