| 392 |
dpurdie |
1 |
#! perl
|
|
|
2 |
########################################################################
|
|
|
3 |
# Copyright ( C ) 2004 ERG Limited, All rights reserved
|
|
|
4 |
#
|
|
|
5 |
# Module name : jats.sh
|
|
|
6 |
# Module type : Makefile system
|
|
|
7 |
# Compiler(s) : n/a
|
|
|
8 |
# Environment(s): jats
|
|
|
9 |
#
|
|
|
10 |
# Description : Proto type for package ripple
|
|
|
11 |
# Needs CWD = sandbox with build.pl
|
|
|
12 |
# Needs command - package name and version
|
|
|
13 |
# Assumes Sydney Release-1 as an RTAG_ID
|
|
|
14 |
#
|
|
|
15 |
# Will create an auto.pl file
|
|
|
16 |
#
|
|
|
17 |
# Usage:
|
|
|
18 |
#
|
|
|
19 |
# Version Who Date Description
|
|
|
20 |
#
|
|
|
21 |
#......................................................................#
|
|
|
22 |
|
|
|
23 |
require 5.006_001;
|
|
|
24 |
use strict;
|
|
|
25 |
use warnings;
|
|
|
26 |
use JatsError;
|
|
|
27 |
use JatsVersionUtils;
|
|
|
28 |
use JatsRmApi;
|
|
|
29 |
|
|
|
30 |
#use Data::Dumper;
|
|
|
31 |
use Cwd;
|
|
|
32 |
use DBI;
|
|
|
33 |
use Getopt::Long;
|
|
|
34 |
use Pod::Usage; # required for help support
|
|
|
35 |
|
|
|
36 |
my $GBE_PERL = $ENV{'GBE_PERL'}; # Essential ENV variables
|
|
|
37 |
my $GBE_CORE = $ENV{'GBE_CORE'};
|
|
|
38 |
my $RM_DB;
|
|
|
39 |
|
|
|
40 |
################################################################################
|
|
|
41 |
# Global data
|
|
|
42 |
#
|
|
|
43 |
my $VERSION = "1.0.0";
|
|
|
44 |
my %ReleasePackages; # Packages in the release
|
|
|
45 |
my %BuildPackages; # Packages for this build
|
|
|
46 |
my $base_name;
|
|
|
47 |
my $base_version;
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
#
|
|
|
51 |
# Options
|
|
|
52 |
#
|
|
|
53 |
my $opt_help = 0;
|
|
|
54 |
my $opt_manual = 0;
|
|
|
55 |
my $opt_verbose = 0;
|
|
|
56 |
|
|
|
57 |
my $result = GetOptions (
|
|
|
58 |
"help+" => \$opt_help, # flag, multiple use allowed
|
|
|
59 |
"manual" => \$opt_manual, # flag
|
|
|
60 |
"verbose+" => \$opt_verbose, # flag
|
|
|
61 |
);
|
|
|
62 |
|
|
|
63 |
#
|
|
|
64 |
# Process help and manual options
|
|
|
65 |
#
|
|
|
66 |
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
|
|
|
67 |
pod2usage(-verbose => 1) if ($opt_help == 2 );
|
|
|
68 |
pod2usage(-verbose => 2) if ($opt_manual || ($opt_help > 2));
|
|
|
69 |
|
|
|
70 |
#
|
|
|
71 |
# Configure the error reporting process now that we have the user options
|
|
|
72 |
#
|
|
|
73 |
ErrorConfig( 'name' =>'PLAY6',
|
|
|
74 |
'verbose' => $opt_verbose );
|
|
|
75 |
|
|
|
76 |
unless ( $ARGV[0] && $ARGV[1] )
|
|
|
77 |
{
|
|
|
78 |
Error( "Specify a package as 'name' 'version'" );
|
|
|
79 |
}
|
|
|
80 |
$base_name = $ARGV[0];
|
|
|
81 |
$base_version = $ARGV[1];
|
|
|
82 |
Verbose( "Base Package: $base_name, $base_version");
|
|
|
83 |
|
|
|
84 |
#
|
|
|
85 |
# Create a hash of all the packages in the current release
|
|
|
86 |
# Need this generate basis for WIP labels
|
|
|
87 |
# Need this to create current versions
|
|
|
88 |
#
|
|
|
89 |
#getPkgDetailsByRTAG_ID ( 2362 ); # Sydney Release-1
|
|
|
90 |
getPkgDetailsByRTAG_ID ( 2301 ); # Seattle I7
|
|
|
91 |
#getPkgDetailsByRTAG_ID ( 2102 ); # Sydney Future
|
|
|
92 |
#getPkgDetailsByRTAG_ID ( 1861 ); # Sydney Legacy
|
|
|
93 |
|
|
|
94 |
#
|
|
|
95 |
# Assume that we need to ripple the current build version
|
|
|
96 |
# Generate a new build version. The package may be a WIP
|
|
|
97 |
#
|
|
|
98 |
my ($pkg_name, $pkg_ver, $pkg_proj ) = NextBuildVersion( $base_name, $base_version ,'r' );
|
|
|
99 |
|
|
|
100 |
#
|
|
|
101 |
# Body of the process
|
|
|
102 |
#
|
|
|
103 |
GetDepends ( $base_name, $base_version );
|
|
|
104 |
|
|
|
105 |
#
|
|
|
106 |
# Create a configuration file for use by the JATS rewrite tool
|
|
|
107 |
# This will allow the build.pl file to be re-written
|
|
|
108 |
#
|
|
|
109 |
my $file = "jats_rewrite.cfg";
|
|
|
110 |
open CFG, ">$file" || Error("Cannot create $file" );
|
|
|
111 |
print CFG "${pkg_name} ${pkg_ver}.${pkg_proj}\n";
|
|
|
112 |
|
|
|
113 |
foreach my $pkg ( keys %BuildPackages )
|
|
|
114 |
{
|
|
|
115 |
foreach my $prj ( keys %{$BuildPackages{$pkg}} )
|
|
|
116 |
{
|
|
|
117 |
my $ver = $BuildPackages{$pkg}{$prj};
|
|
|
118 |
print CFG "${pkg} ${ver}.${prj}\n";
|
|
|
119 |
}
|
|
|
120 |
}
|
|
|
121 |
close CFG;
|
|
|
122 |
|
|
|
123 |
#
|
|
|
124 |
# Massage the build.pl file to create the auto.pl file
|
|
|
125 |
# That will be used to create the final package.
|
|
|
126 |
#
|
|
|
127 |
JatsTool ("jats_rewrite.pl", "-conf", "$file", "-verb" ) && Error("Did not rewrite build.pl file");
|
|
|
128 |
|
|
|
129 |
exit 0;
|
|
|
130 |
|
|
|
131 |
#-------------------------------------------------------------------------------
|
|
|
132 |
# Function : NextBuildVersion
|
|
|
133 |
#
|
|
|
134 |
# Description : Determine the next build version number
|
|
|
135 |
# Assume this is a SIMPLE ripple build
|
|
|
136 |
#
|
|
|
137 |
# Inputs : pkg_name
|
|
|
138 |
# pkg_ver
|
|
|
139 |
# type - M,m,p,r
|
|
|
140 |
# Major, Minor, Patch or Ripple
|
|
|
141 |
#
|
|
|
142 |
# Returns :
|
|
|
143 |
#
|
|
|
144 |
sub NextBuildVersion
|
|
|
145 |
{
|
|
|
146 |
my ( $name, $ver, $type ) = @_;
|
|
|
147 |
|
|
|
148 |
#
|
|
|
149 |
# Extract the version number from the project name
|
|
|
150 |
#
|
|
|
151 |
my ( $pn, $pv, $pp ) = SplitPackage( $name, $ver );
|
|
|
152 |
if ( $pv eq 'WIP' )
|
|
|
153 |
{
|
|
|
154 |
($pv) = keys %{$ReleasePackages{$pn}{$pp}};
|
|
|
155 |
Error ("Cannot determine current version for package", "$name $ver" ) unless ( $pv );
|
|
|
156 |
|
|
|
157 |
$type = GetWipChangeType($name, $ver);
|
|
|
158 |
Error ("Cannot determine WIP change Type", "$name $ver" ) unless ( $type );
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
#
|
|
|
162 |
# Create a hash of existing versions for the required package
|
|
|
163 |
# These will be used to assist in determing the next version number
|
|
|
164 |
#
|
|
|
165 |
my $versions = GetPackageVersions( $name );
|
|
|
166 |
$versions = $versions->{$pp};
|
|
|
167 |
|
|
|
168 |
#
|
|
|
169 |
# Scan the versions and create a hash to assist in determing if a version
|
|
|
170 |
# already exists.
|
|
|
171 |
# Key it by MAJOR, MINOR, PATCH
|
|
|
172 |
#
|
|
|
173 |
my %vhash;
|
|
|
174 |
foreach ( @{$versions} )
|
|
|
175 |
{
|
|
|
176 |
next if ( m/WIP/i );
|
|
|
177 |
my ($major, $minor, $patch, $build ) = SplitVersion( $_ );
|
|
|
178 |
$vhash{$major}{$minor}{$patch}{$build} = 1;
|
|
|
179 |
}
|
|
|
180 |
# DebugDumpData ("VVVV", \%vhash );
|
|
|
181 |
|
|
|
182 |
#
|
|
|
183 |
# Extract the major, minor, patch and build number
|
|
|
184 |
#
|
|
|
185 |
my ($major, $minor, $patch, $build ) = SplitVersion( $pv );
|
|
|
186 |
|
|
|
187 |
#print "Base: $major, $minor, $patch, $build, Type: $type\n";
|
|
|
188 |
my $done = 0;
|
|
|
189 |
while ( !$done )
|
|
|
190 |
{
|
|
|
191 |
#
|
|
|
192 |
# Bump the reqired part of the version number
|
|
|
193 |
#
|
|
|
194 |
if ( $type eq 'M' ) {
|
|
|
195 |
$major++;
|
|
|
196 |
next if ( exists $vhash{$major} );
|
|
|
197 |
$minor = 0;
|
|
|
198 |
$patch = 0;
|
|
|
199 |
$build = 0;
|
|
|
200 |
|
|
|
201 |
} elsif ( $type eq 'm' || $type eq 'N' ) {
|
|
|
202 |
$minor++;
|
|
|
203 |
next if ( exists $vhash{$major}{$minor} );
|
|
|
204 |
$patch = 0;
|
|
|
205 |
$build = 0;
|
|
|
206 |
|
|
|
207 |
} elsif ( $type eq 'p' || $type eq 'P' ) {
|
|
|
208 |
$patch++;
|
|
|
209 |
next if ( exists $vhash{$major}{$minor}{$patch} );
|
|
|
210 |
$build = 0;
|
|
|
211 |
} else {
|
|
|
212 |
$build++;
|
|
|
213 |
next if ( exists $vhash{$major}{$minor}{$patch}{$build} );
|
|
|
214 |
}
|
|
|
215 |
$done = 1;
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
#
|
|
|
219 |
# Build number retains its 3 character extension
|
|
|
220 |
#
|
|
|
221 |
Error ("Build number is too big: $build" )
|
|
|
222 |
if ( $build >= 999 );
|
|
|
223 |
$build = sprintf( "%-03.3d", $build );
|
|
|
224 |
|
|
|
225 |
|
|
|
226 |
#
|
|
|
227 |
# Join them back again
|
|
|
228 |
#
|
|
|
229 |
print "NextBuildVersion: $name, $ver ==> ${name}_$major.$minor.${patch}${build}.$pp\n";
|
|
|
230 |
return ( $name, "$major.$minor.${patch}${build}", $pp );
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
#-------------------------------------------------------------------------------
|
|
|
234 |
# Function : GetWipChangeType
|
|
|
235 |
#
|
|
|
236 |
# Description : The current data is a WIP
|
|
|
237 |
# Determine the true type of the change requested
|
|
|
238 |
#
|
|
|
239 |
# Inputs : pkg_name
|
|
|
240 |
# pkg_ver
|
|
|
241 |
#
|
|
|
242 |
# Returns :
|
|
|
243 |
#
|
|
|
244 |
sub GetWipChangeType
|
|
|
245 |
{
|
|
|
246 |
my ( $pkg_name, $pkg_ver ) = @_;
|
|
|
247 |
my (@row);
|
|
|
248 |
my $pv_id;
|
|
|
249 |
my $change_type;
|
|
|
250 |
|
|
|
251 |
# if we are not or cannot connect then return 0 as we have not found anything
|
|
|
252 |
connectRM(\$RM_DB) unless ( $RM_DB );
|
|
|
253 |
|
|
|
254 |
#
|
|
|
255 |
# First determine the PV_ID for the specified version of the package
|
|
|
256 |
#
|
|
|
257 |
my $m_sqlstr = "SELECT pkg.PKG_NAME, pkg.PKG_ID, pv.PKG_VERSION, pv.PV_ID, pv.CHANGE_TYPE FROM PACKAGES pkg, PACKAGE_VERSIONS pv WHERE pkg.PKG_NAME = \'$pkg_name\' AND pkg.PKG_ID = pv.PKG_ID AND pv.PKG_VERSION = \'$pkg_ver\'";
|
|
|
258 |
my $sth = $RM_DB->prepare($m_sqlstr);
|
|
|
259 |
if ( defined($sth) )
|
|
|
260 |
{
|
|
|
261 |
if ( $sth->execute( ) )
|
|
|
262 |
{
|
|
|
263 |
if ( $sth->rows )
|
|
|
264 |
{
|
|
|
265 |
while ( @row = $sth->fetchrow_array )
|
|
|
266 |
{
|
|
|
267 |
$pv_id = $row[3];
|
|
|
268 |
$change_type = $row[4];
|
|
|
269 |
last;
|
|
|
270 |
}
|
|
|
271 |
}
|
|
|
272 |
$sth->finish();
|
|
|
273 |
}
|
|
|
274 |
}
|
|
|
275 |
else
|
|
|
276 |
{
|
|
|
277 |
Error("GetDepends:Prepare failure" );
|
|
|
278 |
}
|
|
|
279 |
|
|
|
280 |
return $change_type;
|
|
|
281 |
}
|
|
|
282 |
|
|
|
283 |
#-------------------------------------------------------------------------------
|
|
|
284 |
# Function : GetPackageVersions
|
|
|
285 |
#
|
|
|
286 |
# Description : Get a hash of package versions for the named package
|
|
|
287 |
#
|
|
|
288 |
# Inputs : $name - Package name
|
|
|
289 |
#
|
|
|
290 |
# Returns :
|
|
|
291 |
#
|
|
|
292 |
sub GetPackageVersions
|
|
|
293 |
{
|
|
|
294 |
my ($name ) = @_;
|
|
|
295 |
|
|
|
296 |
my $foundDetails = 0;
|
|
|
297 |
my (@row);
|
|
|
298 |
my %versions;
|
|
|
299 |
|
|
|
300 |
# if we are not or cannot connect then return 0 as we have not found anything
|
|
|
301 |
connectRM(\$RM_DB) unless ( $RM_DB );
|
|
|
302 |
|
|
|
303 |
#
|
|
|
304 |
# Determine all versions of the named package
|
|
|
305 |
#
|
|
|
306 |
|
|
|
307 |
my $m_sqlstr = "SELECT pkg.PKG_NAME, pkg.PKG_ID, pv.PKG_VERSION FROM PACKAGES pkg, PACKAGE_VERSIONS pv WHERE pkg.PKG_NAME = \'$name\' AND pkg.PKG_ID = pv.PKG_ID";
|
|
|
308 |
my $sth = $RM_DB->prepare($m_sqlstr);
|
|
|
309 |
if ( defined($sth) )
|
|
|
310 |
{
|
|
|
311 |
if ( $sth->execute( ) )
|
|
|
312 |
{
|
|
|
313 |
if ( $sth->rows )
|
|
|
314 |
{
|
|
|
315 |
while ( @row = $sth->fetchrow_array )
|
|
|
316 |
{
|
|
|
317 |
my $id = $row[1];
|
|
|
318 |
my ( $name, $ver, $proj ) = SplitPackage( $row[0], $row[2] );
|
|
|
319 |
push @{$versions{$proj}}, $ver;
|
|
|
320 |
}
|
|
|
321 |
}
|
|
|
322 |
$sth->finish();
|
|
|
323 |
}
|
|
|
324 |
}
|
|
|
325 |
else
|
|
|
326 |
{
|
|
|
327 |
Error("GetPackageVersions:Prepare failure" );
|
|
|
328 |
}
|
|
|
329 |
|
|
|
330 |
# DebugDumpData("Versions", \%versions );
|
|
|
331 |
return \%versions;
|
|
|
332 |
}
|
|
|
333 |
|
|
|
334 |
|
|
|
335 |
#-------------------------------------------------------------------------------
|
|
|
336 |
# Function : GetDepends
|
|
|
337 |
#
|
|
|
338 |
# Description :
|
|
|
339 |
#
|
|
|
340 |
# Inputs : pkg_name
|
|
|
341 |
# pkg_ver
|
|
|
342 |
#
|
|
|
343 |
# Returns :
|
|
|
344 |
#
|
|
|
345 |
sub GetDepends
|
|
|
346 |
{
|
|
|
347 |
my ( $pkg_name, $pkg_ver ) = @_;
|
|
|
348 |
my (@row);
|
|
|
349 |
my $pv_id;
|
|
|
350 |
|
|
|
351 |
# if we are not or cannot connect then return 0 as we have not found anything
|
|
|
352 |
connectRM(\$RM_DB) unless ( $RM_DB );
|
|
|
353 |
|
|
|
354 |
#
|
|
|
355 |
# First determine the PV_ID for the specified version of the package
|
|
|
356 |
#
|
|
|
357 |
my $m_sqlstr = "SELECT pkg.PKG_NAME, pkg.PKG_ID, pv.PKG_VERSION, pv.PV_ID FROM PACKAGES pkg, PACKAGE_VERSIONS pv WHERE pkg.PKG_NAME = \'$pkg_name\' AND pkg.PKG_ID = pv.PKG_ID AND pv.PKG_VERSION = \'$pkg_ver\'";
|
|
|
358 |
my $sth = $RM_DB->prepare($m_sqlstr);
|
|
|
359 |
if ( defined($sth) )
|
|
|
360 |
{
|
|
|
361 |
if ( $sth->execute( ) )
|
|
|
362 |
{
|
|
|
363 |
if ( $sth->rows )
|
|
|
364 |
{
|
|
|
365 |
while ( @row = $sth->fetchrow_array )
|
|
|
366 |
{
|
|
|
367 |
$pv_id = $row[3];
|
|
|
368 |
last;
|
|
|
369 |
}
|
|
|
370 |
}
|
|
|
371 |
$sth->finish();
|
|
|
372 |
}
|
|
|
373 |
}
|
|
|
374 |
else
|
|
|
375 |
{
|
|
|
376 |
Error("GetDepends:Prepare failure" );
|
|
|
377 |
}
|
|
|
378 |
|
|
|
379 |
Error ("GetDepends: PV_ID not located") unless ( $pv_id );
|
|
|
380 |
|
|
|
381 |
#
|
|
|
382 |
# Noew extract the package dependacies
|
|
|
383 |
#
|
|
|
384 |
$m_sqlstr = "SELECT pkg.PKG_NAME, pv.PKG_VERSION 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";
|
|
|
385 |
$sth = $RM_DB->prepare($m_sqlstr);
|
|
|
386 |
if ( defined($sth) )
|
|
|
387 |
{
|
|
|
388 |
if ( $sth->execute( ) )
|
|
|
389 |
{
|
|
|
390 |
if ( $sth->rows )
|
|
|
391 |
{
|
|
|
392 |
while ( @row = $sth->fetchrow_array )
|
|
|
393 |
{
|
|
|
394 |
my ( $pn, $pv, $pp ) = SplitPackage( $row[0], $row[1] );
|
|
|
395 |
my ($rp) = keys %{$ReleasePackages{$pn}{$pp}};
|
|
|
396 |
|
|
|
397 |
$BuildPackages{$pn}{$pp} = $rp;
|
|
|
398 |
|
|
|
399 |
# print ' ' x 4, "$pn $pv $pp";
|
|
|
400 |
# if ( $rp ne $pv )
|
|
|
401 |
# {
|
|
|
402 |
# print " ----- Package not in release. Needs $rp";
|
|
|
403 |
# }
|
|
|
404 |
# print "\n";
|
|
|
405 |
}
|
|
|
406 |
}
|
|
|
407 |
$sth->finish();
|
|
|
408 |
}
|
|
|
409 |
}
|
|
|
410 |
else
|
|
|
411 |
{
|
|
|
412 |
Error("GetDepends:Prepare failure" );
|
|
|
413 |
}
|
|
|
414 |
}
|
|
|
415 |
|
|
|
416 |
#-------------------------------------------------------------------------------
|
|
|
417 |
# Function : getPkgDetailsByRTAG_ID
|
|
|
418 |
#
|
|
|
419 |
# Description : Build up a structure for all the currently released
|
|
|
420 |
# packages in a given release
|
|
|
421 |
#
|
|
|
422 |
# Inputs : rtag_id
|
|
|
423 |
#
|
|
|
424 |
# Returns : Hash
|
|
|
425 |
#
|
|
|
426 |
|
|
|
427 |
sub getPkgDetailsByRTAG_ID
|
|
|
428 |
{
|
|
|
429 |
my ($RTAG_ID) = @_;
|
|
|
430 |
my $foundDetails = 0;
|
|
|
431 |
my (@row);
|
|
|
432 |
|
|
|
433 |
# if we are not or cannot connect then return 0 as we have not found anything
|
|
|
434 |
connectRM(\$RM_DB) unless ( $RM_DB );
|
|
|
435 |
|
|
|
436 |
# First get details from pv_id
|
|
|
437 |
|
|
|
438 |
my $m_sqlstr = "SELECT pv.PV_ID, pkg.PKG_NAME, pv.PKG_VERSION 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";
|
|
|
439 |
my $sth = $RM_DB->prepare($m_sqlstr);
|
|
|
440 |
if ( defined($sth) )
|
|
|
441 |
{
|
|
|
442 |
if ( $sth->execute( ) )
|
|
|
443 |
{
|
|
|
444 |
if ( $sth->rows )
|
|
|
445 |
{
|
|
|
446 |
while ( @row = $sth->fetchrow_array )
|
|
|
447 |
{
|
|
|
448 |
my $pv_id = $row[0];
|
|
|
449 |
my $name = $row[1];
|
|
|
450 |
my $version = $row[2];
|
|
|
451 |
|
|
|
452 |
my ( $pn, $pv, $pp ) = SplitPackage( $name, $version );
|
|
|
453 |
$ReleasePackages{$pn}{$pp}{$pv} = $pv_id;
|
|
|
454 |
}
|
|
|
455 |
}
|
|
|
456 |
$sth->finish();
|
|
|
457 |
}
|
|
|
458 |
}
|
|
|
459 |
else
|
|
|
460 |
{
|
|
|
461 |
Error("Prepare failure" );
|
|
|
462 |
}
|
|
|
463 |
}
|
|
|
464 |
|
|
|
465 |
|