Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
227 dpurdie 1
#! perl
2
########################################################################
6177 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/ ) {
93
            $result{RELAXED_VERSION} = 1;       # Legacy (COTS) packages have no number scheme
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
5744 dpurdie 107
    #   Must be of the 3 arg form ('PkgName', PkgVer', 'Proj')
4032 dpurdie 108
    #
109
    if ( $#args == 2 && ($args[2] eq 'cots' || $args[2] eq 'tool' ))
110
    {
111
        $result{RELAXED_VERSION} = 1;           # Legacy (COTS) packages have no number scheme
112
    }
113
 
6133 dpurdie 114
    if ( $#args == 0 && ($args[0] =~ '(.*)\s+(.*)\s+(cots)$' || $args[0] =~ '(.*)\s+(.*)\s+(tool)$' ))
115
    {
116
        $result{RELAXED_VERSION} = 1;           # Legacy (COTS) packages have no number scheme
117
        $args[0] = $1;
118
        $args[1] = $2;
119
        $args[2] = $3;
120
    }
121
 
122
    if ( $#args == 1 && ($args[1] =~ '(.*)[. ](cots)$' || $args[1] =~ '(.*)[. ](tool)$' ))
123
    {
124
        $result{RELAXED_VERSION} = 1;           # Legacy (COTS) packages have no number scheme
125
        $args[1] = $1;
126
        $args[2] = $2;
127
    }
128
 
4032 dpurdie 129
    #
227 dpurdie 130
    #   Process non-flagged options
131
    #
132
    Error ("BuildName. No name provided") unless ( defined($args[0]) );
133
    my $BUILDNAME = $args[0];
134
    my $BUILDVERSION = $args[1] if ( defined($args[1]) );
135
 
136
    #
137
    #   Validate the format of BUILDNAME
138
    #   BUILDNAME is inserted into the descpkg file and tools rely on the
139
    #   correct form:
140
    #
141
    if ( $result{RELAXED_VERSION} )
142
    {
143
        #
144
        #   Relaxed version allows for some old cots packages
145
        #   DO NOT USE THIS AS A REGULAR OPTION. ITS A KLUDGE
146
        #
147
        #   This form will only accept two or three fields as
148
        #       "name", "version"
149
        #       "name", "version", "project"
150
        #
151
        $result{BUILDNAME_PACKAGE} = $args[0];
5783 dpurdie 152
        $result{BUILDNAME_VERSION} = $args[1] || '';
227 dpurdie 153
        $result{BUILDNAME_PROJECT} = $args[2] || '';
154
 
5783 dpurdie 155
        push (@errors , "Package Name should not contain spaces",
227 dpurdie 156
               "Name: \'$args[0]\'" ) if ( $args[0] =~ m~\s~ );
157
 
5783 dpurdie 158
        push (@errors , "Package Version not specified" ) 
159
            unless ( $args[1] );
227 dpurdie 160
 
5783 dpurdie 161
        push (@errors , "Package Version should not contain spaces",
162
               "Version: \'$args[1]\'" ) if ( $args[1] && $args[1] =~ m~\s~ );
163
 
164
        push (@errors , "Package Project should not contain spaces",
227 dpurdie 165
               "Project: \'$args[2]\'" ) if ( $args[2] && $args[2] =~ m~\s~ );
166
 
167
    }
5783 dpurdie 168
    elsif ( $#args == 2 )
169
    {
170
        # Three argument form
171
        # 'name', 'nn.nn.nn', 'prj'
172
        # 
173
        $result{BUILDNAME_PACKAGE} = $args[0];
174
        $result{BUILDNAME_VERSION} = $args[1] || '';
175
        $result{BUILDNAME_PROJECT} = $args[2] || '';
176
 
177
        push (@errors , "Package Name should not contain spaces",
178
               "Name: \'$args[0]\'" ) if ( $args[0] =~ m~\s~ );
179
 
180
        push (@errors , "Package Version not specified" ) 
181
            unless ( $args[1] );
182
 
183
        push (@errors , "Package Project not specified" ) 
184
            unless ( $args[2] );
185
 
186
        push (@errors , "Package Project should not contain spaces",
187
               "Project: \'$args[2]\'" ) if ( $args[2] && $args[2] =~ m~\s~ );
188
 
189
         push (@errors , "Package Version is not in form nn.nn.nn",
190
               "Version: \'$args[1]\'" ) unless ( $args[1] =~ m~^\d+\.\d+\.\d+$~ );
191
 
192
    }
3967 dpurdie 193
    elsif ( $BUILDNAME =~ m~^\s*([\w-]+)\s+(\d+\.\d+\.\d+)[\s.]+(\w+)\s*$~ )
227 dpurdie 194
    {
5783 dpurdie 195
        # One argument form
196
        #   name nn.nn.nn prj
227 dpurdie 197
        $result{BUILDNAME_PACKAGE} = $1;
198
        $result{BUILDNAME_VERSION} = $2;
199
        $result{BUILDNAME_PROJECT} = $3;
200
 
201
    }
3967 dpurdie 202
    elsif ( $BUILDNAME =~ m~^\s*[\w-]+$~ and $BUILDVERSION =~ m~^(\d+\.\d+\.\d+)\.(\w+)\s*$~ )
227 dpurdie 203
    {
5783 dpurdie 204
        # Two argument form
205
        # 'name', 'nn.nn.nn prj'
227 dpurdie 206
        $result{BUILDNAME_PACKAGE} = $BUILDNAME;
207
        $result{BUILDNAME_VERSION} = $1;
208
        $result{BUILDNAME_PROJECT} = $2;
209
    }
210
    else
211
    {
5783 dpurdie 212
        $unknownForm = 1;
227 dpurdie 213
    }
214
 
215
    #
5783 dpurdie 216
    #   Descriptive error message
217
    if (@errors || $unknownForm)
218
    {
219
        Error("BUILDNAME is not compatible with dpkg_archive tools","Allowed formats:",
220
                    "'name nn.nn.nn prj'",
221
                    "'name', 'nn.nn.nn.prj'",
222
                    "'name', 'nn.nn.nn', 'prj'",
223
                    "'name', 'cots_version', 'cots'",
224
                    @errors,
225
                    "Arguments: '@arguments'" );
226
    }
227
 
228
    #
227 dpurdie 229
    #   Compatability values
6511 dpurdie 230
    #       BUILDNAME               - A space seperated name of name, ver, project
231
    #       BUILDVERSION            - Version number and project if available
232
    #       BUILDNAME_BASE_VERSION  - Version without the patch/ripple
227 dpurdie 233
 
234
    $result{BUILDNAME} = $result{BUILDNAME_PACKAGE};
235
    $result{BUILDNAME} .= ' ' . $result{BUILDNAME_VERSION};
236
    $result{BUILDNAME} .= ' ' . $result{BUILDNAME_PROJECT} if ($result{BUILDNAME_PROJECT}) ;
237
 
238
    $result{BUILDVERSION} = $result{BUILDNAME_VERSION};
239
    $result{BUILDVERSION} .= '.' . $result{BUILDNAME_PROJECT} if ( $result{BUILDNAME_PROJECT} );
240
 
6511 dpurdie 241
    $result{BUILDNAME_BASE_VERSION} = $result{BUILDNAME_VERSION};
242
    $result{BUILDNAME_BASE_VERSION} =~ s~\.[0-9]+$~~;
243
 
244
 
227 dpurdie 245
#    DebugDumpData ("BuildNameInfo", \%result);
246
    return \%result;
247
}
248
 
249
1;