Subversion Repositories DevTools

Rev

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

########################################################################
# Copyright ( C ) 2007 ERG Limited, All rights reserved
#
# Module name   : jats.sh
# Module type   : Makefile system
# Compiler(s)   : n/a
# Environment(s): jats build system
#
# Description   : Provide access to information from the build.pl file as parsed
#                 by JATS. This is more complete than the parser in the
#                 "BuildFile.pm"
#
#                 The purpose of this module is to provide an interface
#                 between (essentially) internal data structures and user
#                 scripts that need to access the data. These are primarily
#                 deployment scripts.
#
#                 The 'All' tag is used for backward compatabilty. It simply
#                 exports all the known data structures. NOT to be used by new
#                 code.
#
#
#
# Interface     : ReadBuildConfig           - Initialise module
#                 getPlatformParts          - Get a list of Platform parts
#
#......................................................................#

require 5.006_001;
use strict;
use warnings;

#===============================================================================
package ReadBuildConfig;
use JatsError;
use JatsMakeInfo qw(:basic);

# automatically export what we need into namespace of caller.
use Exporter();
our (@ISA, @EXPORT, %EXPORT_TAGS, @EXPORT_OK);
@ISA         = qw(Exporter);
@EXPORT      = qw(  ReadBuildConfig
                    getPlatformParts
                    getPackagePaths
                );
@EXPORT_OK =  qw(   $InterfaceVersion
                    $ScmBuildMachType
                    $ScmInterfaceVersion
                    $ScmBuildName
                    $ScmBuildPackage
                    $ScmBuildVersion
                    $ScmBuildProject
                    $ScmBuildVersionFull
                    $ScmBuildPreviousVersion
                    $ScmSrcDir
                    $ScmLocal
                    $ScmDeploymentPatch
                    $ScmBuildSrc
                    $ScmExpert
                    $ScmAll
                    %ScmBuildAliases
                    %ScmBuildProducts
                    %ScmBuildPlatforms
                    %ScmBuildPkgRules
                    @BUILDPLATFORMS
                    @DEFBUILDPLATFORMS
                    @BUILDTOOLSPATH
                    %BUILDPLATFORM_PARTS
                    %BUILDINFO
                    %BUILD_KNOWNFILES
                );

%EXPORT_TAGS = (All => [@EXPORT, @EXPORT_OK]);

#-------------------------------------------------------------------------------
#   Global variables
#

my $interface;
my $platform;

#
#   The $InterfaceVersion value is manually maintained
#   The integer part should be changed to indicate a incompatible change
#   to the JATS files created within the interface directory
#
#   $InterfaceVersion is treated as a float. The fractional part can be
#   used to indicate minor changes to the file format.
#
our $InterfaceVersion       = "2.0";            # Change will issue error message

#
#   The following varaibles are "read" in from the build.cfg file
#   In order to access simply access we need to declare them
#
our %BUILDINFO;
our %BUILDPLATFORM_PARTS;
our $ScmInterfaceVersion;
our %ScmBuildPkgRules;
our $ScmBuildMachType;

