Rev 6177 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#! perl######################################################################### COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.## Module name : jats.sh# Module type : Makefile system# Compiler(s) : n/a# Environment(s): jats## Description : Class to provide utilities associated with a BuildName# All functions are class functions.## Used within buildlib.pl to provide basic parsing and also# used within other programs that need to parse build.pl files## The BuildName directive is a little bit complex due to a lot# of history.## Usage:## Version Who Date Description##......................................................................#require 5.006_001;use strict;use warnings;package BuildName;use JatsError;our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION);use Exporter;$VERSION = 1.00;@ISA = qw(Exporter);# Symbols to autoexport (:DEFAULT tag)@EXPORT = qw( parseBuildName);#-------------------------------------------------------------------------------# Function : parseBuildName## Description : Parse the BuildName directive# Must support a number of different formats# "name nn.nn.nn prj"# "name nn.nn.nn.prj"## "name nn.nn.nn prj", "nn.nn.nn"# "name nn.nn.nn.prj", "nn.nn.nn"## "name", "nn.nn.nn.prj"## "name", "nn.nn.nn", "prj", --RelaxedVersion (deprecated)# "name", "cots_version", "cots"# "name", "nn.nn.nn", "prj"## Inputs : All the BuildName arguments## Returns : A hash with various arguments# DEPLOY_PATCH - Number(optional)# RELAXED_VERSION - Bool(optional)# EXTRA_ARGS - Array(optional)## BUILDNAME_PACKAGE - Mandatory# BUILDNAME_VERSION - Mandatory# BUILDNAME_PROJECT - Mandatory. May be empty## BUILDNAME - BUILDNAME_PACKAGE + BUILDNAME_VERSION + BUILDNAME_PROJECT# BUILDVERSION - BUILDNAME_VERSION + BUILDNAME_PROJECT#sub parseBuildName{my( @arguments ) = @_;my @args;my %result;my $unknownForm;my @errors;Debug( "BuildName(@arguments)" );#.. Parse arguments#.foreach (@arguments){s~["']~~g;if ( m/^--PatchNum=(.*)/ ) {$result{DEPLOY_PATCH} = $1; # Deployment patch number} elsif ( m/^--RelaxedVersion/ ) {$result{RELAXED_VERSION} = 1; # Legacy (COTS) packages have no number scheme} elsif ( m/^--/ ) {push @{$result{EXTRA_ARGS}}, $_; # Unknown options. Just save} else {push @args, $_; # Save other arguments}}## Auto detect Relaxed versioning# cots packages# tool packages# Must be of the 3 arg form ('PkgName', PkgVer', 'Proj')#if ( $#args == 2 && ($args[2] eq 'cots' || $args[2] eq 'tool' )){$result{RELAXED_VERSION} = 1; # Legacy (COTS) packages have no number scheme}if ( $#args == 0 && ($args[0] =~ '(.*)\s+(.*)\s+(cots)$' || $args[0] =~ '(.*)\s+(.*)\s+(tool)$' )){$result{RELAXED_VERSION} = 1; # Legacy (COTS) packages have no number scheme$args[0] = $1;$args[1] = $2;$args[2] = $3;}if ( $#args == 1 && ($args[1] =~ '(.*)[. ](cots)$' || $args[1] =~ '(.*)[. ](tool)$' )){$result{RELAXED_VERSION} = 1; # Legacy (COTS) packages have no number scheme$args[1] = $1;$args[2] = $2;}## Process non-flagged options#Error ("BuildName. No name provided") unless ( defined($args[0]) );my $BUILDNAME = $args[0];my $BUILDVERSION = $args[1] if ( defined($args[1]) );## Validate the format of BUILDNAME# BUILDNAME is inserted into the descpkg file and tools rely on the# correct form:#if ( $result{RELAXED_VERSION} ){## Relaxed version allows for some old cots packages# DO NOT USE THIS AS A REGULAR OPTION. ITS A KLUDGE## This form will only accept two or three fields as# "name", "version"# "name", "version", "project"#$result{BUILDNAME_PACKAGE} = $args[0];$result{BUILDNAME_VERSION} = $args[1] || '';$result{BUILDNAME_PROJECT} = $args[2] || '';push (@errors , "Package Name should not contain spaces","Name: \'$args[0]\'" ) if ( $args[0] =~ m~\s~ );push (@errors , "Package Version not specified" )unless ( $args[1] );push (@errors , "Package Version should not contain spaces","Version: \'$args[1]\'" ) if ( $args[1] && $args[1] =~ m~\s~ );push (@errors , "Package Project should not contain spaces","Project: \'$args[2]\'" ) if ( $args[2] && $args[2] =~ m~\s~ );}elsif ( $#args == 2 ){# Three argument form# 'name', 'nn.nn.nn', 'prj'#$result{BUILDNAME_PACKAGE} = $args[0];$result{BUILDNAME_VERSION} = $args[1] || '';$result{BUILDNAME_PROJECT} = $args[2] || '';push (@errors , "Package Name should not contain spaces","Name: \'$args[0]\'" ) if ( $args[0] =~ m~\s~ );push (@errors , "Package Version not specified" )unless ( $args[1] );push (@errors , "Package Project not specified" )unless ( $args[2] );push (@errors , "Package Project should not contain spaces","Project: \'$args[2]\'" ) if ( $args[2] && $args[2] =~ m~\s~ );push (@errors , "Package Version is not in form nn.nn.nn","Version: \'$args[1]\'" ) unless ( $args[1] =~ m~^\d+\.\d+\.\d+$~ );}elsif ( $BUILDNAME =~ m~^\s*([\w-]+)\s+(\d+\.\d+\.\d+)[\s.]+(\w+)\s*$~ ){# One argument form# name nn.nn.nn prj$result{BUILDNAME_PACKAGE} = $1;$result{BUILDNAME_VERSION} = $2;$result{BUILDNAME_PROJECT} = $3;}elsif ( $BUILDNAME =~ m~^\s*[\w-]+$~ and $BUILDVERSION =~ m~^(\d+\.\d+\.\d+)\.(\w+)\s*$~ ){# Two argument form# 'name', 'nn.nn.nn prj'$result{BUILDNAME_PACKAGE} = $BUILDNAME;$result{BUILDNAME_VERSION} = $1;$result{BUILDNAME_PROJECT} = $2;}else{$unknownForm = 1;}## Descriptive error messageif (@errors || $unknownForm){Error("BUILDNAME is not compatible with dpkg_archive tools","Allowed formats:","'name nn.nn.nn prj'","'name', 'nn.nn.nn.prj'","'name', 'nn.nn.nn', 'prj'","'name', 'cots_version', 'cots'",@errors,"Arguments: '@arguments'" );}## Compatability values# BUILDNAME - A space seperated name of name, ver, project# BUILDVERSION - Version number and project if available# BUILDNAME_BASE_VERSION - Version without the patch/ripple$result{BUILDNAME} = $result{BUILDNAME_PACKAGE};$result{BUILDNAME} .= ' ' . $result{BUILDNAME_VERSION};$result{BUILDNAME} .= ' ' . $result{BUILDNAME_PROJECT} if ($result{BUILDNAME_PROJECT}) ;$result{BUILDVERSION} = $result{BUILDNAME_VERSION};$result{BUILDVERSION} .= '.' . $result{BUILDNAME_PROJECT} if ( $result{BUILDNAME_PROJECT} );$result{BUILDNAME_BASE_VERSION} = $result{BUILDNAME_VERSION};$result{BUILDNAME_BASE_VERSION} =~ s~\.[0-9]+$~~;# DebugDumpData ("BuildNameInfo", \%result);return \%result;}1;