Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
########################################################################
263 dpurdie 2
# Copyright ( C ) 2008 ERG Limited, All rights reserved
227 dpurdie 3
#
263 dpurdie 4
# Module name   : jats_rewrite.pl
5
# Module type   : JATS Utility
6
# Compiler(s)   : Perl
227 dpurdie 7
# Environment(s): jats
8
#
9
# Description   : Rewrite a build.pl file
10
#                 Use an external configuration file to provide a common
11
#                 source of configuration information
12
#
263 dpurdie 13
# Usage         : See POD
227 dpurdie 14
#
15
#......................................................................#
16
 
255 dpurdie 17
require 5.006_001;
227 dpurdie 18
use strict;
19
use warnings;
20
 
21
use JatsError;
22
use BuildName;
23
use Getopt::Long;
24
use Pod::Usage;                             # required for help support
25
 
26
 
27
################################################################################
28
#   Option variables
29
#
30
 
263 dpurdie 31
my $VERSION = "1.3.0";                      # Update this
227 dpurdie 32
my $opt_verbose = 0;
33
my $opt_datafile = "";
34
my $opt_ofile  = "auto.pl";
35
my $opt_infile = "build.pl";
36
my $opt_help = 0;
37
my $opt_errors = 0;
38
my $opt_xml;
39
my $opt_oldproject;
40
my $opt_newproject;
263 dpurdie 41
my $opt_noconfig;
227 dpurdie 42
 
43
#
44
#   Globals
45
#
46
my %component =  ();
47
my %component_use =  ();
48
my $not_use_count = 0;
49
my $suffix_count = 0;
50
 
247 dpurdie 51
#
52
#   Known extended fields
53
#   Only these values may be configured with the value=tag syntax
54
#   These may not be used as package names
55
#
56
my %fields = (
57
    'releasemanager.releasename' => undef,
58
    'releasemanager.projectname' => undef,
59
);
227 dpurdie 60
 
61
my $result = GetOptions (
263 dpurdie 62
                "help:+"    => \$opt_help,          # flag, multiple use allowed
63
                "manual:3"  => \$opt_help,          # flag
64
                "verbose:+"  => \$opt_verbose,      # flag
227 dpurdie 65
                "config=s"  => \$opt_datafile,      # string
263 dpurdie 66
                "noconfig"  => \$opt_noconfig,      # flag
227 dpurdie 67
                "outfile=s" => \$opt_ofile,         # string
68
                "infile=s"  => \$opt_infile,        # string
69
                "errors"    => \$opt_errors,        # flag
70
                "xml!"       => \$opt_xml,          # flag
71
                "oldproject=s"  => \$opt_oldproject,
72
                "newproject=s"  => \$opt_newproject,
73
                );
74
 
75
#
76
#   Process help and manual options
77
#
78
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
79
pod2usage(-verbose => 1)  if ($opt_help == 2 );
263 dpurdie 80
pod2usage(-verbose => 2)  if ($opt_help > 2);
227 dpurdie 81
 
82
#
83
#   Configure the error reporting process now that we have the user options
84
#
85
ErrorConfig( 'name'    =>'REWRITE',
86
             'verbose' => $opt_verbose );
87
 
88
Error ("Must specify both Old and New project tags")
89
    if ( $opt_newproject xor $opt_oldproject );
90
 
263 dpurdie 91
Error ("Conflicting options -config=file and -noconfig")
92
    if ( $opt_datafile && $opt_noconfig );
93
 
227 dpurdie 94
Error ("No configuration file specified")
263 dpurdie 95
    unless ( $opt_datafile || $opt_newproject || $opt_noconfig );
227 dpurdie 96
 
97
Error ("Input and output file are the same" )
98
    if ( $opt_infile eq $opt_ofile );
99
 
100
#
101
#   Auto detect XML files
102
#
103
$opt_xml = 1
104
    if ( $opt_infile =~ m~\.xml$~i );
105
 
106
#
107
#   Process config and input files
108
#
109
read_config_file()          if $opt_datafile;
110
process_build_file()        unless( $opt_xml);
111
process_xml_build_file()    if ( $opt_xml);
112
 
113
Verbose ("Number of project extensions changed: $suffix_count")
114
    if ( $ opt_newproject );
115
 
