Subversion Repositories DevTools

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

########################################################################
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
#
# Module name   : PackagerUtils.pm
# Module type   : JATS Utility
# Compiler(s)   : Perl
# Environment(s): jats
#
# Description   : Some utilities common to:
#                   Build-Time
#                       Debian Packager
#                       RPM Packager
#                   Run-Time  
#                       DebianPackager Runtime
#
# Usage         : See function headers
#
#......................................................................#

require 5.008_002;
use strict;
use warnings;

use JatsError;

#-------------------------------------------------------------------------------
# Function        : canonicalName 
#
# Description     : Convert a Jats package name to a name suitable for the current
#                   target: RPM or Debian
#                   
#                   Used to transform names for the Packager 'Depends' list
#                    
#
# Inputs          : $rawName            - Current Name
#                   $type               - Target Type: Debian or RPM
#                   $quiet              - true: No warnings
#
# Returns         : $canonicalName
#                   May not return 
#
sub canonicalName
{
    my ($rawName, $type, $quiet) = @_;
    my $canonicalName = $rawName;
    my $quietFn = $quiet ? \&Verbose : \&Warning;

    if ($type =~ m~Debian~i) {

        #   Debian has stricter requirements than JATS
        #       Name:    Lower case letters (a-z), digits (0-9), plus (+) and minus (-) signs, and periods (.).
        #                Release Manager does not allow '.'
        #       Version: alphanumerics and the characters . + - : (full stop, plus, hyphen, colon) and should start with a digit
        #
        #   Allow ( and cleanup )
        #       ERGxxxxx    -> erg-xxx
        #       VIXxxxxx    -> vix-xxx
        #       Whitespace   -> -
        #       _           -> -
        #       Remove multiple '-' characters
        #       Lowercase all text

        my $cvt = 0;
        $cvt = 1 if ( $canonicalName =~ s/^ERG/erg-/ );
        $cvt = 2 if ( $canonicalName =~ s/^VIX/vix-/ );
        $cvt = 3 if ( $canonicalName =~ s~\s~-~g );
        $cvt = 4 if ( $canonicalName =~ s~_~-~g );
        $cvt = 5 if ( $canonicalName =~ s~--+~-~g );
        if ( $canonicalName =~ m/[A-Z]/ )
        {
            $cvt = 6;
            $canonicalName = lc $canonicalName;
        }

        $quietFn->("Package Name ($rawName) converted to debian form: $canonicalName") 
            if ( $cvt );

        unless ( $canonicalName =~ m/^[a-z][-+a-z0-9]+$/ )
        {
            Error ("Package Name does not conform to Debian Requirements",
                   "and cannot be massaged into a conforming name",
                   "Must be at least two characters long",
                   "Must start with an alphabetic character",
                   "Must only contain: (a-z) (0-9) and -",
                   "Provided Name: $rawName",
                   "Massaged: $canonicalName");
        }

    } elsif ($type =~ m~Rpm~i) {

        #   Sanity check the package name and version
        #   RedHat has stricter requirements than JATS
        #       Name:    Upper and Lower case letters (a-z), digits (0-9), plus (+) and minus (-) signs, and periods (.).
        #                '-' is used as a field seperator, although it is allowed in names
        #                Release Manager does not allow '.'
        #       Version: alphanumerics and the characters . + - : (full stop, plus, hyphen, colon) and should start with a digit
        #
        #   Allow ( and cleanup )
        #       Whitespace   -> -
        #       _           -> -
        #       Remove multiple '-' characters
        #       Lowercase all text
        #
        my $cvt = 0;
        $cvt = 3 if ( $canonicalName =~ s~\s~_~g );
        $cvt = 4 if ( $canonicalName =~ s~-~_~g );
        $cvt = 5 if ( $canonicalName =~ s~__+~-~g );

        $quietFn->("Package Name ($rawName) converted to RedHat form: $canonicalName")
            if ( $cvt );

        unless ( $canonicalName =~ m/^[a-zA-Z][_+a-zA-Z0-9]+$/ )
        {
            Error ("Package Name does not conform to RedHat Requirements",
                   "and cannot be massaged into a conforming name",
                   "Must be at least two characters long",
                   "Must start with an alphabetic character",
                   "Must only contain: (a-zA-Z) (0-9) and _",
                   "Provided Name: $rawName",
                   "Massaged: $canonicalName");
        }

    } else {
        Error ("canonicalName. Unknown type: $type");
    }

    return $canonicalName; 
}