Subversion Repositories DevTools

Rev

Rev 6937 | Blame | Compare with Previous | Last modification | View Log | RSS feed

########################################################################
# 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   : This package extends the JATS toolset at build time
#                 It provides additional directives to the JATS makefiles
#                 to simplify the directives.
#
#                 The directive matches up with a run-time tool to
#                 do the bulk of the work.
#
# Operation     : This package adds the JATS directive MakeRpmPackage
#                 When used the directive will use GenerateFiles to invoke
#                 a script (DebianPackager.pl) to actually do the hard work.
#
# Syntax        : MakeRpmPackage (<platforms>, Options+);
#                 Where Options may be one of:
#                   --Script=PackagerScript             - Mandatory. Name of a the packaging script
#                   --Name=Name                         - Redhat Package name(optional)
#                   --Variant=Text                      - Package Variant(optional)
#                   --DeployMode                        - Ignored
#                   --NoDeployMode                      - Ignored
#                                                         Default for embedded devices
#                   --NoArch                            - Marks the package as having no specific architecture
#                                                         
#                   --TarFile[=TemplateName]            - Create named .tgz file, of the data area [not Debian scripts]
#                   --TarFile                           - Same as --TarFile=PACKAGE_VERSION_PLATFORM_TYPE or PACKAGE_VERSION_PLATFORM
#                   --TarOnly                           - Suppress the Debian Build
#                   
#                   --ZipFile[=TemplateName]            - Create named .zip file, of the data area [not Debian scripts]
#                   --ZipFile                           - Same as --TarFile=PACKAGE_VERSION_PLATFORM_TYPE or PACKAGE_VERSION_PLATFORM
#                   --ZipOnly                           - Suppress the Debian Build
#
#               Templates may contain:
#                   PACKAGE
#                   VARIANT
#                   VERSION
#                   PLATFORM
#                   RELEASE
#                   TYPE
#                   ARCH
#                       
#......................................................................#

require 5.006_001;
#use strict;
use warnings;
#use PackagerUtils;