116
Warning("No project extensions changed")
117
    if ( !$suffix_count && $opt_newproject);
118
 
119
Error("Unused packages found: $not_use_count")
120
    if ( $opt_errors && $not_use_count && $opt_datafile);
121
 
122
 
123
exit 0;
124
 
125
#-------------------------------------------------------------------------------
126
# Function        : read_config_file
127
#
128
# Description     : Read and store config file information
129
#
130
# Inputs          :
131
#
132
# Returns         :
133
#
134
 
135
sub read_config_file
136
{
137
    open ( FILE, "<$opt_datafile" ) or Error ("Config file ($opt_datafile) not found" );
138
    while ( <FILE> )
139
    {
140
        #
141
        #   Clean up lines
142
        #   Skip comments and blank lines
143
        #   Remove leading and training white space
144
        #
145
        chomp;
146
        s~^\s*~~;
147
        s~#.*$~~;
148
        s~\s*$~~;
149
        next if ( length( $_) <= 0 );
150
 
151
#        Verbose ($_);
152
 
153
        #
247 dpurdie 154
        #   Extract special fields
155
        #   These are not dependent packages and are not mandatory
156
        #   These are of the form tag = name
157
        #
158
        if ( m{(\S+)\s*=\s*(.+)} )
159
        {
160
            Error ("Unsupported named field")  unless ( exists $fields{$1} );
161
            $fields{$1} = $2;
162
            Verbose ("Field: $1, \"$2\"");
163
            next;
164
        }
165
 
166
        #
227 dpurdie 167
        #   Process LinkPkgArchive and BuildPkgArchive statements
168
        #   These allow simple updating of the config file from Release manager
169
        #
170
        if ( m/LinkPkgArchive/ or m/BuildPkgArchive/ )
171
        {
172
            m/'(.*)'[^']*'(.*)'/;
173
 
174
            my $comp = $1;
175
            my $ver = $2;
176
 
177
#print "Got Archive stuff: $_ : $comp, $ver\n";
178
 
179
            Error "Version not specified for: $comp" unless ( $ver );
180
            Warning "Suspect version format for: $comp ($ver)" unless ( $ver =~ m~^\w+\.\w+\.\w+.\w+$~ || $ver =~ m~^\w+\.\w+\.\w+$~ );
181
 
182
            save_package( $comp, $ver );
183
            next;
184
        }
185
 
186
 
187
 
188
        #
189
        #   Process line as
190
        #       component version
191
        #
192
        my ( $comp, $ver, $opt ) = split( /[\s,]+/, $_, 3);
193
        Error "Version not specified for: $comp" unless ( $ver );
194
        Warning "Suspect version format for: $comp ($ver)" unless ( $ver =~ m~^\w+\.\w+\.\w+.\w+$~ || $ver =~ m~^\w+\.\w+\.\w+$~ );
195
        save_package( $comp, $ver );
196
    }
197
    close FILE;
198
 
199
#    DebugDumpData ("component", \%component );
200
}
201
 
202
#-------------------------------------------------------------------------------
203
# Function        : print_update
204
#
205
# Description     : Generate a display line tracking the changes made
206
#
207
# Inputs          :
208
#                   $title          - Update Type
209
#                   $name           - Package name
210
#                   $version        - Original version of package
211
#                   $new_version    - New version
212
#
213
# Returns         :
214
#
215
sub print_update
216
{
217
    my ($title, $name, $version, $new_version ) = @_;
218
    my $diff = ( $version ne $new_version ) ? '*' : '';
219
 
220
    #
221
    #   Always display diffs
222
    #   Display all if verbose
223
    #
224
    if ( $diff || $opt_verbose  )
225
    {
226
        $title = 'Package' unless ( $title );
227
        Message( sprintf("%-8s: %-35s, Version: %-15s %1.1s-> %-15s\n", $title, $name ,$version, $diff, $new_version));
228
    }
229
}
230
 
231
#-------------------------------------------------------------------------------
232
# Function        : process_build_file
233
#
234
# Description     : Rewrite one file
235
#                   build.pl -> build-new.pl
236
#
237
# Inputs          :
238
#
239
# Returns         :
240
#
241
sub process_build_file
242
{
243
    Verbose ("Processing build file: $opt_infile");
244
 
245
    #
246
    #   Unlink any OLD output file
247
    #
248
    unlink $opt_ofile;
249
 
250
    #
251
    #   Open the input and output files
252
    #
253
    open ( INFILE, "<$opt_infile" ) || Error( "Cannot open $opt_infile" );
254
    open ( OUTFILE, ">$opt_ofile" ) || Error( "Cannot create $opt_ofile" );
255
 
256
    my $build_info;
257
 
258
    my $release_name;
259
    my $release_version;
260
 
261
    while ( <INFILE> )
262
    {
263 dpurdie 263
        next if ( $opt_noconfig );       # Nothing to do
227 dpurdie 264
        next if ( m~^\s*#~ );            # Skip comments
265
        #
266
        #   Process BuildName
267
        #
268
        if ( m~\s*BuildName[\s\(]~ )
269
        {
270
            #   Build names come in many flavours
271
            #   Must support a number of different formats
272
            #       "name nn.nn.nn prj"
273
            #       "name nn.nn.nn.prj"
274
            #
275
            #       "name nn.nn.nn prj", "nn.nn.nn"
276
            #       "name nn.nn.nn.prj", "nn.nn.nn"
277
            #
278
            #       "name", "nn.nn.nn.prj"
279
            #
280
            m~\(\s*(.*?)\s*\)~;
281
            my @args = split /\s*,\s*/, $1;
282
            $build_info = parseBuildName( @args );
283
 
284
            my $new_ver = get_package ( $build_info->{BUILDNAME_PACKAGE}, $build_info->{BUILDVERSION} );
285
            my $build_args = genBuildName( $build_info, $new_ver );
286
 
287
            #
288
            #   Rewrite the body of the directive
289
            #
290
            s~\(\s*(.*?)\s*\)~( $build_args )~;
291
            print_update( '', $build_info->{BUILDNAME_PACKAGE}, $build_info->{BUILDVERSION}, $new_ver );
292
 
293
        }
294
 
295
        #
296
        #   Process BuildPreviousVersion
297
        #   Save the current version information in this directive
298
        #
299
        if ( m/^\s*BuildPreviousVersion/ )
300
        {
301
            Error ("BuildPreviousVersion directive before BuildName") unless ( $build_info );
302
            m/['"](.*?)['"]/;
303
            my $prev = $1;
304
 
305
            s/['"](.*?)['"]/'$build_info->{BUILDVERSION}'/;
306
            print_update( 'PrevVer', '', $prev, $build_info->{BUILDVERSION} );
307
        }
308
 
309
        #
310
        #   Process BuildPkgArchive and LinkPkgArchive
311
        if ( m/^\s*LinkPkgArchive/ or m/^\s*BuildPkgArchive/ )
312
        {
313
            m/['"](.*?)['"][^'"]*['"](.*?)['"]/;
314
 
315
            my $comp = $1;
316
            my $ver = $2;
317
            my $new_ver = get_package ( $comp, $ver );
318
            s/['"](.*?)['"]([^'"]*)['"](.*?)['"]/'$comp'$2'$new_ver'/;
319
            print_update ('', $comp ,$ver, $new_ver );
320
        }
321
 
322
 
323
    } continue
324
    {
325
        #
326
        #   Always output the resultant line
327
        #
328
        print OUTFILE $_;
329
    }
330
 
331
    #
332
    #   Cleanup
333
    #
334
    close INFILE;
335
    close OUTFILE;
336
    display_unused();
337
}
338
 
339
#-------------------------------------------------------------------------------
340
# Function        : process_xml_build_file
341
#
342
# Description     : Rewrite one depends.xml file
343
#                   depends.xml -> auto.xml
344
#
345
#                   A very cheap and nasty XML (not)parser
346
#                   It assumes that entries are all on one line so that we can
347
#                   do trivial substitutions
348
#
349
#                   Processes
350
#                       <using ... >
247 dpurdie 351
#                       <property name="packagename" value="...">
352
#                       <property name="packageversion" value="...">
353
#                       <property name="releasemanager.releasename" value="...">
354
#                       <property name="releasemanager.projectname" value="...">
227 dpurdie 355
#                       <import file=...>
356
#
247 dpurdie 357
#                  Note: This function handles a wider scope of XML files
358
#                        than it really needs to. All thats needed is
249 dpurdie 359
#                        the <property name= value=> fields.
227 dpurdie 360
#
361
# Inputs          :
362
#
363
# Returns         :
364
#
365
sub process_xml_build_file
366
{
367
    Verbose ("$opt_infile");
368
 
369
    #
370
    #   Unlink any OLD output file
371
    #
372
    unlink $opt_ofile;
373
 
374
    #
375
    #   Open the input and output files
376
    #
377
    open ( INFILE, "<$opt_infile" ) || Error( "Cannot open $opt_infile" );
378
    open ( OUTFILE, ">$opt_ofile" ) || Error( "Cannot create $opt_ofile" );
379
 
380
    my $release_name;
381
    my $release_version;
382
 
383
    while ( <INFILE> )
384
    {
263 dpurdie 385
        next if ( $opt_noconfig );       # Nothing to do
227 dpurdie 386
        #
387
        #   Process "project" statement
388
        #
389
        if ( m~<project~ )
390
        {
391
            #   Extract the package name
392
            #   this to determine the required version of the package
393
            #
249 dpurdie 394
            if ( m~name="([^"]*)"~ )
233 dpurdie 395
            {
396
                $release_name = $1;
397
                Error ("Empty 'name' attribute not found in 'project'") unless ( $release_name );
398
                Verbose2 ("Project: $release_name");
399
            }
227 dpurdie 400
        }
401
 
402
        #
403
        #   Process "property" statements
404
        #
405
        elsif ( m~<property~ )
406
        {
407
            #
247 dpurdie 408
            #   Extract name and value
409
            #   Both must exist
227 dpurdie 410
            #
247 dpurdie 411
            my $name;
412
            my $value;
227 dpurdie 413
 
249 dpurdie 414
            if ( m~name="([^"]*)"~  )
247 dpurdie 415
            {
416
                $name = $1;
417
            }
418
            else
419
            {
420
                Error ("Name attribute not found in 'property'");
421
            }
422
 
249 dpurdie 423
            if ( m~value="([^"]*)"~ )
247 dpurdie 424
            {
425
                $value = $1;
426
            }
427
            else
428
            {
429
                Error ("Value attribute not found in $name 'property'");
430
            }
431
            Verbose2 ("Property: $name, Value: $value");
432
 
227 dpurdie 433
            #
247 dpurdie 434
            #   Examine th property name
435
            #   Some of the them are special, others will be package names
227 dpurdie 436
            #
437
            if ( $name eq 'packagename' )
438
            {
247 dpurdie 439
                $release_name = $value;
227 dpurdie 440
                Error ("Value attribute not found in packagename 'property'") unless ( $release_name );
441
            }
442
            elsif ( $name eq 'packageversion' )
443
            {
247 dpurdie 444
                $release_version = $value;
227 dpurdie 445
 
446
                #
447
                #   Ensure that we already have the package name
448
                #
449
                Error ("packageversion before packagename") unless ( $release_name );
450
 
451
                my $new_ver = get_package ( $release_name, $release_version );
249 dpurdie 452
                s~(.*)value="([^"]*)"~$1value=\"$new_ver\"~;
227 dpurdie 453
                print_update( '', $release_name ,$release_version, $new_ver );
454
            }
247 dpurdie 455
            elsif ( defined $fields{$name} )
227 dpurdie 456
            {
457
                #
247 dpurdie 458
                #   Use tagged values in preference to packages
459
                #   There are very few tagged values.
227 dpurdie 460
                #
247 dpurdie 461
                my $new_value = $fields{$name};
462
                Error ("Release attribute not found: $name") unless ( $new_value );
463
 
249 dpurdie 464
                s~(.*)value="([^"]*)"~$1value=\"$new_value\"~;
247 dpurdie 465
                print_update( 'Release', $name ,$value, $new_value );
227 dpurdie 466
            }
467
            else
468
            {
247 dpurdie 469
                my $new_ver = get_package ( $name, $value );
249 dpurdie 470
                s~(.*)value="([^"]*)"~$1value=\"$new_ver\"~;
247 dpurdie 471
                print_update( '', $name ,$value, $new_ver );
227 dpurdie 472
            }
