Rev 5710 | 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 : Walk compete dependency tree for a given package version# Generate a build order# Generate build directives## Usage:## Version Who Date Description##......................................................................#require 5.006_001;use strict;use warnings;use JatsError;use JatsSystem;use Getopt::Long;use Pod::Usage; # required for help supportuse JatsRmApi;use DBI;my $VERSION = "1.2.3"; # Update thismy $opt_verbose = 1;my $opt_help = 0;my $opt_manual;my $opt_rtag_id = 2641; # NZSmy $opt_no_ver = 0;my $RM_DB;## Package information#my %Package;my @StrayPackages;#-------------------------------------------------------------------------------# Function : Main Entry## Description :## Inputs :## Returns :#my $result = GetOptions ("help+" => \$opt_help, # flag, multiple use allowed"manual" => \$opt_manual, # flag"verbose+" => \$opt_verbose, # flag);## Process help and manual options#pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);pod2usage(-verbose => 1) if ($opt_help == 2 );pod2usage(-verbose => 2) if ($opt_manual || ($opt_help > 2));ErrorConfig( 'name' =>'PLAY17' );## Determine root package#unless ( $ARGV[0] && $ARGV[1] ){print "Specify a package as 'name' 'version'\n";exit;}my $pv_id = getPkgDetailsByName($ARGV[0], $ARGV[1]);GetDepends ( $pv_id, $ARGV[0], $ARGV[1] );#getPkgDetailsByRTAG_ID($opt_rtag_id);LocateStrays();BuildOrder();#DebugDumpData ("Package", \%Package );exit;sub getPkgDetailsByName{my ($pname, $pver) = @_;my $pv_id;my (@row);# if we are not or cannot connect then return 0 as we have not found anythingconnectRM( \$RM_DB);# First get details for a given package versionmy $m_sqlstr = "SELECT pv.PV_ID, pkg.PKG_NAME, pv.PKG_VERSION" ." FROM PACKAGE_VERSIONS pv, PACKAGES pkg" ." WHERE pkg.PKG_NAME = \'$pname\' AND pv.PKG_VERSION = \'$pver\' AND pv.PKG_ID = pkg.PKG_ID";my $sth = $RM_DB->prepare($m_sqlstr);if ( defined($sth) ){if ( $sth->execute( ) ){if ( $sth->rows ){while ( @row = $sth->fetchrow_array ){$pv_id = $row[0];my $name = $row[1];my $ver = $row[2];Verbose( "PV_ID= $pv_id");}}$sth->finish();}}else{Error("Prepare failure" );}return $pv_id;}sub getPkgDetailsByRTAG_ID{my ($RTAG_ID) = @_;my $foundDetails = 0;my (@row);# if we are not or cannot connect then return 0 as we have not found anythingconnectRM( \$RM_DB);# First get details from pv_idmy $m_sqlstr = "SELECT pv.PV_ID, pkg.PKG_NAME, pv.PKG_VERSION, pv.PKG_LABEL, pv.SRC_PATH, pv.BUILD_TYPE, pv.IS_DEPLOYABLE, rc.BASE_VIEW_ID" ." FROM RELEASE_CONTENT rc, PACKAGE_VERSIONS pv, PACKAGES pkg" ." WHERE rc.RTAG_ID = $RTAG_ID AND rc.PV_ID = pv.PV_ID AND pv.PKG_ID = pkg.PKG_ID";my $sth = $RM_DB->prepare($m_sqlstr);if ( defined($sth) ){if ( $sth->execute( ) ){if ( $sth->rows ){while ( @row = $sth->fetchrow_array ){my $pv_id = $row[0];my $name = $row[1];my $ver = $row[2];my $label = $row[3] || '';my $path = $row[4] || '';my $deployable = $row[6];my $base_id = $row[7] || '';if ($opt_no_ver){push @{$Package{$name}{'xxx'}{ver_list}}, $ver;$ver = 'xxx';}## Construct archive path#my $dpkg;foreach my $var ( 'GBE_DPKG', 'GBE_DPLY' ){my $pkg_dir="$ENV{$var}/${name}/${ver}";if ( -d $pkg_dir ){$dpkg = $pkg_dir;last;}}$path =~ tr~\\/~/~s;#print "$row[5] --";#printf ( "%40s %15s %50s %s\n", $name, $ver, $label, $path);#printf ( "copy e:\\%s\\%s .\n", $name, $ver, $label, $path);#print "$name $ver\n";#print "$name $ver, $dpkg\n";$Package{$name}{$ver}{done} = 1;$Package{$name}{$ver}{base} = 1;$Package{$name}{$ver}{base_id} = $base_id;$Package{$name}{$ver}{deployable} = 1 if ($deployable);$Package{$name}{$ver}{dpkg} = $dpkg if ($dpkg);$Package{$name}{$ver}{label} = $label;$Package{$name}{$ver}{path} = $path;GetDepends( $pv_id, $name, $ver );}}$sth->finish();}}else{Error("Prepare failure" );}}#-------------------------------------------------------------------------------# Function : GetDepends## Description : Extract the dependancies for a given package version## Inputs : $pvid## Returns :#sub GetDepends{my ($pv_id, $pname, $pver ) = @_;Message ("GetDepends: $pv_id, $pname, $pver");## Now extract the package dependacies#my $m_sqlstr = "SELECT pkg.PKG_NAME, pv.PKG_VERSION, pd.DPV_ID, pv.IS_DEPLOYABLE" ." FROM PACKAGE_DEPENDENCIES pd, PACKAGE_VERSIONS pv, PACKAGES pkg" ." WHERE pd.PV_ID = \'$pv_id\' AND pd.DPV_ID = pv.PV_ID AND pv.PKG_ID = pkg.PKG_ID";my $sth = $RM_DB->prepare($m_sqlstr);if ( defined($sth) ){if ( $sth->execute( ) ){if ( $sth->rows ){my %depends;while ( my @row = $sth->fetchrow_array ){# print "$name ===== @row\n";my $name = $row[0];my $ver = $row[1];my $deployable = $row[3];Message (" $name, $ver");if ($opt_no_ver){push @{$Package{$name}{'xxx'}{ver_list}}, $ver;$ver = 'xxx';}$depends{$name,$ver} = 1;push @{$Package{$name}{$ver}{usedby}}, [ $pname, $pver ];unless ( exists $Package{$name}{$ver}{done} ){$Package{$name}{$ver}{needed} = 1;$Package{$name}{$ver}{deployable} = 1 if ($deployable);my @DATA = ($name, $ver, $row[2]);push @StrayPackages, \@DATA;}}$Package{$pname}{$pver}{depends} = \%depends;}$sth->finish();}}else{Error("GetDepends:Prepare failure" );}}#-------------------------------------------------------------------------------# Function : LocateStrays## Description :## Inputs :## Returns :#sub LocateStrays{while ( $#StrayPackages >= 0 ){my $DATA = pop @StrayPackages;my $name = $DATA->[0];my $ver = $DATA->[1];my $pv_id = $DATA->[2];next if ( exists $Package{$name}{$ver}{done} );GetDepends( $pv_id, $name, $ver );$Package{$name}{$ver}{done} = 1;$Package{$name}{$ver}{stray} = 1;}}#-------------------------------------------------------------------------------# Function : BuildOrder## Description : Determine the order to build packages## Inputs :## Returns :#sub BuildOrder{foreach my $name ( keys %Package ){foreach my $ver ( keys %{$Package{$name}} ){AddToBuildList( $name, $ver, $Package{$name}{$ver}{depends} );}}DetermineBuildOrder();}#-------------------------------------------------------------------------------# Function : AddToBuildList## Description : Add packages to a build list## Inputs : PackageName# PackageVersion# Hash of dependancies## Returns :#my %BuildList;sub AddToBuildList{my ($name, $ver, $pdepends ) = @_;print "Duplicate Package to build: $name, $ver\n" if exists $BuildList{$name,$ver};$BuildList{$name,$ver}{depends} = $pdepends;}#-------------------------------------------------------------------------------# Function : DetermineBuildOrder## Description : Determine the build order## Inputs :## Returns :#sub DetermineBuildOrder{# DebugDumpData ("BuildList", \%BuildList); exit 1;my $more = 1;my $level = 0;while ( $more ){my @build;$level ++;$more = 0;foreach my $key ( keys %BuildList ){## Locate packges with no dependencies left#next if ( keys %{$BuildList{$key}{depends}} );push @build, $key;}foreach my $build ( @build ){$more = 1;delete $BuildList{$build};my ($name, $ver) = split $;, $build;# next if ( exists $Package{$name}{$ver}{stray} );my $dpkg = $Package{$name}{$ver}{dpkg} || '';my $label = $Package{$name}{$ver}{label} || '';my $path = $Package{$name}{$ver}{path} || '';printf( "Build(%2d): %25s %15s %-40s %s\n", $level, $name, $ver, $label, $path);}## Delete dependencies#foreach my $key ( keys %BuildList ){foreach my $build ( @build ){delete $BuildList{$key}{depends}->{$build};}}}}