#-------------------------------------------------------------------------------
# Function        : ReadBuildConfig
#
# Description     : Read in the build config information
#                   Read in build.cfg
#
# Inputs          : $interface              - Path to the interface directory
#                   $platform               - Platform being processed
#
# Returns         : Nothing
#
sub ReadBuildConfig
{
    $interface = shift;
    $platform = shift;

    my $no_test;
    foreach  ( @_ )
    {
        if ( m/^--NoTest/i ) {
            $no_test = 1;
        } else {
            Warning ("ReadBuildConfig, Unknown option: $_");
        }
    }

    Debug("BuildConfig::Reading config, $interface");
    my $cfgfile = "$interface/build.cfg";
    Error ("JATS internal file missing. Rebuild required",
           "BuildConfig: Cannot find file: $cfgfile" ) unless ( -f $cfgfile );

    #
    #   Include the build.cfg data
    #
    require ( $cfgfile );

    #
    #   Ensure that the version of the interface files can be consumed
    #   The $ScmInterfaceVersion is a written copy of $InterfaceVersion
    #
    #   Allow build.cfg files that do not have a ScmInterfaceVersion
    #   Assume that these are at version 1.0.
    #
    $ScmInterfaceVersion = '1.0' unless ( $ScmInterfaceVersion );
    Debug ("ReadBuildConfig: Version: $ScmInterfaceVersion, Need: $InterfaceVersion");
    if ( int($ScmInterfaceVersion) != int($InterfaceVersion)  )
    {
        Error ("JATS interface files are not compatible with this version of JATS",
               "Rebuild required.",
               "Current Interface Version: $ScmInterfaceVersion",
               "JATS Interface Version   : $InterfaceVersion" );
    }

    #
    #   Ensure that this config file is designed for this machine type
    #   At make-time this test may not be valid. It should have been
    #   validated before make-time.
    #
    TestMachType ($ScmBuildMachType, "build.cfg") unless $no_test;
    
    #
    #   Remove some unused data
    #   Reduces the size of Makefile.cfg. Speeds up writting
    #
    if ( $platform )
    {
        for (keys %::ScmBuildPlatforms)
        {
            next if ($_ eq $platform );
            delete ($::BUILDPLATFORM_PARTS{$_} );
            delete ($::BUILDINFO{$_} );
            delete ($::ScmBuildPkgRules{$_} );
        }
    }

    #   dump
    #
    Debug( "Aliases:" );
    if ( ! defined(%::ScmBuildAliases) ) {
        Debug( "  undefined" );

    } else {
        foreach my $key (keys %::ScmBuildAliases) {
            my( @value ) = split( ' ', $::ScmBuildAliases{ $key } );
            Debug( " $key\t= @value" );
        }
    }

    Debug( "Products:" );
    if ( ! defined(%::ScmBuildProducts) ) {
        Debug( "  undefined" );

    } else {
        foreach my $key (keys %::ScmBuildProducts) {
            my( @value ) = split( ',', $::ScmBuildProducts{ $key } );
            Debug( " $key\t= @value" );
        }
    }

    Debug( "Platforms:" );
    if ( ! defined(%::ScmBuildPlatforms) ) {
        Debug( "  undefined" );

    } else {
        foreach my $key (keys %::ScmBuildPlatforms) {
            my( @args ) = split( /$;/, $::ScmBuildPlatforms{ $key } );
            Debug( " $key\t= @args" );
        }
    }
}

#-------------------------------------------------------------------------------
# Function        : getPlatformParts
#
# Description     : return a list of platform parts
#
# Inputs          : None
#
# Returns         : A list of platform parts to search in the interface
#                   directory, local directory or other
#
sub getPlatformParts
{
    Error ("BuildConfig. Not initialised") unless ( $platform );
    return @{$BUILDINFO{$platform}{PARTS}};
}

#-------------------------------------------------------------------------------
# Function        : getPackagePaths
#
# Description     : Return a list of all packages
#                   LinkPkgarchive packages will be provided as is
#                   BuildPkgArchive packages will be provided as a single
#                   reference to the interface directory
#
# Inputs          : Options
#                       --Interface=xxxx            Path to the interface dir
#                                                   If provided, then the path
#                                                   will be used for the first
#                                                   BuildPkgArchive
#                       --All                       All paths
#                       --Tools                     All Tools Paths
#                       --Gbe                       All Gbe paths
#
# Returns         : An array of paths
#
sub getPackagePaths
{
    Error ("BuildConfig. Not initialised") unless ( $platform );

    my $interface;
    my $all;
    my $need;
    my @result;

    #
    #   Parse Options
    #
    foreach ( @_ )
    {
        if ( m~^--Interface=(.+)~ ) {
            $interface = $1;
        } elsif ( m~^--All~ ) {
            $all = 1;
        } elsif ( m~^--Tools~ ) {
            $need = 'TOOLDIRS';
        } elsif ( m~^--Gbe~ ) {
            $need = 'CFGDIR';
        } else {
            Error ("BuildConfig. Unknown Option: $_");
        }
    }

    #
    #   Locate rqeuired entries
    #
    for my $entry (@{$ScmBuildPkgRules{$platform} })
    {
        #
        #   Do we need this entry
        #   Select tools and gbe entries
        #
        my @subdirs = '/';
        if ( $need )
        {
            next unless ( exists ($entry->{$need} ) );
            my $subdir = $entry->{$need};
            if ( ref($subdir) eq 'ARRAY' ) {
                @subdirs = @{$subdir};
            } else {
                @subdirs = $subdir;
            }
        }

        #
        #   If a BuildPkgArchive, then give the interface dir, unless
        #   we need all the true paths
        #
        if ( ($entry->{'TYPE'} eq 'build' ) && !$all )
        {
            if ( $interface )
            {
                push @result, $interface;
                $interface = '';
            }
        }
        else
        {
            foreach my $subdir ( @subdirs )
            {
                my $dir = $entry->{'ROOT'} . $subdir;
                $dir =~ s~/+~/~g;
                $dir =~ s~/+$~~g;
                push @result, $dir;
            }
        }
    }

    return @result;
}

#------------------------------------------------------------------------------
1;