473
        }
474
 
475
        #
476
        #   Process "using" statements
477
        #
478
        elsif ( m~<using~ )
479
        {
480
            #
481
            #   Extract the package name and version
482
            #   and use this to determine the required version of the package
483
            #
249 dpurdie 484
            m~name="([^"]*)"~;
227 dpurdie 485
            my $name = $1;
486
            Error ("Name attribute not found in 'using'") unless ( $name );
487
            Verbose2 ("Using: $name");
488
 
489
            #
490
            #   Extract the version
491
            #
249 dpurdie 492
            m~version="([^"]*)"~;
227 dpurdie 493
            $release_version = $1;
494
            Error ("Version attribute not found in package 'using' : $name") unless ( $release_version );
495
 
496
            my $new_ver = get_package ( $name, $release_version );
249 dpurdie 497
            s~(.*)version="([^"]*)"~$1version=\"$new_ver\"~;
227 dpurdie 498
            print_update( '', $name ,$release_version, $new_ver );
499
        }
500
 
501
        #
502
        #   Import File
247 dpurdie 503
        #   Only used to import ant-using
227 dpurdie 504
        #
505
        elsif ( m~<import~ )
506
        {
507
            #
508
            #   Extract the file
509
            #
249 dpurdie 510
            m~file="([^"]*)"~;
