Subversion Repositories DevTools

Rev

Rev 255 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 255 Rev 261
Line 1... Line -...
1
#! perl
-
 
2
########################################################################
1
########################################################################
3
# Copyright ( C ) 2004 ERG Limited, All rights reserved
2
# Copyright ( C ) 2008 ERG Limited, All rights reserved
4
#
3
#
5
# Module name   : jats.sh
4
# Module name   : jats.sh
6
# Module type   : Makefile system
5
# Module type   : Makefile system
7
# Compiler(s)   : n/a
6
# Compiler(s)   : n/a
8
# Environment(s): jats
7
# Environment(s): jats
9
#
8
#
10
# Description   : Save a rewritten build.pl file back into version control
9
# Description   : Build Daemon Support Utility
-
 
10
#                 This utility will:
-
 
11
#                   +   Assume the CWD is the root-dir of a package
-
 
12
#                       within a versioned control view
11
#                 This script is a dedicated part of the auto build system
13
#                   +   Determine a suitable label for the package
-
 
14
#                   +   Save the build file in the view
-
 
15
#                   +   Label the resultant view
12
#
16
#
-
 
17
# Note          : Intended to be backward compatible wth old (simple)
13
# Usage:
18
#                 functionality.
14
#
19
#
15
# Version   Who      Date        Description
20
# Usage:        : See POD at end of this file
16
#
21
#
17
#......................................................................#
22
#......................................................................#
18
 
23
 
19
require 5.006_001;
-
 
20
use strict;
24
use strict;
21
use warnings;
25
use warnings;
22
use JatsError;
26
use JatsError;
-
 
27
use JatsBuildFiles;
-
 
28
use JatsSystem;
-
 
29
use JatsProperties;
23
use Getopt::Long;
30
use Getopt::Long;
24
use Pod::Usage;                             # required for help support
31
use Pod::Usage;                             # required for help support
-
 
32
use Cwd;
25
 
33
 
26
################################################################################
34
################################################################################
27
#   Option variables
35
#   Option variables
28
#
36
#
29
 
37
 
30
my $VERSION = "1.2.0";                      # Update this
38
my $VERSION = "2.0.0";                      # Update this
31
my $opt_verbose = 0;
39
my $opt_verbose = 0;
32
my $opt_infile  = "auto.pl";
40
my $opt_infile  = "auto.pl";
33
my $opt_ofile = "build.pl";
41
my $opt_ofile = "build.pl";
34
my $opt_help = 0;
42
my $opt_help = 0;
35
my $opt_manual;
-
 
36
my $opt_label;
43
my $opt_label;
37
my $opt_branch_default = "AutoBuilder";
44
my $opt_branch_default = "AutoBuilder";
38
my $opt_branch;
45
my $opt_branch;
39
my $opt_newbranch;
46
my $opt_newbranch;
-
 
47
my $opt_infofile;
-
 
48
my $opt_pname;
-
 
49
my $opt_pversion;
-
 
50
my $opt_wiplabel;
-
 
51
my $opt_locate;
40
 
52
 
41
#
53
#
42
#   Globals
54
#   Globals
43
#
55
#
-
 
56
my $root_dir;
-
 
57
my $pkg_label;
-
 
58
my $tag_label;
44
my @error_list;
59
my @error_list;
45
my $last_result;
60
my $last_result;
46
my @last_results;
61
my @last_results;
-
 
62
my $label_created;
47
 
63
 
-
 
64
#
-
 
65
#   Configuration options
-
 
66
#
48
my $result = GetOptions (
67
my $result = GetOptions (
49
                "help+"         => \$opt_help,          # flag, multiple use allowed
68
                "help:+"        => \$opt_help,              # flag, multiple use allowed
50
                "manual"        => \$opt_manual,        # flag
69
                "manual:3"      => \$opt_help,              # flag
51
                "verbose+"      => \$opt_verbose,       # flag
70
                "verbose:+"     => \$opt_verbose,           # flag
-
 
71
 
52
                "outfile=s"     => \$opt_ofile,         # string
72
                "outfile=s"     => \$opt_ofile,             # string
53
                "infile=s"      => \$opt_infile,        # string
73
                "infile=s"      => \$opt_infile,            # string
54
                "label=s"       => \$opt_label,         # string
74
                "label=s"       => \$opt_label,             # string
55
                "branch=s"      => \$opt_branch,        # string
75
                "branch=s"      => \$opt_branch,            # string
56
                "newbranch"     => \$opt_newbranch,     # string
76
                "newbranch"     => \$opt_newbranch,         # string
-
 
77
 
-
 
78
                "infofile=s"    => \$opt_infofile,          # string
-
 
79
                "pname=s"       => \$opt_pname,             # string
-
 
80
                "pversion=s"    => \$opt_pversion,          # string
-
 
81
                "wiplabel=s"    => \$opt_wiplabel,          # string
-
 
82
                "locatepkg=s"   => \$opt_locate,            # string
-
 
83
 
-
 
84
                #
-
 
85
                #   Update documentation at the end of the file
-
 
86
                #
57
                );
87
                );
58
 
88
 
59
#
89
#
60
#   Process help and manual options
90
#   Process help and manual options
61
#
91
#
62
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
92
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
63
pod2usage(-verbose => 1)  if ($opt_help == 2 );
93
pod2usage(-verbose => 1)  if ( $opt_help == 2 );
64
pod2usage(-verbose => 2)  if ($opt_manual || ($opt_help > 2));
94
pod2usage(-verbose => 2)  if ( $opt_help > 2 );
65
 
