Rev 6177 | Blame | Compare with Previous | Last modification | View Log | RSS feed
######################################################################### COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.## Module name : jats_upddep.pl# Module type : Makefile system# Compiler(s) : Perl# Environment(s): jats## Description : Jats utility to Update Build File Dependencies## Usage : See below##......................................................................#require 5.008_002;use strict;use warnings;use Pod::Usage;use Getopt::Long;use JatsError;use JatsVersionUtils;use JatsRmApi;use JatsSystem;use Cwd;my $RM_DB;################################################################################# Global data#my $VERSION = "1.0.0";my %ReleasePackages; # Packages in the releasemy %BuildPackages; # Packages for this buildmy $ReleaseName;my $ProjectName;## Options#my $opt_help = 0;my $opt_verbose = 0;my $opt_rtagid;my $opt_show;my $opt_outfile;my $opt_keep;my $opt_zero;my $result = GetOptions ("help|h:+" => \$opt_help,"manual:3" => \$opt_help,"verbose:+" => \$opt_verbose,"rtagid|rtag_id=s" => \$opt_rtagid,"out=s" => \$opt_outfile,'show:s' => \$opt_show,'keep' => \$opt_keep,'zero!' => \$opt_zero,);## 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_help > 2);## Configure the error reporting process now that we have the user options#ErrorConfig( 'name' =>'UPDDEP','verbose' => $opt_verbose );## Allow some comand line options# -rtag_id=xxx# rtag_id=xxx#foreach ( @ARGV ){if ( m~^rtag_id=(.*)~ ) {$opt_rtagid = $1;} else {Error ("Unknown command line argument: $_");}}Error( "No operation specified" )unless ( $opt_rtagid || defined $opt_show || $opt_zero );## Intelligently select output file# Use auto.pl if it exists# use build.pl if auto.??? does not exist and its writable#unless ( $opt_outfile ){if ( -e 'auto.pl' ) {$opt_outfile = 'auto.pl';} elsif ( -e 'build.pl' && -w 'build.pl' ) {$opt_outfile = 'build.pl';} else {$opt_outfile = 'auto.pl';}}my $file;if ($opt_rtagid) {## Connect to the RM database# Uses infor from the JATS environment# GBE_RM_LOCATION# GBE_RM_USERNAME# GBE_RM_PASSWORD#connectRM(\$RM_DB);## Display all the Release Tags in the data base#if ( defined $opt_show ){show_rtags();exit (0);}## Ensure that the RTAG exists# Extract the Release and Project Name#GetReleaseData( $opt_rtagid );Error ("Rtag not found in Release Manager Database: $opt_rtagid") unless ( $ProjectName );Message ("Project Name: $ProjectName");Message ("Release Name: $ReleaseName");## Get all package info the specified release# This is done as one query so it should be fast#getPkgDetailsByRTAG_ID( $opt_rtagid );## Create a configuration file for use by the JATS rewrite tool# This will allow the build.pl file to be re-written#$file = "jats_rewrite.cfg";open CFG, ">$file" || Error("Cannot create $file", $! );print CFG "releasemanager.projectname = $ProjectName\n";print CFG "releasemanager.releasename = $ReleaseName\n";foreach my $pkg ( sort keys %ReleasePackages ){my $ver;foreach my $prj ( sort keys %{$ReleasePackages{$pkg}} ){$ver = $ReleasePackages{$pkg}{$prj};$ver .= '.' . ${prj} if ( $prj );print CFG "${pkg} ${ver}\n";}}close CFG;}## Massage the build.pl file to create the auto.pl file# That will be used to create the final package.#$result = JatsTool ("jats_rewrite.pl",defined ($file) ? ('-conf', $file) : '','-verb', $opt_verbose,'-outfile', $opt_outfile,'-mode=1',defined($opt_zero) ? '-zero' : '');if ( $file && !$opt_keep){unlink $file}Error("Did not rewrite build.pl file") if ( $result );exit 0;#-------------------------------------------------------------------------------# Function : GetReleaseData## Description : Determine the Release Name and associated project## Inputs : $rtag_id## Returns :#sub GetReleaseData{my ($RTAG_ID) = @_;my $foundDetails = 0;my (@row);# First get details from pv_idmy $m_sqlstr = "SELECT rt.RTAG_NAME, p.PROJ_NAME" ." FROM release_manager.RELEASE_TAGS rt, release_manager.PROJECTS p" ." WHERE rt.RTAG_ID = $RTAG_ID AND rt.PROJ_ID = p.PROJ_ID ";my $sth = $RM_DB->prepare($m_sqlstr);if ( defined($sth) ){if ( $sth->execute( ) ){if ( $sth->rows ){while ( @row = $sth->fetchrow_array ){# print "@row\n";($ReleaseName, $ProjectName) = @row;last;}}$sth->finish();}else{Error("Execute failure: GetReleaseData" );}}else{Error("Prepare failure: GetReleaseData" );}}#-------------------------------------------------------------------------------# Function : getPkgDetailsByRTAG_ID## Description :## Inputs : rtag_id## Returns : Populate %ReleasePackages#sub getPkgDetailsByRTAG_ID{my ($RTAG_ID) = @_;# First get details from pv_idmy $m_sqlstr = "SELECT pv.PV_ID, pkg.PKG_NAME, pv.PKG_VERSION" ." FROM RELEASE_MANAGER.RELEASE_CONTENT rc, RELEASE_MANAGER.PACKAGE_VERSIONS pv, RELEASE_MANAGER.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 ( my @row = $sth->fetchrow_array ){my $pv_id = $row[0];my $name = $row[1];my $ver = $row[2];# print "$name $ver\n";## Store data package name and package suffix#my ( $pn, $pv, $pp ) = SplitPackage( $name, $ver );$ReleasePackages{$pn}{$pp} = $pv;}}$sth->finish();}}else{Error("Prepare failure" );}}#-------------------------------------------------------------------------------# Function : show_rtags## Description : Display all RTAGS inthe data base## Inputs :## Returns :#sub show_rtags{my $foundDetails = 0;my (@row);$opt_show = quotemeta( $opt_show );# First get details from pv_idmy $m_sqlstr = "SELECT rt.RTAG_ID, p.PROJ_NAME, rt.RTAG_NAME" ." FROM release_manager.RELEASE_TAGS rt, release_manager.PROJECTS p" ." WHERE rt.PROJ_ID = p.PROJ_ID " ."AND rt.OFFICIAL != 'A' " ."AND rt.OFFICIAL != 'Y' " ." ORDER BY p.PROJ_NAME";my $sth = $RM_DB->prepare($m_sqlstr);if ( defined($sth) ){if ( $sth->execute( ) ){if ( $sth->rows ){while ( @row = $sth->fetchrow_array ){# print "@row\n";if ( $opt_show ){next unless ( "$row[1]$row[2]" =~ m/$opt_show/i );}printf ("%-6d: %s, %s\n", @row);$foundDetails = 1;}}$sth->finish();}else{Error("Execute failure: show_rtags" );}}else{Error("Prepare failure: show_rtags" );}Warning ("No Project or Release names Match: \"$opt_show\"")if ( $opt_show && ! $foundDetails );}#-------------------------------------------------------------------------------# Documentation#=pod=head1 NAMEjats upddep - Update Build File Dependencies=head1 SYNOPSISjats upddep [options]Options:-help - brief help message-help -help - Detailed help message-man - Full documentation-verbose - Verbose operation-show[=text] - Show all Release Tags, that match text-rtag=nnn - Release Tag-out=file - Output filename [auto.pl]-keep - Keep the generated dependency files-zero - Zero version numbers=head1 OPTIONS=over 8=item B<-help>Print a brief help message and exits.=item B<-help -help>Print a detailed help message with an explanation for each option.=item B<-man>Prints the manual page and exits.=item B<-verbose>Increases program output. This option may be specified multiple times=item B<-show[=text]>This option will case the utility to list all the Release Tags in the ReleaseManager database. It may be used to simplify the selection of the correct tag.If B<text> is provided, then it will be used to limit the list of tags shown.Closed and Archived Releases are not shown. The tool can still be used to updatethe build files against such releases, but the Release Tag must be determinedfrom Release Manager.=item B<-rtag=nnn> also -rtag_id=nn or -rtagid=nnThis option specifies the Release, within the Release Manager Database, that willbe used to update the build dependency file.The Release Tag is provided by the Release Manager Web Page, or by the -Show optionof this utility.=item B<-out=file>This option specifies the name of the output file in which the modified buildinformation will be placed. The utility will use 'auto.pl' unless there isno 'auto.pl' file and the 'build.pl' exists and is writable.=item B<-keep>This option will prevent the utility from deleting the generated dependency file.=item B<-zero>This option will update version numbers to 0.0.0000. It will still provide sanitytesting of the package dependencies against the Release Manager entry is provided.=back=head1 DESCRIPTIONThis utilty will update the dependency information within a build file toreflect the desired package-versions within a specified release.The intent of this utility is to simplify the process of package development byautomating the maintenance of a packages dependencies.The utility will:=over 8=item *Contact the Release Manager Database.The credentials are provided via JATS environment variables. JATS must becorrectly configured in order for this to work.=item *Locate the Release as specified by the Release TagThe name of the Release and the containing Project will be displayed.=item *Extract all package-versions within the ReleaseThe information is then written to a file called jats_rewrite.cfg. If the file isleft in place by the utility, with the '-keep' option, then it may be deletedand must not be committed to version control.=item *Invoke the 'jats rewrite' utility to create or modify the build files.Only the package dependencies are modified. The package version itself is not modified.=backThis utility will use either the build.pl or auto.pl file as a template forupdating version numbers. The tool will not add or remove packages from thebuild file nor will it modify the project suffix on a package.The 'auto.pl' file will be used if it exists and it has a more recent timestampthan the build.pl file. This allows a developer to modify either file withoutfear of losing the changes.=head1 EXAMPLEThe following command will update the build.pl file in the current directory sothat the dependecies match those from the Release with an rtag_id of 25423.jats upddep -rtag_id=25423The following command will zero the version numbersjats upddep -zero=cut