227 dpurdie 511
            my $file = $1;
512
            Error ("File attribute not found in 'import'") unless ( $file );
513
 
514
            #
515
            #   Extract the package name and version from the file
516
            #   Will be of the form /package/version/filename
517
            #
518
            $file =~ m~(.*?)/([^/]+)/([^/]+)/([^/]+)$~;
519
            my $prefix = $1;
520
            my $pname = $2;
521
            my $pver = $3;
522
            my $fname = $4;
523
            Error ("Package details not found in import file") unless ( $fname );
524
 
525
            my $new_ver = get_package ( $pname, $pver );
526
 
527
            #
528
            #   Rewrite the body of the directive
529
            #
249 dpurdie 530
            s~(.*)file="([^"]*)"~$1file=\"$prefix/$pname/$new_ver/$fname\"~;
227 dpurdie 531
            print_update( '', $pname ,$pver, $new_ver );
532
        }
533
 
534
    } continue
535
    {
536
        #
537
        #   Always output the resultant line
538
        #
539
        print OUTFILE $_;
540
    }
541
 
542
    #
543
    #   Cleanup
544
    #
545
    close INFILE;
546
    close OUTFILE;
547
    display_unused();
548
}
549
 
550
#-------------------------------------------------------------------------------
551
# Function        : display_unused
552
#
553
# Description     : Generate warnings about config items that were not used
554
#
555
# Inputs          :
556
#
557
# Returns         :
558
#
559
sub display_unused
560
{
561
    foreach my $comp ( sort keys %component_use )
562
    {
563
        foreach my $suf ( keys %{$component_use{$comp}} )
564
        {
565
            my $ver = get_version( $comp, $suf );
566
            Warning("Unused package: ${comp}_${ver}");
567
            $not_use_count++;
568
        }
569
    }
570
}
571
 