95
 
66
#
96
#
67
#   Configure the error reporting process now that we have the user options
97
#   Configure the error reporting process now that we have the user options
68
#
98
#
69
ErrorConfig( 'name'    =>'ASAVE',
99
ErrorConfig( 'name'    =>'ABTSAVE',
70
             'verbose' => $opt_verbose,
100
             'verbose' => $opt_verbose,
71
             'on_exit' => \&display_error_list
101
             'on_exit' => \&display_error_list
72
           );
102
           );
73
 
103
 
74
Error ("No label")
-
 
75
    unless ( $opt_label  );
-
 
76
 
-
 
77
Error ("Input and output file are the same: $opt_infile" )
104
Error ("Input and output file are the same: $opt_infile" )
78
    if ( $opt_infile eq $opt_ofile );
105
    if ( $opt_infile eq $opt_ofile );
79
 
106
 
80
Error ("Input file not found: $opt_infile" )
-
 
81
    unless ( -f $opt_infile );
-
 
82
 
-
 
83
Error ("Output file not found: $opt_ofile" )
-
 
84
    unless ( -f $opt_ofile );
-
 
85
 
-
 
86
Error ("Must provide a branch when usng newbranch option")
107
Error ("Must provide a branch when usng newbranch option")
87
    if ( $opt_newbranch && ! $opt_branch );
108
    if ( $opt_newbranch && ! $opt_branch );
88
 
109
 
89
$opt_branch = $opt_branch_default
110
$opt_branch = $opt_branch_default
90
    unless ( $opt_branch );
111
    unless ( $opt_branch );
91
 
112
 
92
#
113
#
-
 
114
#   If $opt_label has been provided, then operate in a backwardly
-
 
115
#   compatible manner. Only perform the build file save. Do not perform
-
 
116
#   any of the advanced label operations.
-
 
117
#
-
 
118
unless ( $opt_label )
-
 
119
{
-
 
120
    Error ("Package Name not provided")
-
 
121
        unless ( $opt_pname );
-
 
122
 
-
 
123
    Error ("Package Version not provided")
-
 
124
        unless ( $opt_pversion );
-
 
125
 
-
 
126
    Warning("Path to info file not provided")
-
 
127
        unless ( $opt_infofile );
-
 
128
    unlink ($opt_infofile) if $opt_infofile;
-
 
129
}
-
 
130
else
-
 
131
{
-
 
132
    #
-
 
133
    #   Ensure none of the 'new' options are used
-
 
134
    #
-
 
135
    Error ("Option not compatible with -label: locatepkg")
-
 
136
        if ( $opt_locate );
-
 
137
 
-
 
138
    Error ("Option not compatible with -label: wiplabel")
-
 
139
        if ( $opt_wiplabel );
-
 
140
 
-
 
141
    Error ("Option not compatible with -label: infofile")
-
 
142
        if ( $opt_infofile );
-
 
143
}
-
 
144
 
-
 
145
#
-
 
146
#   Locate the build directory and chdir to that directory
-
 
147
#
-
 
148
locate_build_directory();
-
 
149
 
-
 
150
#
-
 
151
#   Have changed to the directory with build files
-
 
152
#   Continue with user argument sanity check
-
 
153
#
-
 
154
Error ("Input file not found: $opt_infile" )
-
 
155
    unless ( -f $opt_infile );
-
 
156
 
-
 
157
Error ("Output file not found: $opt_ofile" )
-
 
158
    unless ( -f $opt_ofile );
-
 
159
 
-
 
160
#
93
#   Determine the name of the Branch to be used
161
#   Determine the name of the Branch to be used
94
#   This is based on the branch that the file is already on as ClearCase does
162
#   This is based on the branch that the file is already on as ClearCase does
95
#   not allow multiple instances of a branch on different sub-branches
163
#   not allow multiple instances of a branch on different sub-branches
96
#
164
#
97
ClearCmd ("describe -fmt \"%n\" \"$opt_ofile\"");
165
ClearCmd ('describe',  '-fmt', '%n', $opt_ofile);
98
Error ("Program Terminated") if ( @error_list );
166
Error ("Program Terminated") if ( @error_list );
99
Error ("File may not be a VOB object: $opt_ofile" ) unless ( $last_result );
167
Error ("File may not be a VOB object: $opt_ofile" ) unless ( $last_result );
100
my $full_name = $last_result;
168
my $full_name = $last_result;
101
 
169
 
102
$last_result =~ m~(.*)/([^/]+)$~;
170
$last_result =~ m~(.*)/([^/]+)$~;
Line 157... Line 225...
157
 
225
 
158
Verbose2 ("TargetBranch : $target_branch" );
226
Verbose2 ("TargetBranch : $target_branch" );
159
Verbose2 ("BranchPoint  : $branch_point" );
227
Verbose2 ("BranchPoint  : $branch_point" );
160
 
228
 
161
#
229
#
162
#   Ensure that the specified label exists
230
#   Determine the desired label for the package
163
#   Determine if it is locked too
231
#   May need to pick an unassigned label
-
 
232
#
-
 
233
determine_package_label();
-
 
234
 
164
#
235
#
-
 
236
#   Ensure that the specified package label exists
-
 
