Subversion Repositories DevTools

Rev

Rev 6857 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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