572
 
573
#-------------------------------------------------------------------------------
574
# Function        : save_package
575
#
576
# Description     : Save the package name and version
577
#
578
# Inputs          : $package
579
#                   $version
580
#
581
# Returns         : Nothing
582
#
583
sub save_package
584
{
585
    my ($package, $version) = @_;
586
 
587
    #
588
    #   Split the suffix off the version
589
    #
590
    my ($rel, $suf ) = extract_version( $package, $version);
591
 
592
    Error ("Multiple definitions for $package $version" )
593
        if ( $component{$package}{$suf} );
594
 
247 dpurdie 595
    Error ("Package Name is a reserved key field: $package" )
596
        if ( exists $fields{$package} );
597
 
227 dpurdie 598
    $component{$package}{$suf} = $rel;
599
    $component_use{$package}{$suf} = $rel;
600
 
601
    Verbose2 ("Package: $package, $version, $rel, $suf");
602
 
603
}
604
 
605
#-------------------------------------------------------------------------------
606
# Function        : get_package
607
#
608
# Description     : get the package version
609
#
610
# Inputs          : $package
611
#                   $version ( suffix is used only )
612
#
613
# Returns         : Replacement version
614
#
615
 
616
sub get_package
617
{
618
    my ($package, $version) = @_;
619
 
620
    #
621
    #   Split the suffix off the version
622
    #       Suffixes are not numeric
623
    #   Must allow for
624
    #       9.9.9
625
    #       9.9.cots
626
    #       9.9.9.cots
627
    #
628
    my ($rel, $suf ) = extract_version( $package, $version);
629
 
630
    Verbose2 ("Get Package: $package, $version, $rel, $suf");
631
 
632
    #
633
    #   If the CFG file has 'new' project extensions then we
634
    #   must transform them before attempting to look up the versions
635
    #
636
    if ( $opt_oldproject && $suf eq $opt_oldproject )
637
    {
638
        $suf = $opt_newproject;
639
        $suffix_count++;
640
    }
641
 
642
    #
643
    #   If a datafile was provided, then the packages MUST be present
644
    #
645
    if ( $opt_datafile )
646
    {
647
        Error ("No definitions for the package '$package'" )
648
            unless ( exists $component{$package} );
649
 
650
    #    print Data::Dumper->Dump ( [\%component], ["Component" ]);
651
 
652
        Error ("No definitions for '$package' '$version' '$suf'" )
653
            unless ( exists $component{$package}{$suf} );
654
    }
655
 
656
    #
657
    #   remove used packages from the "use" hash
658
    #
659
    delete $component_use{$package}{$suf};
660
    delete $component_use{$package} unless ( keys %{$component_use{$package}} );
661
 
662
    #
663
    #   Was the suffix real
664
    #
665
    return get_version( $package, $suf, $rel );
666
}
667
 
