Subversion Repositories DevTools

Rev

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