#! perl ######################################################################## # Copyright ( C ) 2004 ERG Limited, 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 # # 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; 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 # if ( $#args == 2 && ($args[2] eq 'cots' || $args[2] eq 'tool' )) { $result{RELAXED_VERSION} = 1; # Legacy (COTS) packages have no number scheme } # # 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] || Error("BuildName. No version specified");; $result{BUILDNAME_PROJECT} = $args[2] || ''; Error ("Package Name should not contain spaces", "Name: \'$args[0]\'" ) if ( $args[0] =~ m~\s~ ); Error ("Package Version should not contain spaces", "Version: \'$args[1]\'" ) if ( $args[1] =~ m~\s~ ); Error ("Package Project should not contain spaces", "Project: \'$args[2]\'" ) if ( $args[2] && $args[2] =~ m~\s~ ); } elsif ( $BUILDNAME =~ m~^\s*([\w-]+)\s+(\d+\.\d+\.\d+)[\s.]+(\w+)\s*$~ ) { $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*$~ ) { $result{BUILDNAME_PACKAGE} = $BUILDNAME; $result{BUILDNAME_VERSION} = $1; $result{BUILDNAME_PROJECT} = $2; } else { Error( "BUILDNAME is not compatible with dpkg_archive tools", "Allowed formats: 'name nn.nn.nn prj' or 'name', 'nn.nn.nn.prj' ", "Arguments: '@arguments'" ); } # # Compatability values # BUILDNAME - A space seperated name of name, ver, project # BUILDVERSION - Version number and project if available $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} ); # DebugDumpData ("BuildNameInfo", \%result); return \%result; } 1;