668
#-------------------------------------------------------------------------------
669
# Function        : extract_version
670
#
671
# Description     : Extracts a version and project suffix from a string
672
#
673
# Inputs          : $1  - Package name
674
#                   $2  - Package Version Input string
675
#
676
# Returns         : $1  - Vesrion part
677
#                   $2  - Suffix (project) part
678
#
679
sub extract_version
680
{
681
    my ($package, $version) = @_;
682
 
683
    my $rel;
684
    my $suf;
685
 
686
    if ( $version =~ m~^(.*?)([\.\s]([^0-9]+))$~ )
687
    {
688
        $rel = $1;
689
        $suf = $3;
690
        $suf = '' unless ( $suf );
691
    }
692
    else
693
    {
694
        $rel = $version;
695
        $suf = '';
696
    }
697
 
698
    return ( $rel, $suf );
699
}
700
 
701
#-------------------------------------------------------------------------------
702
# Function        : get_version
703
#
704
# Description     : Create a nice package version
705
#
706
# Inputs          : $package
707
#                   $suf
708
#
709
# Returns         :
710
#
711
sub get_version
712
{
713
    my ($package,$suf, $version) = @_;
714
 
715
    if ( exists( $component{$package}{$suf} ) )
716
    {
717
        $version = $component{$package}{$suf};
718
    }
719
 
720
    if ( $opt_oldproject && $suf eq $opt_oldproject )
721
    {
722
        $suf = $opt_newproject;
723
        $suffix_count++;
724
    }
725
 
726
    $version .= '.' . $suf if ( length( $suf) );
727
    return  $version;
728
 
729
}
730
 
731
#-------------------------------------------------------------------------------
732
# Function        : genBuildName
733
#
734
# Description     : Generate a BuildName argument string
735
#
736
# Inputs          : build_info      - Hash of buildname arguments
737
#                   new_ver         - New version
738
#
739
# Returns         : A string of quoted BuildName arguemnts
740
#
741
sub genBuildName
742
{
743
    my ( $build_info, $new_ver ) = @_;
744
    my @args;
745
 
746
    #
747
    #   Remove the project part from the new version name
748
    #
749
    my $prj = $build_info->{BUILDNAME_PROJECT};
750
 
751
    $prj = $opt_newproject
752
        if ( $opt_oldproject && $prj eq $opt_oldproject );
753
 
754
    $new_ver =~ s~\.$prj$~~ if ( $prj );
755
 
756
    #
757
    #   Determine the format of the BuildName
758
    #
759
    if ( $build_info->{RELAXED_VERSION} )
760
    {
761
        #
762
        #   Relaxed format
763
        #
764
        push @args, $build_info->{BUILDNAME_PACKAGE};
765
        push @args, $new_ver;
766
        push @args, $prj if ( $prj );
767
        push @args, '--RelaxedVersion';
768
    }
769
    else
770
    {
771
        #
772
        #   Generate two field version as some of the deployment scripts
773
        #   need this format.
774
        #
775
        push @args, "$build_info->{BUILDNAME_PACKAGE} $new_ver $prj";
776
    }
777
 
778
    #
779
    #   Common arguments
780
    #
781
    push @args, "--PatchNum=$build_info->{DEPLOY_PATCH}"
782
        if ( $build_info->{DEPLOY_PATCH} );
783
 
784
    push @args, @{$build_info->{EXTRA_ARGS}} if exists ($build_info->{EXTRA_ARGS});
785
 
786
 
787
    #
788
    #   Format the arguments
789
    #
790
    return join ", ", map { "'$_'" } @args;
791
}
792
 
