Subversion Repositories DevTools

Rev

Rev 3967 | Rev 5710 | 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
########################################################################
3
# Copyright ( C ) 2004 ERG Limited, All rights reserved
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
103
    #
104
    if ( $#args == 2 && ($args[2] eq 'cots' || $args[2] eq 'tool' ))
105
    {
106
        $result{RELAXED_VERSION} = 1;           # Legacy (COTS) packages have no number scheme
107
    }
108
 
109
    #
227 dpurdie 110
    #   Process non-flagged options
111
    #
112
    Error ("BuildName. No name provided") unless ( defined($args[0]) );
113
    my $BUILDNAME = $args[0];
114
    my $BUILDVERSION = $args[1] if ( defined($args[1]) );
115
 
116
    #
117
    #   Validate the format of BUILDNAME
118
    #   BUILDNAME is inserted into the descpkg file and tools rely on the
119
    #   correct form:
120
    #
121
    if ( $result{RELAXED_VERSION} )
122
    {
123
        #
124
        #   Relaxed version allows for some old cots packages
125
        #   DO NOT USE THIS AS A REGULAR OPTION. ITS A KLUDGE
126
        #
127
        #   This form will only accept two or three fields as
128
        #       "name", "version"
129
        #       "name", "version", "project"
130
        #
131
        $result{BUILDNAME_PACKAGE} = $args[0];
132
        $result{BUILDNAME_VERSION} = $args[1] || Error("BuildName. No version specified");;
133
        $result{BUILDNAME_PROJECT} = $args[2] || '';
134
 
135
        Error ("Package Name should not contain spaces",
136
               "Name: \'$args[0]\'" ) if ( $args[0] =~ m~\s~ );
137
 
138
        Error ("Package Version should not contain spaces",
139
               "Version: \'$args[1]\'" ) if ( $args[1] =~ m~\s~ );
140
 
141
        Error ("Package Project should not contain spaces",
142
               "Project: \'$args[2]\'" ) if ( $args[2] && $args[2] =~ m~\s~ );
143
 
144
    }
3967 dpurdie 145
    elsif ( $BUILDNAME =~ m~^\s*([\w-]+)\s+(\d+\.\d+\.\d+)[\s.]+(\w+)\s*$~ )
227 dpurdie 146
    {
147
        $result{BUILDNAME_PACKAGE} = $1;
148
        $result{BUILDNAME_VERSION} = $2;
149
        $result{BUILDNAME_PROJECT} = $3;
150
 
151
    }
3967 dpurdie 152
    elsif ( $BUILDNAME =~ m~^\s*[\w-]+$~ and $BUILDVERSION =~ m~^(\d+\.\d+\.\d+)\.(\w+)\s*$~ )
227 dpurdie 153
    {
154
        $result{BUILDNAME_PACKAGE} = $BUILDNAME;
155
        $result{BUILDNAME_VERSION} = $1;
156
        $result{BUILDNAME_PROJECT} = $2;
157
    }
158
    else
159
    {
160
        Error( "BUILDNAME is not compatible with dpkg_archive tools",
161
               "Allowed formats: 'name nn.nn.nn prj' or 'name', 'nn.nn.nn.prj' ",
3967 dpurdie 162
               "Arguments: '@arguments'" );
227 dpurdie 163
    }
164
 
165
    #
166
    #   Compatability values
167
    #       BUILDNAME       - A space seperated name of name, ver, project
168
    #       BUILDVERSION    - Version number and project if available
169
 
170
    $result{BUILDNAME} = $result{BUILDNAME_PACKAGE};
171
    $result{BUILDNAME} .= ' ' . $result{BUILDNAME_VERSION};
172
    $result{BUILDNAME} .= ' ' . $result{BUILDNAME_PROJECT} if ($result{BUILDNAME_PROJECT}) ;
173
 
174
    $result{BUILDVERSION} = $result{BUILDNAME_VERSION};
175
    $result{BUILDVERSION} .= '.' . $result{BUILDNAME_PROJECT} if ( $result{BUILDNAME_PROJECT} );
176
 
177
#    DebugDumpData ("BuildNameInfo", \%result);
178
    return \%result;
179
}
180
 
181
1;