237
#   Determine if it is locked too
-
 
238
#   
-
 
239
Verbose ("Checking package label: $pkg_label");
165
ClearCmd ("describe -fmt %[locked]p lbtype:$opt_label" );
240
ClearCmd ('describe', '-fmt', '%[locked]p', "lbtype:$pkg_label" );
166
Error ("Program Terminated") if ( @error_list );
241
Error ("Program Terminated") if ( @error_list );
167
my $was_locked = 1 unless ( $last_result =~ m~unlocked~ );
242
my $was_locked = 1 unless ( $last_result =~ m~unlocked~ );
168
 
243
 
169
#
244
#
170
#   Create the desired branch if it does not already exist
245
#   Create the desired branch if it does not already exist
171
#   Dtected locked element and unlock it
246
#   Detected locked element and unlock it
172
#
247
#
-
 
248
Verbose ("Checking branch existence: $opt_branch");
173
ClearCmd ("lstype -short brtype:$opt_branch" );
249
ClearCmd ('lstype', '-short', "brtype:$opt_branch" );
174
if ( $last_result =~ m~\(locked\)~ )
250
if ( $last_result =~ m~\(locked\)~ )
175
{
251
{
-
 
252
    Verbose ("Unlocking branch: $opt_branch");
176
    ClearCmd( "unlock -c \"Unlocked by JATS ASAVE\" brtype:$opt_branch" );
253
    ClearCmd( 'unlock', '-c', 'Unlocked by JATS ABTSAVE', "brtype:$opt_branch" );
177
}
254
}
178
elsif ( $last_result ne $opt_branch )
255
elsif ( $last_result ne $opt_branch )
179
{
256
{
-
 
257
    Verbose ("Create new branch: $opt_branch");
180
    ClearCmd ("mkbrtype -c \"Contains saved versions of $opt_ofile files created by the AutoBuild system\" $opt_branch" );
258
    ClearCmd ('mkbrtype', '-c', "Contains saved versions of $opt_ofile files created by the AutoBuild system", $opt_branch );
181
    Error ("Program Terminated") if ( @error_list );
259
    Error ("Program Terminated") if ( @error_list );
182
}
260
}
183
 
261
 
184
#
262
#
185
#   Ensure that the file is not locked
263
#   Ensure that the file is not locked
186
#   Unlock the file - can't do anything to a 'locked' file
264
#   Unlock the file - can't do anything to a 'locked' file
187
#
265
#
-
 
266
Verbose ("Checking for locked file: $opt_ofile");
188
ClearCmd ("lslock -short $opt_ofile" );
267
ClearCmd ('lslock', '-short', $opt_ofile );
189
if ( $last_result )
268
if ( $last_result )
190
{
269
{
-
 
270
    Verbose ("Unlocking file: $opt_ofile");
191
    ClearCmd( "unlock -c \"Unlocked by JATS ASAVE\" $opt_ofile" );
271
    ClearCmd( 'unlock', '-c', 'Unlocked by JATS ABTSAVE', $opt_ofile );
192
}
272
}
193
 
273
 
194
if ( $current_branch ne $opt_branch )
274
if ( $current_branch ne $opt_branch )
195
{
275
{
196
    #
276
    #
197
    #   Need to create the initial branch point, but only if one does not already
277
    #   Need to create the initial branch point, but only if one does not already
198
    #   exists
278
    #   exists
199
    #
279
    #
200
    Verbose ("Does a branch exist" );
280
    Verbose ("Check for existing branch: $opt_branch" );
201
    if ( ClearCmd( "find $opt_ofile -version \"brtype($opt_branch)\" -print" ) )
281
    if ( ClearCmd( 'find', $opt_ofile, '-version', "brtype($opt_branch)", '-print' ) )
202
    {
282
    {
203
        Error ("Internal error. Cleartool find should not fail");
283
        Error ("Internal error. Cleartool find should not fail");
204
    }
284
    }
205
    if ( $last_result )
285
    if ( $last_result )
206
    {
286
    {
Line 213... Line 293...
213
        Verbose2 ("Target Branch: $target_branch" );
293
        Verbose2 ("Target Branch: $target_branch" );
214
    }
294
    }
215
    else
295
    else
216
    {
296
    {
217
        Verbose ("Create the initial branch point" );
297
        Verbose ("Create the initial branch point" );
218
        ClearCmd( "mkbranch -nco -nc -nwarn $branch_point $opt_branch $opt_ofile" );
298
        ClearCmd( 'mkbranch', '-nco', '-nc', '-nwarn', $branch_point, $opt_branch, $opt_ofile );
219
    }
299
    }
220
}
300
}
221
 
301
 
222
#
302
#
223
#   Ensure that the branch with the target auto builder file on is not locked
303
#   Ensure that the branch with the target auto builder file on is not locked
224
#
304
#
225
ClearCmd ("lslock -short \"$opt_ofile\@\@$target_branch\"" );
305
ClearCmd ( 'lslock', '-short', "$opt_ofile\@\@$target_branch" );
226
if ( $last_result )
306
if ( $last_result )
227
{
307
{
-
 
308
    Verbose ("Unlocking branch: $target_branch");
228
    ClearCmd( "unlock -c \"Unlocked by JATS ASAVE\" \"$opt_ofile\@\@$target_branch\"" );
309
    ClearCmd( 'unlock', '-c', 'Unlocked by JATS ABTSAVE', "$opt_ofile\@\@$target_branch" );
229
}
310
}
230
 