793
#-------------------------------------------------------------------------------
794
#   Documentation
795
#
796
 
797
=pod
798
 
799
=head1 NAME
800
 
801
jats_rewrite - Rewrite a build.pl file
802
 
803
=head1 SYNOPSIS
804
 
805
  jats etool jats_rewrite [options]
806
 
807
 Options:
808
    -help               - brief help message
809
    -help -help         - Detailed help message
810
    -man                - Full documentation
811
    -verbose            - Verbose operation
812
    -config xxx         - Configuration file. Full file name
263 dpurdie 813
    -noconfig           - No configuration file
227 dpurdie 814
    -oldproject         - Old project extension (optional)
815
    -newproject         - New project extension (optional)
816
    -infile xxx         - Input file (build.pl)
817
    -outfile xxx        - Output file (auto.pl)
818
    -errors             - Generate errors for unused config items
819
    -xml                - Process a build.xml file
820
 
821
=head1 OPTIONS
822
 
823
=over 8
824
 
825
=item B<-help>
826
 
827
Print a brief help message and exits.
828
 
829
=item B<-help -help>
830
 
831
Print a detailed help message with an explanation for each option.
832
 
833
=item B<-man>
834
 
835
Prints the manual page and exits.
836
 
837
=item B<-verbose>
838
 
247 dpurdie 839
Increases program output. This option may be specified multiple times
227 dpurdie 840
 
841
=item B<-config=xxx>
842
 
843
This option specifies the name of a configuration file that will provide the
844
transformation between of version numbers. The format of the config file is
845
described later.
846
 
847
The option is not required if -newproject and -oldproject are specified
848
 
263 dpurdie 849
=item B<-noconfig>
850
 
851
This option indiocates that no config file is present and that the output file
852
is to be created without reference to the configuration.
853
 
227 dpurdie 854
=item B<-oldproject=xxx>
855
 
856
This option, in conjunction with B<-oldproject=xxx> allows the project
247 dpurdie 857
extensions to be modified. ie: .syd projects can be converted into .bej
227 dpurdie 858
projects.
859
 
247 dpurdie 860
If this option is present then the config data file is not required, although
227 dpurdie 861
it will be sued if it is present.
862
 
863
=item B<-newproject=xxx>
864
 
865
See B<-oldproject=xxx>
866
 
867
 
868
=item B<-infile=xxx>
869
 
870
The name of the input file. The default file is build.pl
871
 
872
=item B<-outfile=xxx>
873
 
874
The name of the output file. The default is auto.pl, even if an XML file is
875
being processed.
876
 
877
=item B<-errors>
878
 
879
This option will force the program to generate an error message if there are
880
packages in the config file that were not used by the re-write process.
881
 
882
=item B<-xml>
883
 
884
Process a build.xml file instead of a build.pl file.
247 dpurdie 885
This option will be set internally if the infile extension is '.xml'
227 dpurdie 886
 
887
=back
888
 
889
=head1 DESCRIPTION
890
 
247 dpurdie 891
This utility is used within the automated build system to rewrite build files
892
so that they contain suitable version numbers.
227 dpurdie 893
 
247 dpurdie 894
The program takes a configuration file, described below, that contains package
895
and version information for the build.
896
 
897
The program takes a JATS build.pl file, or an ANT style dependency file, and
898
will create a file that is similar, but contains modified package-version
899
information.
900
 
