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