Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
227 dpurdie 1
#! perl
2
########################################################################
7300 dpurdie 3
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
227 dpurdie 4
#
5
# Module name   : jats.sh
6
# Module type   : Makefile system
7
# Compiler(s)   : n/a
8
# Environment(s): jats
9
#
10
# Description   : Class to provide utilities associated with a BuildName
11
#                 All functions are class functions.
12
#
13
#                 Used within buildlib.pl to provide basic parsing and also
14
#                 used within other programs that need to parse build.pl files
15
#
16
#                 The BuildName directive is a little bit complex due to a lot
17
#                 of history.
18
#
19
# Usage:
20
#
21
# Version   Who      Date        Description
22
#
23
#......................................................................#
24
 
255 dpurdie 25
require 5.006_001;
227 dpurdie 26
use strict;
27
use warnings;
28
 
29
package BuildName;
30
use JatsError;
31
 
32
our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION);
33
use Exporter;
34
 
35
$VERSION = 1.00;
36
@ISA = qw(Exporter);
37
 
38
# Symbols to autoexport (:DEFAULT tag)
39
@EXPORT = qw( parseBuildName
40
            );
41
 
42
 
43
#-------------------------------------------------------------------------------
44
# Function        : parseBuildName
45
#
46
# Description     : Parse the BuildName directive
47
#                   Must support a number of different formats
48
#                       "name nn.nn.nn prj"
49
#                       "name nn.nn.nn.prj"
50
#
51
#                       "name nn.nn.nn prj", "nn.nn.nn"
52
#                       "name nn.nn.nn.prj", "nn.nn.nn"
53
#
54
#                       "name", "nn.nn.nn.prj"
55
#
5783 dpurdie 56
#                       "name", "nn.nn.nn", "prj", --RelaxedVersion (deprecated)
57
#                       "name", "cots_version", "cots"
58
#                       "name", "nn.nn.nn", "prj"
227 dpurdie 59
#
60
# Inputs          : All the BuildName arguments
61
#
62
# Returns         : A hash with various arguments
63
#                       DEPLOY_PATCH        - Number(optional)
64
#                       RELAXED_VERSION     - Bool(optional)
65
#                       EXTRA_ARGS          - Array(optional)
66
#
67
#                       BUILDNAME_PACKAGE   - Mandatory
68
#                       BUILDNAME_VERSION   - Mandatory
69
#                       BUILDNAME_PROJECT   - Mandatory. May be empty
70
#
71
#                       BUILDNAME           - BUILDNAME_PACKAGE + BUILDNAME_VERSION + BUILDNAME_PROJECT
72
#                       BUILDVERSION        - BUILDNAME_VERSION + BUILDNAME_PROJECT
73
#
74
sub parseBuildName
75
{
76
    my( @arguments ) = @_;
77
    my @args;
78
    my %result;
5783 dpurdie 79
    my $unknownForm;
80
    my @errors;
7306 dpurdie 81
    my $veritasKludge;
227 dpurdie 82
 
83
    Debug( "BuildName(@arguments)" );
84
 
85
#.. Parse arguments
86
#.
87
    foreach (@arguments)
88
    {
89
        s~["']~~g;
90
        if ( m/^--PatchNum=(.*)/ ) {
91
            $result{DEPLOY_PATCH} = $1;         # Deployment patch number
92
 
93
        } elsif ( m/^--RelaxedVersion/ ) {
7301 dpurdie 94
            $result{RELAXED_VERSION} = 0;       # Ignored. Will now auto detect
227 dpurdie 95
 
96
        } elsif ( m/^--/ ) {
97
            push @{$result{EXTRA_ARGS}}, $_;    # Unknown options. Just save
98
 
99
        } else {
100
            push @args, $_;                     # Save other arguments
101
        }
102
    }
103
 
104
    #
4032 dpurdie 105
    #   Auto detect Relaxed versioning
106
    #       cots packages
107
    #       tool packages
7301 dpurdie 108
    #   Must allow: 
109
    #       The 3 arg form ('PkgName', PkgVer', 'Proj')
110
    #       The 2 arg form ('PkgName', PkgVer.Proj')
111
    #       The 1 arg form ('PkgName PkgVer Proj')
4032 dpurdie 112
    #
113
    if ( $#args == 2 && ($args[2] eq 'cots' || $args[2] eq 'tool' ))
114
    {
115
        $result{RELAXED_VERSION} = 1;           # Legacy (COTS) packages have no number scheme
116
    }
117
 
6133 dpurdie 118
    if ( $#args == 0 && ($args[0] =~ '(.*)\s+(.*)\s+(cots)$' || $args[0] =~ '(.*)\s+(.*)\s+(tool)$' ))
119
    {
120
        $result{RELAXED_VERSION} = 1;           # Legacy (COTS) packages have no number scheme
121
        $args[0] = $1;
122
        $args[1] = $2;
123
        $args[2] = $3;
124
    }
125
 
126
    if ( $#args == 1 && ($args[1] =~ '(.*)[. ](cots)$' || $args[1] =~ '(.*)[. ](tool)$' ))
127
    {
128
        $result{RELAXED_VERSION} = 1;           # Legacy (COTS) packages have no number scheme
129
        $args[1] = $1;
130
        $args[2] = $2;
131
    }
132
 
4032 dpurdie 133
    #
7306 dpurdie 134
    #   Special kludge for the veritas package - the one package that does not
135
    #   have a project extension. MUST be fixed and theis code removed
136
    #
137
    if ( $#args == 1 && $args[0] eq 'veritas' )
138
    {
139
        $result{RELAXED_VERSION} = 1;           # Legacy (COTS) packages with no project suffix
140
        $veritasKludge = 1;
141
        $args[2] = '';
142
    }
143
 
144
    #
227 dpurdie 145
    #   Process non-flagged options
146
    #
147
    Error ("BuildName. No name provided") unless ( defined($args[0]) );
148
    my $BUILDNAME = $args[0];
149
    my $BUILDVERSION = $args[1] if ( defined($args[1]) );
150
 
151
    #
152
    #   Validate the format of BUILDNAME
153
    #   BUILDNAME is inserted into the descpkg file and tools rely on the
154
    #   correct form:
155
    #
156
    if ( $result{RELAXED_VERSION} )
157
    {
158
        #
159
        #   Relaxed version allows for some old cots packages
160
        #   DO NOT USE THIS AS A REGULAR OPTION. ITS A KLUDGE
161
        #
7301 dpurdie 162
        #   This form will only accept three fields as
227 dpurdie 163
        #       "name", "version", "project"
164
        #
7301 dpurdie 165
        push (@errors, "Use of --RelaxedVersion with insufficient arguments",
166
              "Aguments: @arguments") unless ($#args == 2) ;
167
 
227 dpurdie 168
        $result{BUILDNAME_PACKAGE} = $args[0];
5783 dpurdie 169
        $result{BUILDNAME_VERSION} = $args[1] || '';
227 dpurdie 170
        $result{BUILDNAME_PROJECT} = $args[2] || '';
171
 
5783 dpurdie 172
        push (@errors , "Package Name should not contain spaces",
227 dpurdie 173
               "Name: \'$args[0]\'" ) if ( $args[0] =~ m~\s~ );
174
 
5783 dpurdie 175
        push (@errors , "Package Version not specified" ) 
176
            unless ( $args[1] );
227 dpurdie 177
 
7301 dpurdie 178
        push (@errors , "Package Project not specified" ) 
7306 dpurdie 179
            unless ( $args[2] || $veritasKludge );
7301 dpurdie 180
 
5783 dpurdie 181
        push (@errors , "Package Version should not contain spaces",
182
               "Version: \'$args[1]\'" ) if ( $args[1] && $args[1] =~ m~\s~ );
183
 
184
        push (@errors , "Package Project should not contain spaces",
227 dpurdie 185
               "Project: \'$args[2]\'" ) if ( $args[2] && $args[2] =~ m~\s~ );
186
 
187
    }
5783 dpurdie 188
    elsif ( $#args == 2 )
189
    {
190
        # Three argument form
191
        # 'name', 'nn.nn.nn', 'prj'
192
        # 
193
        $result{BUILDNAME_PACKAGE} = $args[0];
194
        $result{BUILDNAME_VERSION} = $args[1] || '';
195
        $result{BUILDNAME_PROJECT} = $args[2] || '';
196
 
197
        push (@errors , "Package Name should not contain spaces",
198
               "Name: \'$args[0]\'" ) if ( $args[0] =~ m~\s~ );
199
 
200
        push (@errors , "Package Version not specified" ) 
201
            unless ( $args[1] );
202
 
203
        push (@errors , "Package Project not specified" ) 
204
            unless ( $args[2] );
205
 
206
        push (@errors , "Package Project should not contain spaces",
207
               "Project: \'$args[2]\'" ) if ( $args[2] && $args[2] =~ m~\s~ );
208
 
209
         push (@errors , "Package Version is not in form nn.nn.nn",
210
               "Version: \'$args[1]\'" ) unless ( $args[1] =~ m~^\d+\.\d+\.\d+$~ );
211
 
212
    }
3967 dpurdie 213
    elsif ( $BUILDNAME =~ m~^\s*([\w-]+)\s+(\d+\.\d+\.\d+)[\s.]+(\w+)\s*$~ )
227 dpurdie 214
    {
5783 dpurdie 215
        # One argument form
216
        #   name nn.nn.nn prj
227 dpurdie 217
        $result{BUILDNAME_PACKAGE} = $1;
218
        $result{BUILDNAME_VERSION} = $2;
219
        $result{BUILDNAME_PROJECT} = $3;
220
 
221
    }
3967 dpurdie 222
    elsif ( $BUILDNAME =~ m~^\s*[\w-]+$~ and $BUILDVERSION =~ m~^(\d+\.\d+\.\d+)\.(\w+)\s*$~ )
227 dpurdie 223
    {
5783 dpurdie 224
        # Two argument form
225
        # 'name', 'nn.nn.nn prj'
227 dpurdie 226
        $result{BUILDNAME_PACKAGE} = $BUILDNAME;
227
        $result{BUILDNAME_VERSION} = $1;
228
        $result{BUILDNAME_PROJECT} = $2;
229
    }
230
    else
231
    {
5783 dpurdie 232
        $unknownForm = 1;
227 dpurdie 233
    }
234
 
235
    #
5783 dpurdie 236
    #   Descriptive error message
237
    if (@errors || $unknownForm)
238
    {
239
        Error("BUILDNAME is not compatible with dpkg_archive tools","Allowed formats:",
240
                    "'name nn.nn.nn prj'",
241
                    "'name', 'nn.nn.nn.prj'",
242
                    "'name', 'nn.nn.nn', 'prj'",
243
                    "'name', 'cots_version', 'cots'",
244
                    @errors,
245
                    "Arguments: '@arguments'" );
246
    }
247
 
248
    #
227 dpurdie 249
    #   Compatability values
7322 dpurdie 250
    #       BUILDNAME               - A space seperated name of name, ver, project
251
    #       BUILDVERSION            - Version number and project if available
252
    #       BUILDNAME_BASE_VERSION  - Version without the patch/ripple
227 dpurdie 253
 
254
    $result{BUILDNAME} = $result{BUILDNAME_PACKAGE};
255
    $result{BUILDNAME} .= ' ' . $result{BUILDNAME_VERSION};
256
    $result{BUILDNAME} .= ' ' . $result{BUILDNAME_PROJECT} if ($result{BUILDNAME_PROJECT}) ;
257
 
258
    $result{BUILDVERSION} = $result{BUILDNAME_VERSION};
259
    $result{BUILDVERSION} .= '.' . $result{BUILDNAME_PROJECT} if ( $result{BUILDNAME_PROJECT} );
260
 
7322 dpurdie 261
    $result{BUILDNAME_BASE_VERSION} = $result{BUILDNAME_VERSION};
262
    $result{BUILDNAME_BASE_VERSION} =~ s~\.[0-9]+$~~;
263
 
264
 
227 dpurdie 265
#    DebugDumpData ("BuildNameInfo", \%result);
266
    return \%result;
267
}
268
 
269
1;