Subversion Repositories DevTools

Rev

Rev 6861 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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