Subversion Repositories DevTools

Rev

Rev 5710 | Rev 5783 | 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
#
56
#                       "name", "nn.nn.nn", "prj", --RelaxedVersion
57
#
58
# Inputs          : All the BuildName arguments
59
#
60
# Returns         : A hash with various arguments
61
#                       DEPLOY_PATCH        - Number(optional)
62
#                       RELAXED_VERSION     - Bool(optional)
63
#                       EXTRA_ARGS          - Array(optional)
64
#
65
#                       BUILDNAME_PACKAGE   - Mandatory
66
#                       BUILDNAME_VERSION   - Mandatory
67
#                       BUILDNAME_PROJECT   - Mandatory. May be empty
68
#
69
#                       BUILDNAME           - BUILDNAME_PACKAGE + BUILDNAME_VERSION + BUILDNAME_PROJECT
70
#                       BUILDVERSION        - BUILDNAME_VERSION + BUILDNAME_PROJECT
71
#
72
sub parseBuildName
73
{
74
    my( @arguments ) = @_;
75
    my @args;
76
    my %result;
77
 
78
    Debug( "BuildName(@arguments)" );
79
 
80
#.. Parse arguments
81
#.
82
    foreach (@arguments)
83
    {
84
        s~["']~~g;
85
        if ( m/^--PatchNum=(.*)/ ) {
86
            $result{DEPLOY_PATCH} = $1;         # Deployment patch number
87
 
88
        } elsif ( m/^--RelaxedVersion/ ) {
89
            $result{RELAXED_VERSION} = 1;       # Legacy (COTS) packages have no number scheme
90
 
91
        } elsif ( m/^--/ ) {
92
            push @{$result{EXTRA_ARGS}}, $_;    # Unknown options. Just save
93
 
94
        } else {
95
            push @args, $_;                     # Save other arguments
96
        }
97
    }
98
 
99
    #
4032 dpurdie 100
    #   Auto detect Relaxed versioning
101
    #       cots packages
102
    #       tool packages
5744 dpurdie 103
    #   Must be of the 3 arg form ('PkgName', PkgVer', 'Proj')
4032 dpurdie 104
    #
105
    if ( $#args == 2 && ($args[2] eq 'cots' || $args[2] eq 'tool' ))
106
    {
107
        $result{RELAXED_VERSION} = 1;           # Legacy (COTS) packages have no number scheme
108
    }
109
 
110
    #
227 dpurdie 111
    #   Process non-flagged options
112
    #
113
    Error ("BuildName. No name provided") unless ( defined($args[0]) );
114
    my $BUILDNAME = $args[0];
115
    my $BUILDVERSION = $args[1] if ( defined($args[1]) );
116
 
117
    #
118
    #   Validate the format of BUILDNAME
119
    #   BUILDNAME is inserted into the descpkg file and tools rely on the
120
    #   correct form:
121
    #
122
    if ( $result{RELAXED_VERSION} )
123
    {
124
        #
125
        #   Relaxed version allows for some old cots packages
126
        #   DO NOT USE THIS AS A REGULAR OPTION. ITS A KLUDGE
127
        #
128
        #   This form will only accept two or three fields as
129
        #       "name", "version"
130
        #       "name", "version", "project"
131
        #
132
        $result{BUILDNAME_PACKAGE} = $args[0];
133
        $result{BUILDNAME_VERSION} = $args[1] || Error("BuildName. No version specified");;
134
        $result{BUILDNAME_PROJECT} = $args[2] || '';
135
 
136
        Error ("Package Name should not contain spaces",
137
               "Name: \'$args[0]\'" ) if ( $args[0] =~ m~\s~ );
138
 
139
        Error ("Package Version should not contain spaces",
140
               "Version: \'$args[1]\'" ) if ( $args[1] =~ m~\s~ );
141
 
142
        Error ("Package Project should not contain spaces",
143
               "Project: \'$args[2]\'" ) if ( $args[2] && $args[2] =~ m~\s~ );
144
 
145
    }
3967 dpurdie 146
    elsif ( $BUILDNAME =~ m~^\s*([\w-]+)\s+(\d+\.\d+\.\d+)[\s.]+(\w+)\s*$~ )
227 dpurdie 147
    {
148
        $result{BUILDNAME_PACKAGE} = $1;
149
        $result{BUILDNAME_VERSION} = $2;
150
        $result{BUILDNAME_PROJECT} = $3;
151
 
152
    }
3967 dpurdie 153
    elsif ( $BUILDNAME =~ m~^\s*[\w-]+$~ and $BUILDVERSION =~ m~^(\d+\.\d+\.\d+)\.(\w+)\s*$~ )
227 dpurdie 154
    {
155
        $result{BUILDNAME_PACKAGE} = $BUILDNAME;
156
        $result{BUILDNAME_VERSION} = $1;
157
        $result{BUILDNAME_PROJECT} = $2;
158
    }
159
    else
160
    {
161
        Error( "BUILDNAME is not compatible with dpkg_archive tools",
162
               "Allowed formats: 'name nn.nn.nn prj' or 'name', 'nn.nn.nn.prj' ",
3967 dpurdie 163
               "Arguments: '@arguments'" );
227 dpurdie 164
    }
165
 
166
    #
167
    #   Compatability values
168
    #       BUILDNAME       - A space seperated name of name, ver, project
169
    #       BUILDVERSION    - Version number and project if available
170
 
171
    $result{BUILDNAME} = $result{BUILDNAME_PACKAGE};
172
    $result{BUILDNAME} .= ' ' . $result{BUILDNAME_VERSION};
173
    $result{BUILDNAME} .= ' ' . $result{BUILDNAME_PROJECT} if ($result{BUILDNAME_PROJECT}) ;
174
 
175
    $result{BUILDVERSION} = $result{BUILDNAME_VERSION};
176
    $result{BUILDVERSION} .= '.' . $result{BUILDNAME_PROJECT} if ( $result{BUILDNAME_PROJECT} );
177
 
178
#    DebugDumpData ("BuildNameInfo", \%result);
179
    return \%result;
180
}
181
 
182
1;