| 227 |
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 : Rewrite a build.pl file
|
|
|
11 |
# Use an external configuration file to provide a common
|
|
|
12 |
# source of configuration information
|
|
|
13 |
#
|
|
|
14 |
# Usage:
|
|
|
15 |
#
|
|
|
16 |
# Version Who Date Description
|
|
|
17 |
#
|
|
|
18 |
#......................................................................#
|
|
|
19 |
|
|
|
20 |
require 5.6.1;
|
|
|
21 |
use strict;
|
|
|
22 |
use warnings;
|
|
|
23 |
|
|
|
24 |
use JatsError;
|
|
|
25 |
use BuildName;
|
|
|
26 |
use Getopt::Long;
|
|
|
27 |
use Pod::Usage; # required for help support
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
################################################################################
|
|
|
31 |
# Option variables
|
|
|
32 |
#
|
|
|
33 |
|
|
|
34 |
my $VERSION = "1.2.4"; # Update this
|
|
|
35 |
my $opt_verbose = 0;
|
|
|
36 |
my $opt_datafile = "";
|
|
|
37 |
my $opt_ofile = "auto.pl";
|
|
|
38 |
my $opt_infile = "build.pl";
|
|
|
39 |
my $opt_help = 0;
|
|
|
40 |
my $opt_manual;
|
|
|
41 |
my $opt_errors = 0;
|
|
|
42 |
my $opt_xml;
|
|
|
43 |
my $opt_oldproject;
|
|
|
44 |
my $opt_newproject;
|
|
|
45 |
|
|
|
46 |
#
|
|
|
47 |
# Globals
|
|
|
48 |
#
|
|
|
49 |
my %component = ();
|
|
|
50 |
my %component_use = ();
|
|
|
51 |
my $not_use_count = 0;
|
|
|
52 |
my $suffix_count = 0;
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
my $result = GetOptions (
|
|
|
56 |
"help+" => \$opt_help, # flag, multiple use allowed
|
|
|
57 |
"manual" => \$opt_manual, # flag
|
|
|
58 |
"verbose+" => \$opt_verbose, # flag
|
|
|
59 |
"config=s" => \$opt_datafile, # string
|
|
|
60 |
"outfile=s" => \$opt_ofile, # string
|
|
|
61 |
"infile=s" => \$opt_infile, # string
|
|
|
62 |
"errors" => \$opt_errors, # flag
|
|
|
63 |
"xml!" => \$opt_xml, # flag
|
|
|
64 |
"oldproject=s" => \$opt_oldproject,
|
|
|
65 |
"newproject=s" => \$opt_newproject,
|
|
|
66 |
);
|
|
|
67 |
|
|
|
68 |
#
|
|
|
69 |
# Process help and manual options
|
|
|
70 |
#
|
|
|
71 |
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
|
|
|
72 |
pod2usage(-verbose => 1) if ($opt_help == 2 );
|
|
|
73 |
pod2usage(-verbose => 2) if ($opt_manual || ($opt_help > 2));
|
|
|
74 |
|
|
|
75 |
#
|
|
|
76 |
# Configure the error reporting process now that we have the user options
|
|
|
77 |
#
|
|
|
78 |
ErrorConfig( 'name' =>'REWRITE',
|
|
|
79 |
'verbose' => $opt_verbose );
|
|
|
80 |
|
|
|
81 |
Error ("Must specify both Old and New project tags")
|
|
|
82 |
if ( $opt_newproject xor $opt_oldproject );
|
|
|
83 |
|
|
|
84 |
Error ("No configuration file specified")
|
|
|
85 |
unless ( $opt_datafile || $opt_newproject );
|
|
|
86 |
|
|
|
87 |
Error ("Input and output file are the same" )
|
|
|
88 |
if ( $opt_infile eq $opt_ofile );
|
|
|
89 |
|
|
|
90 |
#
|
|
|
91 |
# Auto detect XML files
|
|
|
92 |
#
|
|
|
93 |
$opt_xml = 1
|
|
|
94 |
if ( $opt_infile =~ m~\.xml$~i );
|
|
|
95 |
|
|
|
96 |
#
|
|
|
97 |
# Process config and input files
|
|
|
98 |
#
|
|
|
99 |
read_config_file() if $opt_datafile;
|
|
|
100 |
process_build_file() unless( $opt_xml);
|
|
|
101 |
process_xml_build_file() if ( $opt_xml);
|
|
|
102 |
|
|
|
103 |
Verbose ("Number of project extensions changed: $suffix_count")
|
|
|
104 |
if ( $ opt_newproject );
|
|
|
105 |
|
|
|
106 |
Warning("No project extensions changed")
|
|
|
107 |
if ( !$suffix_count && $opt_newproject);
|
|
|
108 |
|
|
|
109 |
Error("Unused packages found: $not_use_count")
|
|
|
110 |
if ( $opt_errors && $not_use_count && $opt_datafile);
|
|
|
111 |
|
|
|
112 |
|
|
|
113 |
exit 0;
|
|
|
114 |
|
|
|
115 |
#-------------------------------------------------------------------------------
|
|
|
116 |
# Function : read_config_file
|
|
|
117 |
#
|
|
|
118 |
# Description : Read and store config file information
|
|
|
119 |
#
|
|
|
120 |
# Inputs :
|
|
|
121 |
#
|
|
|
122 |
# Returns :
|
|
|
123 |
#
|
|
|
124 |
|
|
|
125 |
sub read_config_file
|
|
|
126 |
{
|
|
|
127 |
open ( FILE, "<$opt_datafile" ) or Error ("Config file ($opt_datafile) not found" );
|
|
|
128 |
while ( <FILE> )
|
|
|
129 |
{
|
|
|
130 |
#
|
|
|
131 |
# Clean up lines
|
|
|
132 |
# Skip comments and blank lines
|
|
|
133 |
# Remove leading and training white space
|
|
|
134 |
#
|
|
|
135 |
chomp;
|
|
|
136 |
s~^\s*~~;
|
|
|
137 |
s~#.*$~~;
|
|
|
138 |
s~\s*$~~;
|
|
|
139 |
next if ( length( $_) <= 0 );
|
|
|
140 |
|
|
|
141 |
# Verbose ($_);
|
|
|
142 |
|
|
|
143 |
#
|
|
|
144 |
# Process LinkPkgArchive and BuildPkgArchive statements
|
|
|
145 |
# These allow simple updating of the config file from Release manager
|
|
|
146 |
#
|
|
|
147 |
if ( m/LinkPkgArchive/ or m/BuildPkgArchive/ )
|
|
|
148 |
{
|
|
|
149 |
m/'(.*)'[^']*'(.*)'/;
|
|
|
150 |
|
|
|
151 |
my $comp = $1;
|
|
|
152 |
my $ver = $2;
|
|
|
153 |
|
|
|
154 |
#print "Got Archive stuff: $_ : $comp, $ver\n";
|
|
|
155 |
|
|
|
156 |
Error "Version not specified for: $comp" unless ( $ver );
|
|
|
157 |
Warning "Suspect version format for: $comp ($ver)" unless ( $ver =~ m~^\w+\.\w+\.\w+.\w+$~ || $ver =~ m~^\w+\.\w+\.\w+$~ );
|
|
|
158 |
|
|
|
159 |
save_package( $comp, $ver );
|
|
|
160 |
next;
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
|
|
|
164 |
|
|
|
165 |
#
|
|
|
166 |
# Process line as
|
|
|
167 |
# component version
|
|
|
168 |
#
|
|
|
169 |
my ( $comp, $ver, $opt ) = split( /[\s,]+/, $_, 3);
|
|
|
170 |
Error "Version not specified for: $comp" unless ( $ver );
|
|
|
171 |
Warning "Suspect version format for: $comp ($ver)" unless ( $ver =~ m~^\w+\.\w+\.\w+.\w+$~ || $ver =~ m~^\w+\.\w+\.\w+$~ );
|
|
|
172 |
save_package( $comp, $ver );
|
|
|
173 |
}
|
|
|
174 |
close FILE;
|
|
|
175 |
|
|
|
176 |
# DebugDumpData ("component", \%component );
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
#-------------------------------------------------------------------------------
|
|
|
180 |
# Function : print_update
|
|
|
181 |
#
|
|
|
182 |
# Description : Generate a display line tracking the changes made
|
|
|
183 |
#
|
|
|
184 |
# Inputs :
|
|
|
185 |
# $title - Update Type
|
|
|
186 |
# $name - Package name
|
|
|
187 |
# $version - Original version of package
|
|
|
188 |
# $new_version - New version
|
|
|
189 |
#
|
|
|
190 |
# Returns :
|
|
|
191 |
#
|
|
|
192 |
sub print_update
|
|
|
193 |
{
|
|
|
194 |
my ($title, $name, $version, $new_version ) = @_;
|
|
|
195 |
my $diff = ( $version ne $new_version ) ? '*' : '';
|
|
|
196 |
|
|
|
197 |
#
|
|
|
198 |
# Always display diffs
|
|
|
199 |
# Display all if verbose
|
|
|
200 |
#
|
|
|
201 |
if ( $diff || $opt_verbose )
|
|
|
202 |
{
|
|
|
203 |
$title = 'Package' unless ( $title );
|
|
|
204 |
Message( sprintf("%-8s: %-35s, Version: %-15s %1.1s-> %-15s\n", $title, $name ,$version, $diff, $new_version));
|
|
|
205 |
}
|
|
|
206 |
}
|
|
|
207 |
|
|
|
208 |
#-------------------------------------------------------------------------------
|
|
|
209 |
# Function : process_build_file
|
|
|
210 |
#
|
|
|
211 |
# Description : Rewrite one file
|
|
|
212 |
# build.pl -> build-new.pl
|
|
|
213 |
#
|
|
|
214 |
# Inputs :
|
|
|
215 |
#
|
|
|
216 |
# Returns :
|
|
|
217 |
#
|
|
|
218 |
sub process_build_file
|
|
|
219 |
{
|
|
|
220 |
Verbose ("Processing build file: $opt_infile");
|
|
|
221 |
|
|
|
222 |
#
|
|
|
223 |
# Unlink any OLD output file
|
|
|
224 |
#
|
|
|
225 |
unlink $opt_ofile;
|
|
|
226 |
|
|
|
227 |
#
|
|
|
228 |
# Open the input and output files
|
|
|
229 |
#
|
|
|
230 |
open ( INFILE, "<$opt_infile" ) || Error( "Cannot open $opt_infile" );
|
|
|
231 |
open ( OUTFILE, ">$opt_ofile" ) || Error( "Cannot create $opt_ofile" );
|
|
|
232 |
|
|
|
233 |
my $build_info;
|
|
|
234 |
|
|
|
235 |
my $release_name;
|
|
|
236 |
my $release_version;
|
|
|
237 |
|
|
|
238 |
while ( <INFILE> )
|
|
|
239 |
{
|
|
|
240 |
next if ( m~^\s*#~ ); # Skip comments
|
|
|
241 |
#
|
|
|
242 |
# Process BuildName
|
|
|
243 |
#
|
|
|
244 |
if ( m~\s*BuildName[\s\(]~ )
|
|
|
245 |
{
|
|
|
246 |
# Build names come in many flavours
|
|
|
247 |
# Must support a number of different formats
|
|
|
248 |
# "name nn.nn.nn prj"
|
|
|
249 |
# "name nn.nn.nn.prj"
|
|
|
250 |
#
|
|
|
251 |
# "name nn.nn.nn prj", "nn.nn.nn"
|
|
|
252 |
# "name nn.nn.nn.prj", "nn.nn.nn"
|
|
|
253 |
#
|
|
|
254 |
# "name", "nn.nn.nn.prj"
|
|
|
255 |
#
|
|
|
256 |
m~\(\s*(.*?)\s*\)~;
|
|
|
257 |
my @args = split /\s*,\s*/, $1;
|
|
|
258 |
$build_info = parseBuildName( @args );
|
|
|
259 |
|
|
|
260 |
my $new_ver = get_package ( $build_info->{BUILDNAME_PACKAGE}, $build_info->{BUILDVERSION} );
|
|
|
261 |
my $build_args = genBuildName( $build_info, $new_ver );
|
|
|
262 |
|
|
|
263 |
#
|
|
|
264 |
# Rewrite the body of the directive
|
|
|
265 |
#
|
|
|
266 |
s~\(\s*(.*?)\s*\)~( $build_args )~;
|
|
|
267 |
print_update( '', $build_info->{BUILDNAME_PACKAGE}, $build_info->{BUILDVERSION}, $new_ver );
|
|
|
268 |
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
#
|
|
|
272 |
# Process BuildPreviousVersion
|
|
|
273 |
# Save the current version information in this directive
|
|
|
274 |
#
|
|
|
275 |
if ( m/^\s*BuildPreviousVersion/ )
|
|
|
276 |
{
|
|
|
277 |
Error ("BuildPreviousVersion directive before BuildName") unless ( $build_info );
|
|
|
278 |
m/['"](.*?)['"]/;
|
|
|
279 |
my $prev = $1;
|
|
|
280 |
|
|
|
281 |
s/['"](.*?)['"]/'$build_info->{BUILDVERSION}'/;
|
|
|
282 |
print_update( 'PrevVer', '', $prev, $build_info->{BUILDVERSION} );
|
|
|
283 |
}
|
|
|
284 |
|
|
|
285 |
#
|
|
|
286 |
# Process BuildPkgArchive and LinkPkgArchive
|
|
|
287 |
if ( m/^\s*LinkPkgArchive/ or m/^\s*BuildPkgArchive/ )
|
|
|
288 |
{
|
|
|
289 |
m/['"](.*?)['"][^'"]*['"](.*?)['"]/;
|
|
|
290 |
|
|
|
291 |
my $comp = $1;
|
|
|
292 |
my $ver = $2;
|
|
|
293 |
my $new_ver = get_package ( $comp, $ver );
|
|
|
294 |
s/['"](.*?)['"]([^'"]*)['"](.*?)['"]/'$comp'$2'$new_ver'/;
|
|
|
295 |
print_update ('', $comp ,$ver, $new_ver );
|
|
|
296 |
}
|
|
|
297 |
|
|
|
298 |
|
|
|
299 |
} continue
|
|
|
300 |
{
|
|
|
301 |
#
|
|
|
302 |
# Always output the resultant line
|
|
|
303 |
#
|
|
|
304 |
print OUTFILE $_;
|
|
|
305 |
}
|
|
|
306 |
|
|
|
307 |
#
|
|
|
308 |
# Cleanup
|
|
|
309 |
#
|
|
|
310 |
close INFILE;
|
|
|
311 |
close OUTFILE;
|
|
|
312 |
display_unused();
|
|
|
313 |
}
|
|
|
314 |
|
|
|
315 |
#-------------------------------------------------------------------------------
|
|
|
316 |
# Function : process_xml_build_file
|
|
|
317 |
#
|
|
|
318 |
# Description : Rewrite one depends.xml file
|
|
|
319 |
# depends.xml -> auto.xml
|
|
|
320 |
#
|
|
|
321 |
# A very cheap and nasty XML (not)parser
|
|
|
322 |
# It assumes that entries are all on one line so that we can
|
|
|
323 |
# do trivial substitutions
|
|
|
324 |
#
|
|
|
325 |
# Processes
|
|
|
326 |
# <using ... >
|
|
|
327 |
# <property name="packagename" ...>
|
|
|
328 |
# <import file=...>
|
|
|
329 |
#
|
|
|
330 |
#
|
|
|
331 |
# Inputs :
|
|
|
332 |
#
|
|
|
333 |
# Returns :
|
|
|
334 |
#
|
|
|
335 |
sub process_xml_build_file
|
|
|
336 |
{
|
|
|
337 |
Verbose ("$opt_infile");
|
|
|
338 |
|
|
|
339 |
#
|
|
|
340 |
# Unlink any OLD output file
|
|
|
341 |
#
|
|
|
342 |
unlink $opt_ofile;
|
|
|
343 |
|
|
|
344 |
#
|
|
|
345 |
# Open the input and output files
|
|
|
346 |
#
|
|
|
347 |
open ( INFILE, "<$opt_infile" ) || Error( "Cannot open $opt_infile" );
|
|
|
348 |
open ( OUTFILE, ">$opt_ofile" ) || Error( "Cannot create $opt_ofile" );
|
|
|
349 |
|
|
|
350 |
my $release_name;
|
|
|
351 |
my $release_version;
|
|
|
352 |
|
|
|
353 |
while ( <INFILE> )
|
|
|
354 |
{
|
|
|
355 |
#
|
|
|
356 |
# Process "project" statement
|
|
|
357 |
#
|
|
|
358 |
if ( m~<project~ )
|
|
|
359 |
{
|
|
|
360 |
# Extract the package name
|
|
|
361 |
# this to determine the required version of the package
|
|
|
362 |
#
|
| 233 |
dpurdie |
363 |
if ( m~name=\"([^"]*)"~ )
|
|
|
364 |
{
|
|
|
365 |
$release_name = $1;
|
|
|
366 |
Error ("Empty 'name' attribute not found in 'project'") unless ( $release_name );
|
|
|
367 |
Verbose2 ("Project: $release_name");
|
|
|
368 |
}
|
| 227 |
dpurdie |
369 |
}
|
|
|
370 |
|
|
|
371 |
#
|
|
|
372 |
# Process "property" statements
|
|
|
373 |
#
|
|
|
374 |
elsif ( m~<property~ )
|
|
|
375 |
{
|
|
|
376 |
#
|
|
|
377 |
# Extract the package name and version
|
|
|
378 |
# and use this to determine the required version of the package
|
|
|
379 |
#
|
|
|
380 |
m~name=\"([^"]*)"~;
|
|
|
381 |
my $name = $1;
|
|
|
382 |
Error ("Name attribute not found in 'property'") unless ( $name );
|
|
|
383 |
Verbose2 ("Property: $name");
|
|
|
384 |
|
|
|
385 |
#
|
|
|
386 |
# Update the package name
|
|
|
387 |
# The real package name is held in the value attribute
|
|
|
388 |
#
|
|
|
389 |
if ( $name eq 'packagename' )
|
|
|
390 |
{
|
|
|
391 |
m~value=\"([^"]*)"~;
|
|
|
392 |
$release_name = $1;
|
|
|
393 |
Error ("Value attribute not found in packagename 'property'") unless ( $release_name );
|
|
|
394 |
}
|
|
|
395 |
|
|
|
396 |
elsif ( $name eq 'packageversion' )
|
|
|
397 |
{
|
|
|
398 |
m~value=\"([^"]*)"~;
|
|
|
399 |
$release_version = $1;
|
|
|
400 |
Error ("Value attribute not found in packageversion 'property'") unless ( $release_version );
|
|
|
401 |
|
|
|
402 |
#
|
|
|
403 |
# Ensure that we already have the package name
|
|
|
404 |
#
|
|
|
405 |
Error ("packageversion before packagename") unless ( $release_name );
|
|
|
406 |
|
|
|
407 |
my $new_ver = get_package ( $release_name, $release_version );
|
|
|
408 |
s~(.*)value=\"([^"]*)"~$1value=\"$new_ver\"~;
|
|
|
409 |
print_update( '', $release_name ,$release_version, $new_ver );
|
|
|
410 |
}
|
|
|
411 |
|
|
|
412 |
elsif ( $name eq 'env' )
|
|
|
413 |
{
|
|
|
414 |
#
|
|
|
415 |
# 'env' is special
|
|
|
416 |
# Its not a package. Skip it
|
|
|
417 |
#
|
|
|
418 |
}
|
|
|
419 |
|
|
|
420 |
else
|
|
|
421 |
{
|
|
|
422 |
m~value=\"([^"]*)"~;
|
|
|
423 |
$release_version = $1;
|
|
|
424 |
Error ("Value attribute not found in package 'property' : $name") unless ( $release_version );
|
|
|
425 |
|
|
|
426 |
my $new_ver = get_package ( $name, $release_version );
|
|
|
427 |
s~(.*)value=\"([^"]*)"~$1value=\"$new_ver\"~;
|
|
|
428 |
print_update( '', $name ,$release_version, $new_ver );
|
|
|
429 |
}
|
|
|
430 |
}
|
|
|
431 |
|
|
|
432 |
#
|
|
|
433 |
# Process "using" statements
|
|
|
434 |
#
|
|
|
435 |
elsif ( m~<using~ )
|
|
|
436 |
{
|
|
|
437 |
#
|
|
|
438 |
# Extract the package name and version
|
|
|
439 |
# and use this to determine the required version of the package
|
|
|
440 |
#
|
|
|
441 |
m~name=\"([^"]*)"~;
|
|
|
442 |
my $name = $1;
|
|
|
443 |
Error ("Name attribute not found in 'using'") unless ( $name );
|
|
|
444 |
Verbose2 ("Using: $name");
|
|
|
445 |
|
|
|
446 |
#
|
|
|
447 |
# Extract the version
|
|
|
448 |
#
|
|
|
449 |
m~version=\"([^"]*)"~;
|
|
|
450 |
$release_version = $1;
|
|
|
451 |
Error ("Version attribute not found in package 'using' : $name") unless ( $release_version );
|
|
|
452 |
|
|
|
453 |
my $new_ver = get_package ( $name, $release_version );
|
|
|
454 |
s~(.*)version=\"([^"]*)"~$1version=\"$new_ver\"~;
|
|
|
455 |
print_update( '', $name ,$release_version, $new_ver );
|
|
|
456 |
}
|
|
|
457 |
|
|
|
458 |
#
|
|
|
459 |
# Import File
|
|
|
460 |
# Only used to imprt ant-using
|
|
|
461 |
#
|
|
|
462 |
elsif ( m~<import~ )
|
|
|
463 |
{
|
|
|
464 |
#
|
|
|
465 |
# Extract the file
|
|
|
466 |
#
|
|
|
467 |
m~file=\"([^"]*)"~;
|
|
|
468 |
my $file = $1;
|
|
|
469 |
Error ("File attribute not found in 'import'") unless ( $file );
|
|
|
470 |
|
|
|
471 |
#
|
|
|
472 |
# Extract the package name and version from the file
|
|
|
473 |
# Will be of the form /package/version/filename
|
|
|
474 |
#
|
|
|
475 |
$file =~ m~(.*?)/([^/]+)/([^/]+)/([^/]+)$~;
|
|
|
476 |
my $prefix = $1;
|
|
|
477 |
my $pname = $2;
|
|
|
478 |
my $pver = $3;
|
|
|
479 |
my $fname = $4;
|
|
|
480 |
Error ("Package details not found in import file") unless ( $fname );
|
|
|
481 |
|
|
|
482 |
my $new_ver = get_package ( $pname, $pver );
|
|
|
483 |
|
|
|
484 |
#
|
|
|
485 |
# Rewrite the body of the directive
|
|
|
486 |
#
|
|
|
487 |
s~(.*)file=\"([^"]*)"~$1file=\"$prefix/$pname/$new_ver/$fname\"~;
|
|
|
488 |
print_update( '', $pname ,$pver, $new_ver );
|
|
|
489 |
}
|
|
|
490 |
|
|
|
491 |
} continue
|
|
|
492 |
{
|
|
|
493 |
#
|
|
|
494 |
# Always output the resultant line
|
|
|
495 |
#
|
|
|
496 |
print OUTFILE $_;
|
|
|
497 |
}
|
|
|
498 |
|
|
|
499 |
#
|
|
|
500 |
# Cleanup
|
|
|
501 |
#
|
|
|
502 |
close INFILE;
|
|
|
503 |
close OUTFILE;
|
|
|
504 |
display_unused();
|
|
|
505 |
}
|
|
|
506 |
|
|
|
507 |
#-------------------------------------------------------------------------------
|
|
|
508 |
# Function : display_unused
|
|
|
509 |
#
|
|
|
510 |
# Description : Generate warnings about config items that were not used
|
|
|
511 |
#
|
|
|
512 |
# Inputs :
|
|
|
513 |
#
|
|
|
514 |
# Returns :
|
|
|
515 |
#
|
|
|
516 |
sub display_unused
|
|
|
517 |
{
|
|
|
518 |
foreach my $comp ( sort keys %component_use )
|
|
|
519 |
{
|
|
|
520 |
foreach my $suf ( keys %{$component_use{$comp}} )
|
|
|
521 |
{
|
|
|
522 |
my $ver = get_version( $comp, $suf );
|
|
|
523 |
Warning("Unused package: ${comp}_${ver}");
|
|
|
524 |
$not_use_count++;
|
|
|
525 |
}
|
|
|
526 |
}
|
|
|
527 |
}
|
|
|
528 |
|
|
|
529 |
|
|
|
530 |
#-------------------------------------------------------------------------------
|
|
|
531 |
# Function : save_package
|
|
|
532 |
#
|
|
|
533 |
# Description : Save the package name and version
|
|
|
534 |
#
|
|
|
535 |
# Inputs : $package
|
|
|
536 |
# $version
|
|
|
537 |
#
|
|
|
538 |
# Returns : Nothing
|
|
|
539 |
#
|
|
|
540 |
sub save_package
|
|
|
541 |
{
|
|
|
542 |
my ($package, $version) = @_;
|
|
|
543 |
|
|
|
544 |
#
|
|
|
545 |
# Split the suffix off the version
|
|
|
546 |
#
|
|
|
547 |
my ($rel, $suf ) = extract_version( $package, $version);
|
|
|
548 |
|
|
|
549 |
Error ("Multiple definitions for $package $version" )
|
|
|
550 |
if ( $component{$package}{$suf} );
|
|
|
551 |
|
|
|
552 |
$component{$package}{$suf} = $rel;
|
|
|
553 |
$component_use{$package}{$suf} = $rel;
|
|
|
554 |
|
|
|
555 |
Verbose2 ("Package: $package, $version, $rel, $suf");
|
|
|
556 |
|
|
|
557 |
}
|
|
|
558 |
|
|
|
559 |
#-------------------------------------------------------------------------------
|
|
|
560 |
# Function : get_package
|
|
|
561 |
#
|
|
|
562 |
# Description : get the package version
|
|
|
563 |
#
|
|
|
564 |
# Inputs : $package
|
|
|
565 |
# $version ( suffix is used only )
|
|
|
566 |
#
|
|
|
567 |
# Returns : Replacement version
|
|
|
568 |
#
|
|
|
569 |
|
|
|
570 |
sub get_package
|
|
|
571 |
{
|
|
|
572 |
my ($package, $version) = @_;
|
|
|
573 |
|
|
|
574 |
#
|
|
|
575 |
# Split the suffix off the version
|
|
|
576 |
# Suffixes are not numeric
|
|
|
577 |
# Must allow for
|
|
|
578 |
# 9.9.9
|
|
|
579 |
# 9.9.cots
|
|
|
580 |
# 9.9.9.cots
|
|
|
581 |
#
|
|
|
582 |
my ($rel, $suf ) = extract_version( $package, $version);
|
|
|
583 |
|
|
|
584 |
Verbose2 ("Get Package: $package, $version, $rel, $suf");
|
|
|
585 |
|
|
|
586 |
#
|
|
|
587 |
# If the CFG file has 'new' project extensions then we
|
|
|
588 |
# must transform them before attempting to look up the versions
|
|
|
589 |
#
|
|
|
590 |
if ( $opt_oldproject && $suf eq $opt_oldproject )
|
|
|
591 |
{
|
|
|
592 |
$suf = $opt_newproject;
|
|
|
593 |
$suffix_count++;
|
|
|
594 |
}
|
|
|
595 |
|
|
|
596 |
#
|
|
|
597 |
# If a datafile was provided, then the packages MUST be present
|
|
|
598 |
#
|
|
|
599 |
if ( $opt_datafile )
|
|
|
600 |
{
|
|
|
601 |
Error ("No definitions for the package '$package'" )
|
|
|
602 |
unless ( exists $component{$package} );
|
|
|
603 |
|
|
|
604 |
# print Data::Dumper->Dump ( [\%component], ["Component" ]);
|
|
|
605 |
|
|
|
606 |
Error ("No definitions for '$package' '$version' '$suf'" )
|
|
|
607 |
unless ( exists $component{$package}{$suf} );
|
|
|
608 |
}
|
|
|
609 |
|
|
|
610 |
#
|
|
|
611 |
# remove used packages from the "use" hash
|
|
|
612 |
#
|
|
|
613 |
delete $component_use{$package}{$suf};
|
|
|
614 |
delete $component_use{$package} unless ( keys %{$component_use{$package}} );
|
|
|
615 |
|
|
|
616 |
#
|
|
|
617 |
# Was the suffix real
|
|
|
618 |
#
|
|
|
619 |
return get_version( $package, $suf, $rel );
|
|
|
620 |
}
|
|
|
621 |
|
|
|
622 |
#-------------------------------------------------------------------------------
|
|
|
623 |
# Function : extract_version
|
|
|
624 |
#
|
|
|
625 |
# Description : Extracts a version and project suffix from a string
|
|
|
626 |
#
|
|
|
627 |
# Inputs : $1 - Package name
|
|
|
628 |
# $2 - Package Version Input string
|
|
|
629 |
#
|
|
|
630 |
# Returns : $1 - Vesrion part
|
|
|
631 |
# $2 - Suffix (project) part
|
|
|
632 |
#
|
|
|
633 |
sub extract_version
|
|
|
634 |
{
|
|
|
635 |
my ($package, $version) = @_;
|
|
|
636 |
|
|
|
637 |
my $rel;
|
|
|
638 |
my $suf;
|
|
|
639 |
|
|
|
640 |
if ( $version =~ m~^(.*?)([\.\s]([^0-9]+))$~ )
|
|
|
641 |
{
|
|
|
642 |
$rel = $1;
|
|
|
643 |
$suf = $3;
|
|
|
644 |
$suf = '' unless ( $suf );
|
|
|
645 |
}
|
|
|
646 |
else
|
|
|
647 |
{
|
|
|
648 |
$rel = $version;
|
|
|
649 |
$suf = '';
|
|
|
650 |
}
|
|
|
651 |
|
|
|
652 |
return ( $rel, $suf );
|
|
|
653 |
}
|
|
|
654 |
|
|
|
655 |
#-------------------------------------------------------------------------------
|
|
|
656 |
# Function : get_version
|
|
|
657 |
#
|
|
|
658 |
# Description : Create a nice package version
|
|
|
659 |
#
|
|
|
660 |
# Inputs : $package
|
|
|
661 |
# $suf
|
|
|
662 |
#
|
|
|
663 |
# Returns :
|
|
|
664 |
#
|
|
|
665 |
sub get_version
|
|
|
666 |
{
|
|
|
667 |
my ($package,$suf, $version) = @_;
|
|
|
668 |
|
|
|
669 |
if ( exists( $component{$package}{$suf} ) )
|
|
|
670 |
{
|
|
|
671 |
$version = $component{$package}{$suf};
|
|
|
672 |
}
|
|
|
673 |
|
|
|
674 |
if ( $opt_oldproject && $suf eq $opt_oldproject )
|
|
|
675 |
{
|
|
|
676 |
$suf = $opt_newproject;
|
|
|
677 |
$suffix_count++;
|
|
|
678 |
}
|
|
|
679 |
|
|
|
680 |
$version .= '.' . $suf if ( length( $suf) );
|
|
|
681 |
return $version;
|
|
|
682 |
|
|
|
683 |
}
|
|
|
684 |
|
|
|
685 |
#-------------------------------------------------------------------------------
|
|
|
686 |
# Function : genBuildName
|
|
|
687 |
#
|
|
|
688 |
# Description : Generate a BuildName argument string
|
|
|
689 |
#
|
|
|
690 |
# Inputs : build_info - Hash of buildname arguments
|
|
|
691 |
# new_ver - New version
|
|
|
692 |
#
|
|
|
693 |
# Returns : A string of quoted BuildName arguemnts
|
|
|
694 |
#
|
|
|
695 |
sub genBuildName
|
|
|
696 |
{
|
|
|
697 |
my ( $build_info, $new_ver ) = @_;
|
|
|
698 |
my @args;
|
|
|
699 |
|
|
|
700 |
#
|
|
|
701 |
# Remove the project part from the new version name
|
|
|
702 |
#
|
|
|
703 |
my $prj = $build_info->{BUILDNAME_PROJECT};
|
|
|
704 |
|
|
|
705 |
$prj = $opt_newproject
|
|
|
706 |
if ( $opt_oldproject && $prj eq $opt_oldproject );
|
|
|
707 |
|
|
|
708 |
$new_ver =~ s~\.$prj$~~ if ( $prj );
|
|
|
709 |
|
|
|
710 |
#
|
|
|
711 |
# Determine the format of the BuildName
|
|
|
712 |
#
|
|
|
713 |
if ( $build_info->{RELAXED_VERSION} )
|
|
|
714 |
{
|
|
|
715 |
#
|
|
|
716 |
# Relaxed format
|
|
|
717 |
#
|
|
|
718 |
push @args, $build_info->{BUILDNAME_PACKAGE};
|
|
|
719 |
push @args, $new_ver;
|
|
|
720 |
push @args, $prj if ( $prj );
|
|
|
721 |
push @args, '--RelaxedVersion';
|
|
|
722 |
}
|
|
|
723 |
else
|
|
|
724 |
{
|
|
|
725 |
#
|
|
|
726 |
# Generate two field version as some of the deployment scripts
|
|
|
727 |
# need this format.
|
|
|
728 |
#
|
|
|
729 |
push @args, "$build_info->{BUILDNAME_PACKAGE} $new_ver $prj";
|
|
|
730 |
push @args, "$new_ver";
|
|
|
731 |
}
|
|
|
732 |
|
|
|
733 |
#
|
|
|
734 |
# Common arguments
|
|
|
735 |
#
|
|
|
736 |
push @args, "--PatchNum=$build_info->{DEPLOY_PATCH}"
|
|
|
737 |
if ( $build_info->{DEPLOY_PATCH} );
|
|
|
738 |
|
|
|
739 |
push @args, @{$build_info->{EXTRA_ARGS}} if exists ($build_info->{EXTRA_ARGS});
|
|
|
740 |
|
|
|
741 |
|
|
|
742 |
#
|
|
|
743 |
# Format the arguments
|
|
|
744 |
#
|
|
|
745 |
return join ", ", map { "'$_'" } @args;
|
|
|
746 |
}
|
|
|
747 |
|
|
|
748 |
#-------------------------------------------------------------------------------
|
|
|
749 |
# Documentation
|
|
|
750 |
#
|
|
|
751 |
|
|
|
752 |
=pod
|
|
|
753 |
|
|
|
754 |
=head1 NAME
|
|
|
755 |
|
|
|
756 |
jats_rewrite - Rewrite a build.pl file
|
|
|
757 |
|
|
|
758 |
=head1 SYNOPSIS
|
|
|
759 |
|
|
|
760 |
jats etool jats_rewrite [options]
|
|
|
761 |
|
|
|
762 |
Options:
|
|
|
763 |
-help - brief help message
|
|
|
764 |
-help -help - Detailed help message
|
|
|
765 |
-man - Full documentation
|
|
|
766 |
-verbose - Verbose operation
|
|
|
767 |
-config xxx - Configuration file. Full file name
|
|
|
768 |
-oldproject - Old project extension (optional)
|
|
|
769 |
-newproject - New project extension (optional)
|
|
|
770 |
-infile xxx - Input file (build.pl)
|
|
|
771 |
-outfile xxx - Output file (auto.pl)
|
|
|
772 |
-errors - Generate errors for unused config items
|
|
|
773 |
-xml - Process a build.xml file
|
|
|
774 |
|
|
|
775 |
=head1 OPTIONS
|
|
|
776 |
|
|
|
777 |
=over 8
|
|
|
778 |
|
|
|
779 |
=item B<-help>
|
|
|
780 |
|
|
|
781 |
Print a brief help message and exits.
|
|
|
782 |
|
|
|
783 |
=item B<-help -help>
|
|
|
784 |
|
|
|
785 |
Print a detailed help message with an explanation for each option.
|
|
|
786 |
|
|
|
787 |
=item B<-man>
|
|
|
788 |
|
|
|
789 |
Prints the manual page and exits.
|
|
|
790 |
|
|
|
791 |
=item B<-verbose>
|
|
|
792 |
|
|
|
793 |
Increases program output. This option may be specified mutiple times
|
|
|
794 |
|
|
|
795 |
=item B<-config=xxx>
|
|
|
796 |
|
|
|
797 |
This option specifies the name of a configuration file that will provide the
|
|
|
798 |
transformation between of version numbers. The format of the config file is
|
|
|
799 |
described later.
|
|
|
800 |
|
|
|
801 |
The option is not required if -newproject and -oldproject are specified
|
|
|
802 |
|
|
|
803 |
=item B<-oldproject=xxx>
|
|
|
804 |
|
|
|
805 |
This option, in conjunction with B<-oldproject=xxx> allows the project
|
|
|
806 |
extensions to be modified. ie: .syd projects can eb converted into .bej
|
|
|
807 |
projects.
|
|
|
808 |
|
|
|
809 |
If this option is present thenthe config data file is not required, although
|
|
|
810 |
it will be sued if it is present.
|
|
|
811 |
|
|
|
812 |
=item B<-newproject=xxx>
|
|
|
813 |
|
|
|
814 |
See B<-oldproject=xxx>
|
|
|
815 |
|
|
|
816 |
|
|
|
817 |
=item B<-infile=xxx>
|
|
|
818 |
|
|
|
819 |
The name of the input file. The default file is build.pl
|
|
|
820 |
|
|
|
821 |
=item B<-outfile=xxx>
|
|
|
822 |
|
|
|
823 |
The name of the output file. The default is auto.pl, even if an XML file is
|
|
|
824 |
being processed.
|
|
|
825 |
|
|
|
826 |
=item B<-errors>
|
|
|
827 |
|
|
|
828 |
This option will force the program to generate an error message if there are
|
|
|
829 |
packages in the config file that were not used by the re-write process.
|
|
|
830 |
|
|
|
831 |
=item B<-xml>
|
|
|
832 |
|
|
|
833 |
Process a build.xml file instead of a build.pl file.
|
|
|
834 |
This option will be set internally if the infile extesnion is '.xml'
|
|
|
835 |
|
|
|
836 |
=back
|
|
|
837 |
|
|
|
838 |
=head1 DESCRIPTION
|
|
|
839 |
|
|
|
840 |
=head2 CONFIG FILE FORMAT
|
|
|
841 |
|
|
|
842 |
The format of the configuration file is defined below.
|
|
|
843 |
|
|
|
844 |
Comments begin with a # and go the end of the line
|
|
|
845 |
|
|
|
846 |
There are two types of config line
|
|
|
847 |
package version
|
|
|
848 |
Specifies the version of a package to use
|
|
|
849 |
The version may be of the form:
|
|
|
850 |
nn.nn.nn.aaa
|
|
|
851 |
nn.nn.nn
|
|
|
852 |
other
|
|
|
853 |
|
|
|
854 |
Standard LinkPkgArchive or BuildPkgArchive statements
|
|
|
855 |
|
|
|
856 |
=cut
|
|
|
857 |
|