Subversion Repositories DevTools

Rev

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