#-------------------------------------------------------------------------------
# Function        : MakeRpmPackage
#
# Description     : Create a Debian Package
#
# Inputs          : See above
#
# Returns         : Nothing 
#
sub MakeRpmPackage
{
    my( $platforms, @elements ) = @_;
    Debug2( "MakeRpmPackage($platforms, @elements)" );
    return if ( ! ActivePlatform($platforms) );

    my $build_name =  $::ScmBuildPackage;
    my $build_version = $::ScmBuildVersionFull;
    my $build_variant = '';

    my $name_set=0;
    my $variant_set=0;

    my $tarOnly;
    my $tarFileName = '';

    my $zipOnly;
    my $zipFileName = '';

    my @outputFiles;
    my @optArgs;
    my $noArch;

    my $script;

    #
    #   Collect user arguments
    #   They are all processed within the toolset
    #
    foreach ( @elements )
    {
        if ( m/^--Script=(.+)/i ) {
            ReportError ("MakeRpmPackage: --Script. RPM script name already set") if $script;
            $script = $1;

        } elsif ( m/^--RpmScript=(.+)/i ) {
            ReportError ("MakeDebianPackage: --RpmScript. RPM script name already set") if $script;
            $script = $1;
        } elsif ( m/^--Name=(.+)/i ) {
            $build_name = $1;
            $name_set++;

        } elsif ( m/^--Variant=(.+)/i ) {
            $build_variant = $1;
            $variant_set++;

        } elsif ( m/^--(No)?DeployMode/i ) {

        } elsif ( m/^--NoArch$/i ) {
            $noArch = 1;

        } elsif ( m/^--TarOnly$/i ) {
            $tarOnly = 1;

        } elsif ( m/^--TarFile(=(.*))?/i ) {
            $tarFileName = defined($1) ? $2 : 'DEFAULT';

        } elsif ( m/^--ZipOnly$/i ) {
            $zipOnly = 1;

        } elsif ( m/^--ZipFile(=(.*))?/i ) {
            $zipFileName = defined($1) ? $2 : 'DEFAULT';
            
        } elsif ( m/^--/ ) {
            ReportError("MakeRpmPackage. Unknown option: $_");

        } else {
            ReportError("MakeRpmPackage. Unknown argument: $_");
        }
    }

    #
    #   Sanity test
    #
    ReportError ("MakeRpmPackage: Not supported on a GENERIC target") if ( $ScmPlatform eq 'GENERIC' && !($zipOnly || $tarOnly )  );
    ReportError ("MakeRpmPackage: Script name not defined") unless ( $script );
    ReportError ("MakeRpmPackage: --Name option can only be used once") if ( $name_set > 1 );
    ReportError ("MakeRpmPackage: --Variant option can only be used once") if ( $variant_set > 1 );
    ErrorDoExit();

    #
    #   If the platform cannot generate a native installer then (silently) ignore the request
    #   unless the user has specified a --TarOnly
    #
    my $canGenerateInstaller = ActivePlatform('PKG_RPM');
    if ( !$canGenerateInstaller && !$tarOnly && !$zipOnly) {
        Verbose ("MakeRpmPackage: Installer not builadble for this platform");
        return;
    }

    #   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
    #

    $build_name = canonicalName ($build_name, 'RPM');

    #
    #   Sanity test the version information
    #   

    unless ( $::ScmBuildVersionFull =~ m/^[0-9][-+:.A-Za-z0-9]+$/ )
    {
        Error ("Package Version does not conform to RedHat Requirements",
               "Must only contain: (a-zA-Z) (0-9), _ and .",
               "Must start with a number",
               );
    }

    #
    #   Build up the build name
    #       Add variant to base name.
    #
    if ( $build_variant )
    {
        unless ( $build_variant =~ m/^[a-z[A-Z][_+a-zA-Z0-9]+$/ )
        {
            Error ("Build Variant does not conform to RedHat Requirements",
                   "Must be at least two characters long",
                   "Must start with an alphabetic character",
                   "Must only contain: (a-zA-Z) (0-9) and _",
                   "Provided Variant: $build_variant");
        }
        $build_name .= '-' . $build_variant;
    }

    #
    #   Create the name of the target package
    #   The form of the name is of a fixed form.
    #   Note: "-" used to join parts of the RedHat name
    #         name-version-release.architecture.rpm
    #
    #         release appears to be 'el7' - under RHEL7 and Centos
    #         Append P or D to it
    #
    my $PkgArch = GetGlobalOption('PACKAGE_ARCH', $::ScmPlatform);

    my $PkgRelease = GetGlobalOption('PACKAGE_RELEASE', '') . '$(GBE_TYPE)';
    push @optArgs, '-RpmRelease', $PkgRelease;

    if ($noArch)
    {
        $PkgArch = 'noarch';
        $PkgType = '';
        push @optArgs, "-NoArch";
    }
    my $PkgName = "${build_name}-${::ScmBuildVersionFull}-${PkgRelease}.${PkgArch}.rpm";
    push @optArgs, "-PkgArch=$PkgArch";
    unless ($tarOnly || $zipOnly) {
        push (@outputFiles, $PkgName);
        push @optArgs, "-Output=--GeneratedProg{$PkgName}";
    }

    #
    #   Create name for the optional TGZ file
    #       Allow user to specify parts of the name symbolically
    #
    if ($tarFileName)
    {
        if ($tarFileName eq 'DEFAULT')
        {
            $tarFileName = 'PACKAGE_VERSION_RELEASE.PLATFORM';
            if ($deploy_mode && ! $noArch)
            {
                $tarFileName .= '_TYPE';
            }
        }

        if ($noArch) {
            $PkgArch = 'all';
        }

        $tarFileName =~ s~PACKAGE~${build_name}~g;
        $tarFileName =~ s~VERSION~${::ScmBuildVersionFull}~g;
        $tarFileName =~ s~PLATFORM~${::ScmPlatform}~g;
        $tarFileName =~ s~ARCH~${PkgArch}~g;
        $tarFileName =~ s~TYPE~\$(GBE_TYPE)~;
        $tarFileName =~ s~RELEASE~${PkgRelease}~g;
        $tarFileName .= '.tgz' unless $tarFileName =~ m~\.tgz$~;
        push @outputFiles,  $tarFileName;

        push @optArgs, "-TarFile=--GeneratedProg{$tarFileName}";
#        push @optArgs, "-TarFile=$tarFileName";
        push (@optArgs, '-TarOnly' ) if $tarOnly;
    }

    #
    #   Create name for the optional ZIP file
    #       Allow user to specify parts of the name symbolically
    #
    if ($zipFileName) {
        if ($zipFileName eq 'DEFAULT') {
            $zipFileName = 'PACKAGE_VERSION_RELEASE.PLATFORM';
            if ($deploy_mode && ! $noArch) {
                $zipFileName .= '_TYPE';
            }
        }

        if ($noArch) {
            $PkgArch = 'all';
        }

        $zipFileName =~ s~PACKAGE~${build_name}~g;
        $zipFileName =~ s~VERSION~${::ScmBuildVersionFull}~g;
        $zipFileName =~ s~PLATFORM~${::ScmPlatform}~g;
        $zipFileName =~ s~ARCH~${PkgArch}~g;
        $zipFileName =~ s~TYPE~\$(GBE_TYPE)~;
        $zipFileName =~ s~RELEASE~${PkgRelease}~g;
        $zipFileName .= '.zip' unless $zipFileName =~ m~\.zip$~;
        push @outputFiles,  $zipFileName;

        push @optArgs, "-ZipFile=--GeneratedProg{$zipFileName}";
#        push @optArgs, "-TarFile=$zipFileName";
        push (@optArgs, '-ZipOnly' ) if $zipOnly;
    }

    #
    #   Simply use Generate Files
    #       With lots of options
    #
    Src ( '*', $script );
    GenerateFiles ('*', "--Tool=DebianPackager.pl",               # Associated tool
                        "--AutoGenerate",                         # Build when needed
                        "--UnknownPreq",                          # Always build
                        "--Clean",                                # Script supports jats clean
                        "--Text=RPM Package",                     # Display when building
                        
                        '--Var(BuildName)',                       # Target Package
                        '--Var(BuildVersion)',                    # Target Version
                        '--Var(Platform)',                        # Target platform
                        '--Var(Product)',                         # Target product
                        '--Var(Target)',                          # Underlying Target
                        '--Var(Type)',                            # Build Type

                        '--Var(Verbose)',                         # Verbose operation

                        '--Var(InterfaceDir)',                    # Interface Directory
                        '--Var(InterfaceIncDir)',
                        '--Var(InterfaceLibDir)',
                        '--Var(InterfaceBinDir)',

                        '--Var(LibDir)',                          # My Artifacts
                        '--Var(BinDir)',

                        '--Var(PackageDir)',                      # My Package
                        '--Var(PackageLibDir)',                   # My Package Library
                        '--Var(PackageBinDir)',                   # My Package Bin
                        '--Var(PackagePkgDir)',                   # My Package/pkg.target

                        '--Var(LocalIncDir)',                     # Installed Artifacts
                        '--Var(LocalLibDir)',
                        '--Var(LocalBinDir)',

                        "-genRpm",                                # Type to generate
                        "-Script=--Prerequisite($script)",        # Packager script
                        "-Name=$build_name",                      # Massaged Package Name
                        "-Version=$build_version",                # Massaged Version
                        "-Variant=$build_variant",                # Variant Name
                        @optArgs,                                 # Optional args
                        );

    #
    #   The Packager has created a binary in the 'PROG' directory
    #   Lets package it as a program.
    #
    PackageFile ('*', @outputFiles );
}

1;