901
The build tools are designed to use this I<auto> file, in preference to the
902
original build file.
903
 
904
=head2 Format of the Configuration File
905
 
227 dpurdie 906
The format of the configuration file is defined below.
907
 
247 dpurdie 908
The file is a line oriented text file.
227 dpurdie 909
 
247 dpurdie 910
Comments begin with a # and go the end of the line.
227 dpurdie 911
 
247 dpurdie 912
There are three types of configuration line:
227 dpurdie 913
 
247 dpurdie 914
=over 8
915
 
916
=item Assigned Items
917
 
918
These are of the form: B<tag = value> and are used to specify the value of
919
the following B<special> properties:
920
 
921
=over 8
922
 
923
=item releasemanager.projectname
924
 
925
The name of the Release Manager project used for the build.
926
 
927
=item releasemanager.releasename
928
 
929
The name of the Release Manager release, within the project, used for the build.
930
 
931
=back
932
 
933
These may be used to brand installer programs with Release Information.
934
Currently the use of these tags is only supported by the XML build files.
935
 
936
=item Package Version
937
 
938
Specifies the version of a package to use as two, space separated words of the
939
form C<package_name package_version> where package version is of the form:
940
 
941
=over 8
942
 
943
=item   * nn.nn.nnnn.aaa
944
 
945
=item   * nn.nn.nnnn
946
 
947
=item   * Other
948
 
949
=back
950
 
951
=item LinkPkgArchive or BuildPkgArchive
952
 
953
These are standard JATS LinkPkgArchive or BuildPkgArchive statements.
954
 
955
=back
956
 
957
=head2 XML File Rewrite
958
 
959
This program will process an ERG style ANT build dependency definition file
960
and replace the values of the properties seen within the file.
961
 
962
The following properties are special within the rewrite process:
963
 
964
=over 8
965
 
966
=item	packagename
967
 
968
This is the name of the package. It is not modified, but it
969
is used in conjunction with the C<packageversion> to identify the package, such
970
that the packageversion can be updated. This property is mandatory and must
971
appear before the C<packageversion>.
972
 
973
=item	packageversion
974
 
975
This is the version of the package. It can be rewritten by this program. This
976
property is mandatory.
977
 
978
=item	releasemanager.projectname
979
 
980
If this property is found the value will be replaced with an B<Assigned Item> of the
981
same name.
982
 
983
=item	releasemanager.releasename
984
 
985
If this property is found the value will be replaced with an B<Assigned Item> of the
986
same name.
987
 
988
=back
989
 
990
Properties that are not B<special> will be treated as the name of a package and
991
the value will be updated to reflect the required version of the package.
992
 
993
The XML rewrite process does not, and cannot handle, instances of packages
994
that have the same name, but different project suffixes. This is a limitation of
995
the ERG ANT build system and not a limitation of this utility.
996
 
997
=head2 JATS Build File Rewrite
998
 
999
This program will process a JATS style build.pl file and modify some
1000
directives to update the file.
1001
 
1002
The following directives will be processed:
1003
 
1004
=over 8
1005
 
1006
=item BuildName
1007
 
1008
The existing version in the BuildName directive will be retained and may be used
1009
in any BuildPreviousVersion directive that is seen.
1010
 
1011
=item BuildPreviousVersion
1012
 
1013
This will be updated to contain the version from the BuildName. This is
1014
intended to be used by deployment scripts.
1015
 
1016
=item LinkPkgArchive
1017
 
1018
The version will be updated to reflect the configured package versions. The
1019
project suffix, if present, will be used to identify the correct package.
1020
 
1021
=item BuildPkgArchive
1022
 
1023
The version will be updated to reflect the configured package versions. The
1024
project suffix, if present, will be used to identify the correct package.
1025
 
1026
=back
1027
 
1028
The JATS build file rewrite process, unlike the ANT process, does handle, instances of packages
1029
that have the same name, but different project suffixes. This allows the use
1030
of packages such as C<sysbasetypes.cr> and C<sysbasetypes.prj> within the one
1031
package.
1032
 
1033
Currently the JATS build file rewrite process does pass the
1034
releasemanager.projectname and the releasemanager.releasename items through to
1035
the underlying system. If present in the config file they will be unused. This
1036
is not an error.
1037
 
227 dpurdie 1038
=cut
1039