311
 
231
 
312
 
232
#
313
#
233
#   Look for a checked out file on the target branch
314
#   Look for a checked out file on the target branch
234
#   It may be reserved - this will kill the process, so unreserve it
315
#   It may be reserved - this will kill the process, so unreserve it
235
#
316
#
236
if ( ClearCmd( "lsco -long -brtype $opt_branch $opt_ofile" ) )
317
if ( ClearCmd( 'lsco', '-long', '-brtype', $opt_branch, $opt_ofile ) )
237
{
318
{
238
    Error ("Internal error. Cleartool lsco should not fail");
319
    Error ("Internal error. Cleartool lsco should not fail");
239
}
320
}
240
 
321
 
241
#
322
#
Line 257... Line 338...
257
    {
338
    {
258
        m~\(\"(.+)\"\)~;
339
        m~\(\"(.+)\"\)~;
259
        my $view = $1;
340
        my $view = $1;
260
        $view =~ s~/~\\~g unless ( $ENV{GBE_UNIX} );
341
        $view =~ s~/~\\~g unless ( $ENV{GBE_UNIX} );
261
        Verbose2 ("Reserved checkout: Target View: $view" );
342
        Verbose2 ("Reserved checkout: Target View: $view" );
262
        ClearCmd( "unreserve -comment \"Unreserved by JATS ASAVE\" -view \"$view\" $opt_ofile" );
343
        ClearCmd( 'unreserve', '-comment', 'Unreserved by JATS ABTSAVE', '-view', $view, $opt_ofile );
263
 
344
 
264
        #
345
        #
265
        #   Only one reserved file can exist, so there is no more to do
346
        #   Only one reserved file can exist, so there is no more to do
266
        #
347
        #
267
        last;
348
        last;
Line 274... Line 355...
274
}
355
}
275
 
356
 
276
#
357
#
277
#   Use clearcase to checkout the output file
358
#   Use clearcase to checkout the output file
278
#
359
#
-
 
360
Verbose ("Checkout file: $opt_ofile" );
279
ClearCmd ("co -nc -nq -ndata -nwarn -branch \"$target_branch\" $opt_ofile");
361
ClearCmd ('co', '-nc', '-nq', '-ndata', '-nwarn', '-branch', $target_branch, $opt_ofile);
280
Error ("Program Terminated") if ( @error_list );
362
Error ("Program Terminated") if ( @error_list );
281
 
363
 
282
#
364
#
283
#   Place the label on this file
365
#   Place the label on this file
284
#       If the label is locked then unlock it first
366
#       If the label is locked then unlock it first
285
#       This is OK, because we are the builder ( or have permission )
367
#       This is OK, because we are the builder ( or have permission )
286
#
368
#
-
 
369
if ( $was_locked )
-
 
370
{
-
 
371
    Verbose ("Relocking label: $pkg_label");
287
ClearCmd ("unlock lbtype:$opt_label" ) if $was_locked;
372
    ClearCmd ('unlock', "lbtype:$pkg_label" );
-
 
373
}
288
 
374
 
289
ClearCmd ("mklabel -replace $opt_label \"$opt_ofile\"" );
375
ClearCmd ('mklabel', '-replace', $pkg_label, $opt_ofile );
290
my @delayed_error = @error_list;
376
my @delayed_error = @error_list;
291
 
377
 
292
ClearCmd ("lock lbtype:$opt_label" ) if $was_locked;
378
ClearCmd ('lock', "lbtype:$pkg_label" ) if $was_locked;
293
 
379
 
294
#
380
#
295
#   Place a Hyperlink Merge arrow between the two files if it looks as though we
381
#   Place a Hyperlink Merge arrow between the two files if it looks as though we
296
#   have stolen the file or its label. If the original build file is on a different branch
382
#   have stolen the file or its label. If the original build file is on a different branch
297
#   the we have stolen it.
383
#   the we have stolen it.
298
#
384
#
299
Verbose ("Do we need to create a Hyperlink" );
385
Verbose ("Check need to create a Hyperlink" );
300
 
386
 
301
my $target_name = $opt_ofile;
387
my $target_name = $opt_ofile;
302
Verbose2 ("FullName: $full_name :Branch: $full_branch" );
388
Verbose2 ("FullName: $full_name :Branch: $full_branch" );
303
Verbose2 ("TargetName: $target_name :Branch: $target_branch" );
389
Verbose2 ("TargetName: $target_name :Branch: $target_branch" );
304
 
390
 
305
if ( ( $full_branch ne $target_branch ) && ( !$opt_newbranch ) )
391
if ( ( $full_branch ne $target_branch ) && ( !$opt_newbranch ) )
306
{
392
{
-
 
393
    Verbose ("Creating Hyperlink" );
307
    ClearCmd ("mkhlink Merge \"$full_name\" \"$target_name\" ");
394
    ClearCmd ('mkhlink', 'Merge', $full_name, $target_name);
308
}
395
}
309
 
396
 
310
#
397
#
311
#   Check in the file auto.pl file as the new build.pl file
398
#   Check in the file auto.pl file as the new build.pl file
312
#   This may get ugly if the current config-spec does not have a rule to
399
#   This may get ugly if the current config-spec does not have a rule to
313
#   select the "new" build.pl file. This is often the case
400
#   select the "new" build.pl file. This is often the case
314
#
401
#
315
#   Examine the error output and discard these errors
402
#   Examine the error output and discard these errors
316
#
403
#
-
 
404
Verbose ("Check in build file: $opt_ofile" );
317
ClearCmd ("ci -c \"AutoBuilder checkin: $opt_label\" -identical -from \"$opt_infile\" \"$opt_ofile\"");
405
ClearCmd ('ci', '-c', "AutoBuilder checkin: $pkg_label", '-identical', '-from', $opt_infile, $opt_ofile);
318
Error ("Program Terminated") unless ( $last_result =~ m/Checked in "$opt_ofile" version/ );
406
Error ("Program Terminated") unless ( $last_result =~ m/Checked in "$opt_ofile" version/ );
319
 
407
 
320
@error_list = @delayed_error;
408
@error_list = @delayed_error;
321
Error ("Program Terminated") if ( @error_list );
409
Error ("Program Terminated") if ( @error_list );
322
 
410
 
-
 
411
#
-
 
412
#   Label the view
-
 
413
#
-
 
414
label_build_view();
-
 
415
 
323
exit 0;
416
exit 0;
324
 
417
 
325
#-------------------------------------------------------------------------------
418
#-------------------------------------------------------------------------------
-
 
419
# Function        : locate_build_directory
-
 
420
#
-
 
421
# Description     : Locate the build directory that contains the build files
-
 
422
#                   In an ANT build, this will e the root of the package
-
 
423
#                   Otherwise the build files may not be in the root directory
-
 
424
#
-
 
425
#
-
 
426
# Inputs          : Globals
-
 
427
#
-
 
428
# Returns         : Globals
-
 
429
#
-
 
430
sub locate_build_directory
-
 
431
{
-
 
432
    return unless ( $opt_locate );
-
 
433
 
-
 
434
    my $bscanner = BuildFileScanner ( '.', $opt_infile );
-
 
435
    my $count = $bscanner->locate();
-
 
436
 
-
 
437
    Error ("Autolocate. Build file not found: $opt_infile" )
-
 
438
        if ( $count <= 0 );
-
 
439
 
-
 
440
    #
-
 
441
    #   If multiple build files have been found
-
 
442
    #   Scan the buildfiles and determine the names of the packages that will
-
 
443
    #   be built. This can be used to generate nice error messages
-
 
444
    if ( $count > 1 )
-
 
445
    {
-
 
446
        $bscanner->scan();
-
 
447
        $count = $bscanner->match( $opt_locate );
-
 
448
 
-
 
449
        my $errmess;
-
 
450
        if ( $count <= 0 ) {
-
 
451
            $errmess = "None found that build package: $opt_locate";
-
 
452
 
-
 
453
        } elsif ( $count > 1 ) {
-
 
454
            $errmess = "Multiple build files build the required package: $opt_locate";
-
 
455
        }
-
 
456
 
-
 
457
        #
-
 
458
        #   Pretty error display
-
 
459
        #   Display build directory and the package name (mangled)
-
 
460
        #
-
 
461
        if ( $errmess )
-
 
462
        {
-
 
463
            Error ("Autolocate. Multiple build files found.",
-
 
464
                   $errmess,
-
 
465
                   "Build files found in:", $bscanner->formatData() );
-
 
466
        }
-
 
467
    }
-
 
468
 
-
 
469
    #
-
 
470
    #   Extract the required build file directory
-
 
471
    #
-
 
472
    my $dir = $bscanner->getMatchDir() || '';
-
 
473
    Verbose ("Autolocate. Found $count build files: $dir");
-
 
474
 
-
 
475
    #
-
 
476
    #   Select the one true build directory
-
 
477
    #
-
 
478
    if ( $dir ne '.' )
-
 
479
    {
-
 
480
        #
-
 
481
        #   Save the current directory for later
-
 
482
        #
-
 
483
        $root_dir = getcwd();
-
 
484
        chdir $dir || Error ("Cannot change directory: $dir");
-
 
485
    }
-
 
486
}
-
 
487
 
-
 
488
#-------------------------------------------------------------------------------
-
 
489
# Function        : determine_package_label
-
 
490
#
-
 
491
# Description     : Determine the label that is to be applied to the package
-
 
492
#                   There are several cases to consider
-
 
493
#                       1) Compatability mode: User provides label
-
 
494
#                       2) WIP Mode. Determine name of label to ise in rename
-
 
495
#                       3) Create a new label
-
 
496
#
-
 
497
# Inputs          : Globals
-
 
498
#
-
 
499
# Returns         : Globals
-
 
500
#                       $pkg_label
-
 
501
#
-
 
502
sub determine_package_label
-
 
503
{
-
 
504
 
-
 
505
    #
-
 
506
    #   Compatability mode
-
 
507
    #
-
 
508
    if ( $opt_label )
-
 
509
    {
-
 
510
        $pkg_label = $opt_label;
-
 
511
        return;
-
 
512
    }
-
 
513
 
-
 
514
    #
-
 
515
    #   Determine the desired label for the package
-
 
516
    #   This is a function of the package name and the package version
-
 
517
    #   The two are joined with a '.'
-
 
518
    #
-
 
519
    $tag_label = $opt_pname . '.' . $opt_pversion;
-
 
520
 
-
 
521
    #
-
 
522
    #   Ensure that desired label is "free", if not then hunt for a new one
-
 
523
    #   Determine the name of a 'new' label
-
 
524
    #
-
 
525
    my $base_label = $tag_label;
-
 
526
    my $index = 0;
-
 
527
 
-
 
528
    while ( ++$index )
-
 
529
    {
-
 
530
        if ( $index > 20 )
-
 
531
        {
-
 
532
            Error ("Cannot determine new label. Retry limit exceeded");
-
 
533
        }
-
 
534
        Verbose2 ("Trying $tag_label");
-
 
535
 
-
 
536
        unless (ClearCmd ('describe', '-short', "lbtype:$tag_label" ) )
-
 
537
        {
-
 
538
            #
-
 
539
            #   Label found - so try another
-
 
540
            #
-
 
541
            Verbose2("Label found. Try another");
-
 
542
            $tag_label = $base_label . '.' . $index;
-
 
543
            next;
-
 
544
        }
-
 
545
 
-
 
546
        #
-
 
547
        #   Warn about non standard label
-
 
548
        #
-
 
549
        Verbose ("Package will be labeled: $tag_label");
-
 
550
        Warning ("Labeling with a non-standard label: $tag_label" )
-
 
551
            if ( $index > 1 );
-
 
552
        last;
-
 
553
    }
-
 
554
 
-
 
555
    #
-
 
556
    #   Free label has been found
-
 
557
    #   Create it now, unless we are processing a WIP
-
 
558
    #
-
 
559
    unless ( $opt_wiplabel )
-
 
560
    {
-
 
561
        Verbose ("Creating new label: $tag_label");
-
 
562
        ClearCmd ('mklbtype', '-c', 'Autobuild Created', $tag_label );
-
 
563
        Error ("Cannot create new label: $tag_label" ) if ( @error_list );
-
 
564
 
-
 
565
        #
-
 
566
        #   Mark as created by this utility
-
 
567
        #   Label should be deleted on error
-
 
568
        #
-
 
569
        $label_created = $tag_label;
-
 
570
        $pkg_label = $tag_label;
-
 
571
    }
-
 
572
    else
-
 
573
    {
-
 
574
        $pkg_label = $opt_wiplabel;
-
 
575
    }
-
 
576
}
-
 
577
 
-
 
578
#-------------------------------------------------------------------------------
-
 
579
# Function        : label_build_view
-
 
580
#
-
 
581
# Description     : Label the view
-
 
582
#
-
 
583
#                   Either:
-
 
584
#                       Rename the WIP label to required name
-
 
585
#                       Label all files in the view
-
 
586
#                   
-
 
587
#                   Use JATS to do the hard work
-
 
588
#
-
 
589
#
-
 
590
# Inputs          : Globals
-
 
591
#
-
 
592
# Returns         : 
-
 
593
#
-
 
594
sub label_build_view
-
 
595
{
-
 
596
    #
-
 
597
    #   In compatability mode - do nothing
-
 
598
    #
-
 
599
    return if ( $opt_label );
-
 
600
 
-
 
601
    if ( $opt_wiplabel )
-
 
602
    {
-
 
603
        Verbose ("Rename label: From $opt_wiplabel to $tag_label");
-
 
604
        JatsCmd( 'label', '-unlock', $opt_wiplabel, '-rename', $tag_label, '-lock' );
-
 
605
    }
-
 
606
    else
-
 
607
    {
-
 
608
        Verbose ("Apply new label to package: $tag_label");
-
 
609
        #
-
 
610
        #   Need to return to the root directory to label the entire
-
 
611
        #   package, but only if we moved away from the root directory
-
 
612
        #
-
 
613
        if ( $root_dir )
-
 
614
        {
-
 
615
            chdir ( $root_dir ) || Error ("Cannot chdir to starting directory", $root_dir);
-
 
616
        }
-
 
617
 
-
 
618
        JatsCmd( 'label', '-label', $tag_label, '-replace', '-lock' );
-
 
619
    }
-
 
620
 
-
 
621
    #
-
 
622
    #   Write the label out to the specified file so that the user
-
 
623
    #   can do something with it
-
 
624
    #
-
 
625
    if ( $opt_infofile )
-
 
626
    {
-
 
627
 
-
 
628
        my $data = JatsProperties::New();
-
 
629
 
-
 
630
        $data->setProperty('Label', $tag_label);
-
 
631
        $data->setProperty('WipLabel', $opt_wiplabel ) if $opt_wiplabel;
-
 
632
        $data->setProperty('PackageName', $opt_pname);
-
 
633
        $data->setProperty('PackageVersion', $opt_pversion);
-
 
634
        $data->setProperty('clearcase.branch', $opt_branch);
-
 
635
 
-
 
636
        $data->Dump('InfoFile') if ($opt_verbose);
-
 
637
        $data->store( $opt_infofile );
-
 
638
    }
-
 
639
}
-
 
640
 
-
 
641
#-------------------------------------------------------------------------------
326
# Function        : ClearCmd
642
# Function        : ClearCmd
327
#
643
#
328
# Description     : Execute a ClearCase command and capture the reults
644
# Description     : Execute a ClearCase command and capture the reults
329
#                   Errors are held in one array
645
#                   Errors are held in one array
330
#                   Result are held in another
646
#                   Result are held in another
Line 333... Line 649...
333
#
649
#
334
# Returns         :
650
# Returns         :
335
#
651
#
336
sub ClearCmd
652
sub ClearCmd
337
{
653
{
338
    my( $cmd ) = @_;
654
    my $cmd = QuoteCommand (@_);
339
    Verbose2( "cleartool $cmd" );
655
    Verbose2( "cleartool $cmd" );
340
 
656
 
341
        @error_list = ();
657
        @error_list = ();
342
        @last_results = ();
658
        @last_results = ();
343
        $last_result = undef;
659
        $last_result = undef;
Line 348... Line 664...
348
            chomp;
664
            chomp;
349
            $last_result = $_;
665
            $last_result = $_;
350
            $last_result =~ tr~\\/~/~s;
666
            $last_result =~ tr~\\/~/~s;
351
            push @last_results, $last_result;
667
            push @last_results, $last_result;
352
 
668
 
353
            Verbose ( "cleartool resp:" . $_);
669
            Verbose2 ( "cleartool resp:" . $_);
354
            push @error_list, $_ if ( m~Error:~ );
670
            push @error_list, $_ if ( m~Error:~ );
355
        }
671
        }
356
        close(CMD);
672
        close(CMD);
357
 
673
 
358
    Verbose2( "Exit Status: $?" );
674
    Verbose2( "Exit Status: $?" );
Line 384... Line 700...
384
 
700
 
385
=pod
701
=pod
386
 
702
 
387
=head1 NAME
703
=head1 NAME
388
 
704
 
389
jats_save_build - Save a modified build.pl/depends.xml file into version control
705
jats_save_build - Save a build view to version control system
390
 
706
 
391
=head1 SYNOPSIS
707
=head1 SYNOPSIS
392
 
708
 
393
  jats etool jats_save_build [options]
709
  jats etool jats_save_build [options]
394
 
710
 
395
 Options:
711
 Options:
396
    -help               - brief help message
712
    -help[=n]           - brief help message
397
    -help -help         - Detailed help message
713
    -help -help         - Detailed help message
398
    -man                - Full documentation
714
    -man[=n]            - Full documentation
399
    -verbose            - Verbose operation
715
    -verbose[=n]        - Verbose operation
400
    -infile xxx         - Input file (auto.pl)
716
    -infile=xxx         - Input file (auto.pl)
401
    -outfile xxx        - Output file (build.pl)
717
    -outfile=xxx        - Output file (build.pl)
402
    -label xxx          - Label the new file (mandatory)
718
    -label xxx          - Label the new file (Compatability Mode)
403
    -branch xxx         - Branch to create (AutoBuilder)
719
    -branch=xxx         - Branch to create (AutoBuilder)
404
    -newbranch          - Force file to be on a new (project) branch
720
    -newbranch          - Force file to be on a new (project) branch
-
 
721
    -infofile=path      - Save label information in 'path'
-
 
722
    -pname=name         - Name of the package
-
 
723
    -pversion=text      - Package version
-
 
724
    -locatepkg=text     - Package locator string
-
 
725
    -wiplabel=text      - Current package WIP label
405
 
726
 
406
=head1 OPTIONS
727
=head1 OPTIONS
407
 
728
 
408
=over 8
729
=over 8
409
 
730
 
410
=item B<-help>
731
=item B<-help[=n]>
411
 
732
 
412
Print a brief help message and exits.
733
Print a brief help message and exits.
413
 
734
 
-
 
735
The verbosity of the help text can be controlled by setting the help level to a
-
 
736
number in the range of 1 to 3, or by invoking the option multiple times.
-
 
737
 
-
 
738
=item B<-man[=n]>
-
 
739
 
-
 
740
Without a numeric argument this is the same as -help=3. Full help will be
-
 
741
displayed.
-
 
742
 
-
 
743
With a numeric argument, this option is the same as -help=n.
-
 
744
 
414
=item B<-help -help>
745
=item B<-verbose[=n]>
-
 
746
 
-
 
747
This option will increase the level of verbosity of the utility.
-
 
748
 
-
 
749
If an argument is provided, then it will be used to set the level, otherwise the
-
 
750
existing level will be incremented. This option may be specified multiple times.
-
 
751
 
-
 
752
=item B<-infile=xxxx>
-
 
753
 
-
 
754
This option specifies the name of the generated build configuration file that
-
 
755
will be used as a data-source for the check-in build file.
-
 
756
 
-
 
757
The default file name is 'auto.pl'.
-
 
758
 
-
 
759
=item B<-outfile=xxxx>
-
 
760
 
-
 
761
This option specifies the name of the target build configuration file that
-
 
762
will be checked in to version-control. Data from from file specifies with '-
-
 
763
infile' will be used to update the file.
415
 
764
 
416
Print a detailed help message with an explanation for each option.
765
The default file name is 'build.pl'.
417
 
766
 
418
=item B<-man>
767
=item B<-label=xxxx>
419
 
768
 
-
 
769
This option is provided for backward compatability. If present then much of the
-
 
770
functionality of this utility will be supressed. The utility will only check-
-
 
771
in the modified build files. It will not:
-
 
772
 
-
 
773
=over 8
-
 
774
 
-
 
775
=item   Locate the build files
-
 
776
 
-
 
777
=item   Determine an available label
-
 
778
 
-
 
779
=item   Create the label
-
 
780
 
-
 
781
=item   Label the view
-
 
782
 
420
Prints the manual page and exits.
783
=item   Rename the WIP label
-
 
784
 
-
 
785
=item   Generate the information file
-
 
786
 
-
 
787
=back
-
 
788
 
-
 
789
=item B<-branch=xxxx>
-
 
790
 
-
 
791
This options specifies the root name of the target branch that will be sued to
-
 
792
contain the checked-in build file. If the branch does not exist it will be
-
 
793
created.
-
 
794
 
-
 
795
The default branch will be based on "AutoBuilder".
421
 
796
 
422
=item B<-newbranch>
797
=item B<-newbranch>
423
 
798
 
424
This option will force the file to be checked into a new branch
799
This option will force the file to be checked into a new branch
425
The branch will be created on /main/0 unless it is already found elsewhere
800
The branch will be created on /main/0 unless it is already found elsewhere
426
 
801
 
427
This option allows a build.pl file to be placed on a new project branch.
802
This option allows a build.pl file to be placed on a new project branch.
428
 
803
 
-
 
804
=item B<-infofile=path>
-
 
805
 
-
 
806
This option specifies a file that this utility will use to communicate with a
-
 
807
user script. It will write the new label text into the file.
-
 
808
 
-
 
809
The file path is relative to the current working directory.
-
 
810
 
-
 
811
The file will be deleted, and only created if the utility is successful.
-
 
812
 
-
 
813
=item B<-pname=name>
-
 
814
 
-
 
815
This option specifies the package name. It will be used to construct a new
-
 
816
label for the package.
-
 
817
 
-
 
818
=item B<-pversion=xxx>
-
 
819
 
-
 
820
This option specifies the package version. It will be used to construct a new
-
 
821
label for the package.
-
 
822
 
-
 
823
=item B<-locatepkg=text>
-
 
824
 
-
 
825
This option specifies a name, by which the package's build files may be located.
-
 
826
This is only needed for JATS builds and will only be used to resolve the
-
 
827
location of build files when a package contains multiple build files.
-
 
828
 
-
 
829
=item B<-wiplabel=text>
-
 
830
 
-
 
831
This option controls the manner in which this utility will label the build view.
-
 
832
 
-
 
833
If present, the label specifies a 'Work In Progress' label. The label will be
-
 
834
renamed.
-
 
835
 
-
 
836
If not present, then the view will be labeled with a new label.
-
 
837
 
429
=back
838
=back
430
 
839
 
431
=head1 DESCRIPTION
840
=head1 DESCRIPTION
432
 
841
 
433
This utility is used by the automated build system to place a modified build.pl
842
This utility is used by the automated build system to place build view under
434
or a depends.xml file under version control, and then place a label on the file.
843
version control. The utility will:
435
 
844
 
-
 
845
=over 8
-
 
846
 
-
 
847
=item * Determine a suitable label for the package
-
 
848
 
-
 
849
The label is constructed from the package name and the package version. The
436
The utility will place the "new" build.pl file on a named branch of the branch
850
utility will ensure that the label does not already exist. If it does it will
-
 
851
use an alternate form of the label.
-
 
852
 
-
 
853
=item * Determine a suitable branch name for the build files
-
 
854
 
-
 
855
The modified build file is placed on a file-branch.
-
 
856
 
-
 
857
=item * Locate the build files within the package
-
 
858
 
-
 
859
JATS build files do not need to be at the root of the package. The utility
437
that contains the current build.pl file.
860
will locate the JATS build files.
438
 
861
 
-
 
862
=item * Update the build files and save them into the version control system
-
 
863
 
439
If the build.pl file is sourced from a different branch then a Merge arrow
864
The build file will be updated with new version information as provided by a
-
 
865
secondary configuration file.
-
 
866
 
440
will be created to indicate where the file and its label was taken from.
867
The updated file will be checked into version control. It will be placed on a
-
 
868
branch so as not to affect dynamic views.
441
 
869
 
442
The operation will fail if that file is checked out "reserved". The program
870
The operation will fail if that file is checked out "reserved". The program
443
can work around this - but its not done yet.
871
can work around this - but its not done yet.
444
 
872
 
-
 
873
If the build file is sourced from a different branch then a Merge arrow
-
 
874
will be created to indicate where the file and its label was taken from.   
-
 
875
 
-
 
876
=item * Ensure that the package is labeled
-
 
877
 
-
 
878
The build view will be labeled.
-
 
879
 
-
 
880
If a WIP label is provided then the label will be applied to the modified
-
 
881
build file and then the label will be renamed.
-
 
882
 
-
 
883
If a WIP label is not provided, then the entire package will be labeled with a
-
 
884
suitable label.
-
 
885
 
-
 
886
=item * Return the label to the user
-
 
887
 
-
 
888
The label used to label the package will be returned to the user in an 'info'
-
 
889
file. This is a 'properties' file. The following properties are defined:
-
 
890
 
-
 
891
=over 8
-
 
892
 
-
 
893
=item   1) Label - The label used to tag the file
-
 
894
 
-
 
895
=item   3) WipLabel - The WIP label provided (optional)
-
 
896
 
-
 
897
=item   4) PackageName - The package name
-
 
898
 
-
 
899
=item   5) PackageVersion - The package version
-
 
900
 
-
 
901
=back
-
 
902
 
-
 
903
=back
-
 
904
 
445
=cut
905
=cut
446
 
906