Subversion Repositories DevTools

Rev

Rev 7300 | Rev 7306 | Go to most recent revision | 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;
227 dpurdie 81
 
82
    Debug( "BuildName(@arguments)" );
83
 
84
#.. Parse arguments
85
#.
86
    foreach (@arguments)
87
    {
88
        s~["']~~g;
89
        if ( m/^--PatchNum=(.*)/ ) {
90
            $result{DEPLOY_PATCH} = $1;         # Deployment patch number
91
 
92
        } elsif ( m/^--RelaxedVersion/ ) {
7301 dpurdie 93
            $result{RELAXED_VERSION} = 0;       # Ignored. Will now auto detect
227 dpurdie 94
 
95
        } elsif ( m/^--/ ) {
96
            push @{$result{EXTRA_ARGS}}, $_;    # Unknown options. Just save
97
 
98
        } else {
99
            push @args, $_;                     # Save other arguments
100
        }
101
    }
102
 
103
    #
4032 dpurdie 104
    #   Auto detect Relaxed versioning
105
    #       cots packages
106
    #       tool packages
7301 dpurdie 107
    #   Must allow: 
108
    #       The 3 arg form ('PkgName', PkgVer', 'Proj')
109
    #       The 2 arg form ('PkgName', PkgVer.Proj')
110
    #       The 1 arg form ('PkgName PkgVer Proj')
4032 dpurdie 111
    #
112
    if ( $#args == 2 && ($args[2] eq 'cots' || $args[2] eq 'tool' ))
113
    {
114
        $result{RELAXED_VERSION} = 1;           # Legacy (COTS) packages have no number scheme
115
    }
116
 
6133 dpurdie 117
    if ( $#args == 0 && ($args[0] =~ '(.*)\s+(.*)\s+(cots)$' || $args[0] =~ '(.*)\s+(.*)\s+(tool)$' ))
118
    {
119
        $result{RELAXED_VERSION} = 1;           # Legacy (COTS) packages have no number scheme
120
        $args[0] = $1;
121
        $args[1] = $2;
122
        $args[2] = $3;
123
    }
124
 
125
    if ( $#args == 1 && ($args[1] =~ '(.*)[. ](cots)$' || $args[1] =~ '(.*)[. ](tool)$' ))
126
    {
127
        $result{RELAXED_VERSION} = 1;           # Legacy (COTS) packages have no number scheme
128
        $args[1] = $1;
129
        $args[2] = $2;
130
    }
131
 
4032 dpurdie 132
    #
227 dpurdie 133
    #   Process non-flagged options
134
    #
135
    Error ("BuildName. No name provided") unless ( defined($args[0]) );
136
    my $BUILDNAME = $args[0];
137
    my $BUILDVERSION = $args[1] if ( defined($args[1]) );
138
 
139
    #
140
    #   Validate the format of BUILDNAME
141
    #   BUILDNAME is inserted into the descpkg file and tools rely on the
142
    #   correct form:
143
    #
144
    if ( $result{RELAXED_VERSION} )
145
    {
146
        #
147
        #   Relaxed version allows for some old cots packages
148
        #   DO NOT USE THIS AS A REGULAR OPTION. ITS A KLUDGE
149
        #
7301 dpurdie 150
        #   This form will only accept three fields as
227 dpurdie 151
        #       "name", "version", "project"
152
        #
7301 dpurdie 153
        push (@errors, "Use of --RelaxedVersion with insufficient arguments",
154
              "Aguments: @arguments") unless ($#args == 2) ;
155
 
227 dpurdie 156
        $result{BUILDNAME_PACKAGE} = $args[0];
5783 dpurdie 157
        $result{BUILDNAME_VERSION} = $args[1] || '';
227 dpurdie 158
        $result{BUILDNAME_PROJECT} = $args[2] || '';
159
 
5783 dpurdie 160
        push (@errors , "Package Name should not contain spaces",
227 dpurdie 161
               "Name: \'$args[0]\'" ) if ( $args[0] =~ m~\s~ );
162
 
5783 dpurdie 163
        push (@errors , "Package Version not specified" ) 
164
            unless ( $args[1] );
227 dpurdie 165
 
7301 dpurdie 166
        push (@errors , "Package Project not specified" ) 
167
            unless ( $args[2] );
168
 
5783 dpurdie 169
        push (@errors , "Package Version should not contain spaces",
170
               "Version: \'$args[1]\'" ) if ( $args[1] && $args[1] =~ m~\s~ );
171
 
172
        push (@errors , "Package Project should not contain spaces",
227 dpurdie 173
               "Project: \'$args[2]\'" ) if ( $args[2] && $args[2] =~ m~\s~ );
174
 
175
    }
5783 dpurdie 176
    elsif ( $#args == 2 )
177
    {
178
        # Three argument form
179
        # 'name', 'nn.nn.nn', 'prj'
180
        # 
181
        $result{BUILDNAME_PACKAGE} = $args[0];
182
        $result{BUILDNAME_VERSION} = $args[1] || '';
183
        $result{BUILDNAME_PROJECT} = $args[2] || '';
184
 
185
        push (@errors , "Package Name should not contain spaces",
186
               "Name: \'$args[0]\'" ) if ( $args[0] =~ m~\s~ );
187
 
188
        push (@errors , "Package Version not specified" ) 
189
            unless ( $args[1] );
190
 
191
        push (@errors , "Package Project not specified" ) 
192
            unless ( $args[2] );
193
 
194
        push (@errors , "Package Project should not contain spaces",
195
               "Project: \'$args[2]\'" ) if ( $args[2] && $args[2] =~ m~\s~ );
196
 
197
         push (@errors , "Package Version is not in form nn.nn.nn",
198
               "Version: \'$args[1]\'" ) unless ( $args[1] =~ m~^\d+\.\d+\.\d+$~ );
199
 
200
    }
3967 dpurdie 201
    elsif ( $BUILDNAME =~ m~^\s*([\w-]+)\s+(\d+\.\d+\.\d+)[\s.]+(\w+)\s*$~ )
227 dpurdie 202
    {
5783 dpurdie 203
        # One argument form
204
        #   name nn.nn.nn prj
227 dpurdie 205
        $result{BUILDNAME_PACKAGE} = $1;
206
        $result{BUILDNAME_VERSION} = $2;
207
        $result{BUILDNAME_PROJECT} = $3;
208
 
209
    }
3967 dpurdie 210
    elsif ( $BUILDNAME =~ m~^\s*[\w-]+$~ and $BUILDVERSION =~ m~^(\d+\.\d+\.\d+)\.(\w+)\s*$~ )
227 dpurdie 211
    {
5783 dpurdie 212
        # Two argument form
213
        # 'name', 'nn.nn.nn prj'
227 dpurdie 214
        $result{BUILDNAME_PACKAGE} = $BUILDNAME;
215
        $result{BUILDNAME_VERSION} = $1;
216
        $result{BUILDNAME_PROJECT} = $2;
217
    }
218
    else
219
    {
5783 dpurdie 220
        $unknownForm = 1;
227 dpurdie 221
    }
222
 
223
    #
5783 dpurdie 224
    #   Descriptive error message
225
    if (@errors || $unknownForm)
226
    {
227
        Error("BUILDNAME is not compatible with dpkg_archive tools","Allowed formats:",
228
                    "'name nn.nn.nn prj'",
229
                    "'name', 'nn.nn.nn.prj'",
230
                    "'name', 'nn.nn.nn', 'prj'",
231
                    "'name', 'cots_version', 'cots'",
232
                    @errors,
233
                    "Arguments: '@arguments'" );
234
    }
235
 
236
    #
227 dpurdie 237
    #   Compatability values
238
    #       BUILDNAME       - A space seperated name of name, ver, project
239
    #       BUILDVERSION    - Version number and project if available
240
 
241
    $result{BUILDNAME} = $result{BUILDNAME_PACKAGE};
242
    $result{BUILDNAME} .= ' ' . $result{BUILDNAME_VERSION};
243
    $result{BUILDNAME} .= ' ' . $result{BUILDNAME_PROJECT} if ($result{BUILDNAME_PROJECT}) ;
244
 
245
    $result{BUILDVERSION} = $result{BUILDNAME_VERSION};
246
    $result{BUILDVERSION} .= '.' . $result{BUILDNAME_PROJECT} if ( $result{BUILDNAME_PROJECT} );
247
 
248
#    DebugDumpData ("BuildNameInfo", \%result);
249
    return \%result;
250
}
251
 
252
1;