| 6887 |
dpurdie |
1 |
########################################################################
|
|
|
2 |
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
|
|
|
3 |
#
|
|
|
4 |
# Module name : cc2svn_gen_cots.pl
|
|
|
5 |
# Module type : Makefile system
|
|
|
6 |
# Compiler(s) : Perl
|
|
|
7 |
# Environment(s): jats
|
|
|
8 |
#
|
|
|
9 |
# Description : Create a buildable package based on a COTS package
|
|
|
10 |
# or other package image.
|
|
|
11 |
#
|
|
|
12 |
# Designed to simplify the process of version controlling
|
|
|
13 |
# handcrafted packages that have been dropped into dpkg_archive
|
|
|
14 |
#
|
|
|
15 |
# Supports clearcase and subversion
|
|
|
16 |
#
|
|
|
17 |
# Usage: See Embedded documentation below
|
|
|
18 |
# jats gen_cots ...
|
|
|
19 |
#
|
|
|
20 |
# Kludge to help create packages to import into SVN
|
|
|
21 |
#
|
|
|
22 |
#......................................................................#
|
|
|
23 |
|
|
|
24 |
require 5.006_001;
|
|
|
25 |
use Cwd;
|
|
|
26 |
use strict;
|
|
|
27 |
use warnings;
|
|
|
28 |
use JatsError;
|
|
|
29 |
use FileUtils;
|
|
|
30 |
use File::Basename;
|
|
|
31 |
use File::Find;
|
|
|
32 |
use File::Copy;
|
|
|
33 |
use File::Path;
|
|
|
34 |
use JatsSvn qw(:All);
|
|
|
35 |
use JatsSystem;
|
|
|
36 |
use JatsProperties;
|
|
|
37 |
use File::Temp qw/ tempfile tempdir /;
|
|
|
38 |
|
|
|
39 |
use Pod::Usage; # required for help support
|
|
|
40 |
use Getopt::Long;
|
|
|
41 |
use Cwd;
|
|
|
42 |
|
|
|
43 |
#-------------------------------------------------------------------------------
|
|
|
44 |
# Global variables
|
|
|
45 |
#
|
|
|
46 |
my $VERSION = "1.0.0"; # Update this
|
|
|
47 |
my $GBE_DPKG = $ENV{ GBE_DPKG };
|
|
|
48 |
my %subdirs;
|
|
|
49 |
my %files;
|
|
|
50 |
my $DESTDIR = 'src'; # 'src'
|
|
|
51 |
my $last_result;
|
|
|
52 |
my @error_list;
|
|
|
53 |
my $vob_dir = '';
|
|
|
54 |
my $vob_name = '';
|
|
|
55 |
my $src_dir;
|
|
|
56 |
|
|
|
57 |
my $svnSession;
|
|
|
58 |
my $svnPackageName;
|
|
|
59 |
my $svnPackageExists;
|
|
|
60 |
my $svnRmRef = '';
|
|
|
61 |
|
|
|
62 |
#
|
|
|
63 |
# Options
|
|
|
64 |
#
|
|
|
65 |
my $opt_debug = $ENV{'GBE_DEBUG'}; # Allow global debug
|
|
|
66 |
my $opt_verbose = $ENV{'GBE_VERBOSE'}; # Allow global verbose
|
|
|
67 |
my $opt_help = 0;
|
|
|
68 |
my $opt_manual = 0;
|
|
|
69 |
my $opt_label;
|
|
|
70 |
my $opt_vob;
|
|
|
71 |
my $opt_test;
|
|
|
72 |
my $opt_keep = 1;
|
|
|
73 |
my $opt_subdir;
|
|
|
74 |
my $opt_image;
|
|
|
75 |
my $opt_repository;
|
|
|
76 |
my $opt_destDir;
|
|
|
77 |
|
|
|
78 |
#-------------------------------------------------------------------------------
|
|
|
79 |
# Function : Mainline Entry Point
|
|
|
80 |
#
|
|
|
81 |
# Description : Parse Options
|
|
|
82 |
# Perform Sanity Checks
|
|
|
83 |
# Perform operation
|
|
|
84 |
# Cleanup
|
|
|
85 |
#
|
|
|
86 |
# Inputs : Command Line arguments
|
|
|
87 |
#
|
|
|
88 |
my $result = GetOptions (
|
|
|
89 |
"help+" => \$opt_help, # flag, multiple use allowed
|
|
|
90 |
"manual" => \$opt_manual, # flag
|
|
|
91 |
"verbose:+" => \$opt_verbose, # flag, multiple use allowed
|
|
|
92 |
"label=s" => \$opt_label, # String
|
|
|
93 |
"vob=s" => \$opt_vob, # String
|
|
|
94 |
"test" => \$opt_test, # Flag
|
|
|
95 |
"keep" => \$opt_keep, # Flag
|
|
|
96 |
"subdir=s" => \$opt_subdir, # string
|
|
|
97 |
"image=s" => \$opt_image, # string
|
|
|
98 |
"repository=s" => \$opt_repository, # string
|
|
|
99 |
"dest=s" => \$opt_destDir,
|
|
|
100 |
);
|
|
|
101 |
|
|
|
102 |
#
|
|
|
103 |
# UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
|
|
|
104 |
#
|
|
|
105 |
|
|
|
106 |
#
|
|
|
107 |
# Process help and manual options
|
|
|
108 |
#
|
|
|
109 |
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
|
|
|
110 |
pod2usage(-verbose => 1) if ($opt_help == 2 );
|
|
|
111 |
pod2usage(-verbose => 2) if ($opt_manual || ($opt_help > 2));
|
|
|
112 |
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ( $#ARGV < 0 );
|
|
|
113 |
|
|
|
114 |
#
|
|
|
115 |
# Configure the error reporting process now that we have the user options
|
|
|
116 |
#
|
|
|
117 |
ErrorConfig( 'name' =>'gen_cots',
|
|
|
118 |
'verbose' => $opt_verbose,
|
|
|
119 |
);
|
|
|
120 |
|
|
|
121 |
#
|
|
|
122 |
# Init the file uitilites
|
|
|
123 |
#
|
|
|
124 |
InitFileUtils();
|
|
|
125 |
|
|
|
126 |
#
|
|
|
127 |
# Sanity test user options
|
|
|
128 |
#
|
|
|
129 |
Error ("Can only specify either -vob or -repository.") if ( $opt_vob && $opt_repository );
|
|
|
130 |
Error ("ClearCase mode only supported on WINDOWS, not $::ScmHost") if ( $opt_vob && $::ScmHost ne 'WIN' );
|
|
|
131 |
Error ("No DPK_ARCHIVE") unless ( $GBE_DPKG );
|
|
|
132 |
Error ("Must specify -vob, -repository or -keep") unless ( $opt_vob || $opt_repository || $opt_keep);
|
|
|
133 |
Error ("Need two arguments: package and version") unless ( $#ARGV eq 1 );
|
|
|
134 |
|
|
|
135 |
#
|
|
|
136 |
# Determine base image
|
|
|
137 |
# Either from dpkg_archive or user image
|
|
|
138 |
#
|
|
|
139 |
if ( $opt_image )
|
|
|
140 |
{
|
|
|
141 |
$src_dir = AbsPath($opt_image);
|
|
|
142 |
Error("Image directory is not present: $src_dir") unless ( -d $src_dir );
|
|
|
143 |
}
|
|
|
144 |
else
|
|
|
145 |
{
|
|
|
146 |
#
|
|
|
147 |
# Ensure that the package source in dpkg_archive can be found
|
|
|
148 |
#
|
|
|
149 |
$src_dir = "$GBE_DPKG/$ARGV[0]/$ARGV[1]";
|
|
|
150 |
Message ( "Testing $src_dir" );
|
|
|
151 |
Error ("Package not found: $src_dir" ) unless ( -d $src_dir );
|
|
|
152 |
Message ("Found source package");
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
#
|
|
|
156 |
# Determine target path with the VOB/Repository
|
|
|
157 |
# Will be taken from the package name, unless provided
|
|
|
158 |
#
|
|
|
159 |
$opt_subdir = $ARGV[0] unless ( $opt_subdir );
|
|
|
160 |
$opt_subdir =~ tr~\\/~/~s;
|
|
|
161 |
|
|
|
162 |
#
|
|
|
163 |
# Create a TEMP working area
|
|
|
164 |
# Needs to work on both Unix and Windows
|
|
|
165 |
#
|
|
|
166 |
my $dest_root;
|
|
|
167 |
my $dest_dir;
|
|
|
168 |
if ( $opt_destDir )
|
|
|
169 |
{
|
|
|
170 |
$dest_root = $opt_destDir;
|
|
|
171 |
$dest_dir = join('/', $dest_root, join('_',$ARGV[0],$ARGV[1]));
|
|
|
172 |
}
|
|
|
173 |
else
|
|
|
174 |
{
|
|
|
175 |
$dest_root = tempdir( 'GenCots_XXXX',TMPDIR => 1, CLEANUP => !$opt_keep );
|
|
|
176 |
$dest_dir = "$dest_root/$opt_subdir";
|
|
|
177 |
}
|
|
|
178 |
Message ("Work Dir: $dest_dir");
|
|
|
179 |
Error( "Temp Directory not found: $dest_root") unless ( -d $dest_root);
|
|
|
180 |
Error( "Temp Workspace should not exist: $dest_dir") if ( -d $dest_dir);
|
|
|
181 |
|
|
|
182 |
#
|
|
|
183 |
# Generate a label, if the user has not already specified one
|
|
|
184 |
#
|
|
|
185 |
if ( $opt_vob || $opt_repository )
|
|
|
186 |
{
|
|
|
187 |
$opt_label = "$ARGV[0]_$ARGV[1]"
|
|
|
188 |
unless ( $opt_label );
|
|
|
189 |
Verbose ("Label: $opt_label");
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
#
|
|
|
193 |
# Ensure VOBS/REPO and Labels are good
|
|
|
194 |
#
|
|
|
195 |
ClearCaseValidate() if ($opt_vob);
|
|
|
196 |
SubversionValidate() if ($opt_repository);
|
|
|
197 |
|
|
|
198 |
#
|
|
|
199 |
# Generate the package to be retained
|
|
|
200 |
# Create jats build files and copy of required data
|
|
|
201 |
#
|
|
|
202 |
generatePackage();
|
|
|
203 |
|
|
|
204 |
#
|
|
|
205 |
# Transfer the image into the target VCS System
|
|
|
206 |
#
|
|
|
207 |
ClearCaseImport() if ($opt_vob);
|
|
|
208 |
SubversionImport() if ($opt_repository);
|
|
|
209 |
|
|
|
210 |
#
|
|
|
211 |
# Remove the created directory
|
|
|
212 |
#
|
|
|
213 |
if ( $opt_keep )
|
|
|
214 |
{
|
|
|
215 |
Warning ("KEEP temp directory: $dest_root");
|
|
|
216 |
}
|
|
|
217 |
else
|
|
|
218 |
{
|
|
|
219 |
Message ("Delete temp directory");
|
|
|
220 |
rmtree( $dest_root );
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
#
|
|
|
224 |
# All done
|
|
|
225 |
# Report data to the user to use in Release Manager
|
|
|
226 |
#
|
|
|
227 |
if ( $opt_vob || $opt_repository )
|
|
|
228 |
{
|
|
|
229 |
Message ("\n");
|
|
|
230 |
Message ("Release Manager information");
|
|
|
231 |
if ( $opt_vob )
|
|
|
232 |
{
|
|
|
233 |
Message ("Package path : /$vob_name/$opt_subdir");
|
|
|
234 |
Message ("Label : $opt_label");
|
|
|
235 |
Message ("VCS Tag : CC::/${vob_name}/${opt_subdir}::${opt_label}");
|
|
|
236 |
}
|
|
|
237 |
else
|
|
|
238 |
{
|
|
|
239 |
$svnRmRef =~ m~(.*)::(.*)~;
|
|
|
240 |
my $rmPath = $1 || 'Unknown';
|
|
|
241 |
my $rmTag = $2 || 'Unknown';
|
|
|
242 |
|
|
|
243 |
Message ("Source Path : $rmPath");
|
|
|
244 |
Message ("Tag : $rmTag");
|
|
|
245 |
Message ("VCS Tag : SVN::$svnRmRef");
|
|
|
246 |
}
|
|
|
247 |
|
|
|
248 |
Warning ("Test Mode: Not Version Control System changes made") if ( $opt_test );
|
|
|
249 |
}
|
|
|
250 |
exit 0;
|
|
|
251 |
|
|
|
252 |
#-------------------------------------------------------------------------------
|
|
|
253 |
# Function : generatePackage
|
|
|
254 |
#
|
|
|
255 |
# Description : Craete a jats build package
|
|
|
256 |
#
|
|
|
257 |
#
|
|
|
258 |
# Inputs : All global
|
|
|
259 |
#
|
|
|
260 |
# Returns :
|
|
|
261 |
#
|
|
|
262 |
sub generatePackage
|
|
|
263 |
{
|
|
|
264 |
#
|
|
|
265 |
# Transfer source to target and remove generated files
|
|
|
266 |
#
|
|
|
267 |
mkpath ($dest_dir,$opt_verbose);
|
|
|
268 |
Error( "Cannot create target directory") unless ( -d $dest_dir);
|
|
|
269 |
|
|
|
270 |
Message ("Transfer package to local directory");
|
|
|
271 |
File::Find::find( \&CopyDir, $src_dir );
|
|
|
272 |
|
|
|
273 |
#
|
|
|
274 |
# Create a build.pl file based on a template
|
|
|
275 |
#
|
|
|
276 |
Message ("Create build.pl");
|
|
|
277 |
open (BUILD, ">", "$dest_dir/build.pl" );
|
|
|
278 |
while ( <DATA> )
|
|
|
279 |
{
|
|
|
280 |
chomp;
|
|
|
281 |
last if ( /^__ENDBUILD/ );
|
|
|
282 |
|
|
|
283 |
#
|
|
|
284 |
# Substitute values
|
|
|
285 |
#
|
|
|
286 |
s~__PACKAGENAME__~$ARGV[0]~g;
|
|
|
287 |
s~__PACKAGEVERSION__~$ARGV[1]~g;
|
|
|
288 |
if ( m/__BUILDNAME__/ )
|
|
|
289 |
{
|
|
|
290 |
if ( $ARGV[1] =~ m~^\d+\.\d+\.\d+[\s.]+(\w+)$~ )
|
|
|
291 |
{
|
|
|
292 |
print BUILD "BuildName ( '$ARGV[0]', '$ARGV[1]' );\n";
|
|
|
293 |
}
|
|
|
294 |
elsif ( $ARGV[1] =~ m~^(.*)\.+(\D+)$~ )
|
|
|
295 |
{
|
|
|
296 |
my $ver = $1;
|
|
|
297 |
my $prj = $2;
|
|
|
298 |
print BUILD "BuildName ( '$ARGV[0]', '$ver', '$prj', '--RelaxedVersion' );\n";
|
|
|
299 |
}
|
|
|
300 |
else
|
|
|
301 |
{
|
|
|
302 |
print BUILD "BuildName ( '$ARGV[0]', '$ARGV[1]', '--RelaxedVersion' );\n";
|
|
|
303 |
print "Buildname: '$ARGV[0]', '$ARGV[1]'\n";
|
|
|
304 |
}
|
|
|
305 |
|
|
|
306 |
next;
|
|
|
307 |
}
|
|
|
308 |
|
|
|
309 |
print BUILD "$_\n";
|
|
|
310 |
}
|
|
|
311 |
close (BUILD);
|
|
|
312 |
|
|
|
313 |
#
|
|
|
314 |
# Create a makefile.pl based on a template
|
|
|
315 |
#
|
|
|
316 |
Message ("Create src/makefile.pl");
|
|
|
317 |
mkdir "$dest_dir/src";
|
|
|
318 |
open (MAKE, ">", "$dest_dir/src/makefile.pl" );
|
|
|
319 |
while ( <DATA> )
|
|
|
320 |
{
|
|
|
321 |
chomp;
|
|
|
322 |
last if ( /^__ENDMAKE/ );
|
|
|
323 |
|
|
|
324 |
#
|
|
|
325 |
# Substitute values
|
|
|
326 |
#
|
|
|
327 |
s~__PACKAGENAME__~$ARGV[0]~g;
|
|
|
328 |
s~__PACKAGEVERSION__~$ARGV[1]~g;
|
|
|
329 |
if ( /__PACKAGEFILE__/ )
|
|
|
330 |
{
|
|
|
331 |
unless ( $DESTDIR )
|
|
|
332 |
{
|
|
|
333 |
foreach my $file ( sort keys %files )
|
|
|
334 |
{
|
|
|
335 |
|
|
|
336 |
print MAKE "PackageFile ( '*', '../$file', '--StripDir' );\n";
|
|
|
337 |
}
|
|
|
338 |
} else {
|
|
|
339 |
foreach my $file ( sort keys %files )
|
|
|
340 |
{
|
|
|
341 |
|
|
|
342 |
print MAKE "PackageFile ( '*', '$file' );\n";
|
|
|
343 |
}
|
|
|
344 |
}
|
|
|
345 |
foreach my $subdir ( sort keys %subdirs )
|
|
|
346 |
{
|
|
|
347 |
print MAKE "PackageFile ( '*', '--DirTree=$subdir' );\n";
|
|
|
348 |
}
|
|
|
349 |
next;
|
|
|
350 |
}
|
|
|
351 |
print MAKE "$_\n";
|
|
|
352 |
}
|
|
|
353 |
close (MAKE);
|
|
|
354 |
}
|
|
|
355 |
|
|
|
356 |
#-------------------------------------------------------------------------------
|
|
|
357 |
# Function : CopyDir
|
|
|
358 |
#
|
|
|
359 |
# Description : Find callback function used to copy the archive
|
|
|
360 |
#
|
|
|
361 |
# Inputs :
|
|
|
362 |
#
|
|
|
363 |
# Returns :
|
|
|
364 |
#
|
|
|
365 |
sub CopyDir
|
|
|
366 |
{
|
|
|
367 |
my $item = $File::Find::name;
|
|
|
368 |
my $base = File::Basename::basename($item);
|
|
|
369 |
|
|
|
370 |
#
|
|
|
371 |
# Skip generated files
|
|
|
372 |
#
|
|
|
373 |
return if ( $base =~ m/^descpkg$/ );
|
|
|
374 |
return if ( $base =~ m/^RELEASE_NOTES_/ );
|
|
|
375 |
return if ( $base =~ m/^built\./ );
|
|
|
376 |
|
|
|
377 |
#
|
|
|
378 |
# Don't process directories
|
|
|
379 |
#
|
|
|
380 |
return if ( -d $item );
|
|
|
381 |
|
|
|
382 |
#
|
|
|
383 |
# Calculate target directory
|
|
|
384 |
#
|
|
|
385 |
my $sdl = length ($src_dir);
|
|
|
386 |
my $target = $dest_dir . '/' . $DESTDIR . substr ( $item, $sdl );
|
|
|
387 |
|
|
|
388 |
#
|
|
|
389 |
# Determinate top level package directories
|
|
|
390 |
#
|
|
|
391 |
my $rootdir = substr ( $item, 1 + $sdl );
|
|
|
392 |
$rootdir =~ s~/.*~~;
|
|
|
393 |
|
|
|
394 |
if ( $rootdir eq $base )
|
|
|
395 |
{
|
|
|
396 |
$files{$base} = 1;
|
|
|
397 |
} else {
|
|
|
398 |
$subdirs{$rootdir} = 1;
|
|
|
399 |
}
|
|
|
400 |
|
|
|
401 |
my $tdir = $target;
|
|
|
402 |
$tdir =~ s~/[^/]+$~~;
|
|
|
403 |
|
|
|
404 |
# print "================$item, $base, $tdir, $target, $rootdir\n";
|
|
|
405 |
|
|
|
406 |
mkpath ($tdir, 0) unless ( -d $tdir );
|
|
|
407 |
|
|
|
408 |
Verbose( "Transfer: $target");
|
|
|
409 |
File::Copy::copy( "$item", "$target") || Error("Copy Fault: $item, $target");
|
|
|
410 |
|
|
|
411 |
}
|
|
|
412 |
|
|
|
413 |
#-------------------------------------------------------------------------------
|
|
|
414 |
# Function : ClearCaseValidate
|
|
|
415 |
#
|
|
|
416 |
# Description : Validate the ClearCase VOB and label
|
|
|
417 |
#
|
|
|
418 |
# Inputs : Globals
|
|
|
419 |
#
|
|
|
420 |
# Returns : Nothing
|
|
|
421 |
#
|
|
|
422 |
sub ClearCaseValidate
|
|
|
423 |
{
|
|
|
424 |
#
|
|
|
425 |
# Validate / locate the target VOB
|
|
|
426 |
#
|
|
|
427 |
locate_vob();
|
|
|
428 |
|
|
|
429 |
#
|
|
|
430 |
# Ensure that the label is not locked
|
|
|
431 |
# The user will not be able to move the label if it is already locked
|
|
|
432 |
#
|
|
|
433 |
my $label_exists = 0;
|
|
|
434 |
Verbose ("Check label exists");
|
|
|
435 |
ClearCmd ("describe -short lbtype:$opt_label@/$vob_name" ) unless $opt_test;
|
|
|
436 |
$label_exists = 1 unless( $opt_test || grep ( /Label type not found/, @error_list ));
|
|
|
437 |
Verbose ("Check label: $label_exists");
|
|
|
438 |
|
|
|
439 |
if ( $label_exists )
|
|
|
440 |
{
|
|
|
441 |
Verbose ("Check label not locked");
|
|
|
442 |
ClearCmd ("describe -fmt %[locked]p lbtype:$opt_label@/$vob_name" );
|
|
|
443 |
unless ( $last_result && $last_result =~ m~unlocked~ )
|
|
|
444 |
{
|
|
|
445 |
Error("Label is locked: $opt_label");
|
|
|
446 |
}
|
|
|
447 |
}
|
|
|
448 |
}
|
|
|
449 |
|
|
|
450 |
#-------------------------------------------------------------------------------
|
|
|
451 |
# Function : SubversionValidate
|
|
|
452 |
#
|
|
|
453 |
# Description : Validate the Subversion Repository and label
|
|
|
454 |
#
|
|
|
455 |
# Inputs : Globals
|
|
|
456 |
#
|
|
|
457 |
# Returns : Nothing
|
|
|
458 |
#
|
|
|
459 |
sub SubversionValidate
|
|
|
460 |
{
|
|
|
461 |
#
|
|
|
462 |
# Ensure that the created label will be acceptable
|
|
|
463 |
#
|
|
|
464 |
$opt_label = SvnIsaSimpleLabel ($opt_label);
|
|
|
465 |
|
|
|
466 |
#
|
|
|
467 |
# Prevent the user from creating paths that are too deep
|
|
|
468 |
# Don't want repos that contain hidden packages
|
|
|
469 |
#
|
|
|
470 |
Error ("Created repository structure will be too deep")
|
|
|
471 |
if ( ($opt_subdir =~ tr~/~~) >= 2 );
|
|
|
472 |
|
|
|
473 |
#
|
|
|
474 |
# Create a subversion session
|
|
|
475 |
# Ensure that the repository exists
|
|
|
476 |
#
|
|
|
477 |
$svnPackageName = $opt_repository . '/' . $opt_subdir;
|
|
|
478 |
$svnSession = NewSessionByUrl ( $svnPackageName, 0 );
|
|
|
479 |
my $rv = $svnSession->SvnValidateTarget (
|
|
|
480 |
'target' => $svnSession->Full(),
|
|
|
481 |
'test' => 1,
|
|
|
482 |
);
|
|
|
483 |
if ( $rv )
|
|
|
484 |
{
|
|
|
485 |
#
|
|
|
486 |
# Package exists within the Repo
|
|
|
487 |
# Ensure its a valid package
|
|
|
488 |
$svnSession->SvnValidatePackageRoot();
|
|
|
489 |
$svnPackageExists = 1;
|
|
|
490 |
|
|
|
491 |
$rv = $svnSession->SvnValidateTarget (
|
|
|
492 |
'target' => $svnSession->BranchName( $opt_label, 'tags' ),
|
|
|
493 |
'test' => 1,
|
|
|
494 |
);
|
|
|
495 |
if ( $rv )
|
|
|
496 |
{
|
|
|
497 |
Warning ("Target label already exists in the repository",
|
|
|
498 |
"It will be replaced" );
|
|
|
499 |
}
|
|
|
500 |
}
|
|
|
501 |
}
|
|
|
502 |
|
|
|
503 |
#-------------------------------------------------------------------------------
|
|
|
504 |
# Function : ClearCaseImport
|
|
|
505 |
#
|
|
|
506 |
# Description : Import the generated package into ClearCase
|
|
|
507 |
# Label and all
|
|
|
508 |
# The clearcase command will adjust the target directory
|
|
|
509 |
# to match the source
|
|
|
510 |
#
|
|
|
511 |
# Inputs :
|
|
|
512 |
#
|
|
|
513 |
# Returns :
|
|
|
514 |
#
|
|
|
515 |
sub ClearCaseImport
|
|
|
516 |
{
|
|
|
517 |
|
|
|
518 |
#
|
|
|
519 |
# Determine the target directory within the VOB
|
|
|
520 |
# This is the source directory tree, with the last element removed
|
|
|
521 |
#
|
|
|
522 |
my $target_path = "";
|
|
|
523 |
if ( $opt_subdir =~ m~/~ )
|
|
|
524 |
{
|
|
|
525 |
$target_path = $opt_subdir;
|
|
|
526 |
$target_path =~ s~/[^/]*$~~;
|
|
|
527 |
$target_path = '/' . $target_path;
|
|
|
528 |
}
|
|
|
529 |
|
|
|
530 |
Message ("Import to clearcase vob: $opt_vob");
|
|
|
531 |
my $cmd = "clearfsimport.exe -nsetevent -rec -rmname";
|
|
|
532 |
$cmd .= " -preview" if $opt_test;
|
|
|
533 |
$cmd .= " -mklabel $opt_label";
|
|
|
534 |
$cmd .= " -c \"Package snapshot $ARGV[0]_$ARGV[1]\"";
|
|
|
535 |
$cmd .= " $dest_dir $opt_vob$target_path";
|
|
|
536 |
|
|
|
537 |
Verbose($cmd);
|
|
|
538 |
@error_list = ();
|
|
|
539 |
open(CMD, "$cmd 2>&1 |") || Error( "can't run command: $!");
|
|
|
540 |
while (<CMD>)
|
|
|
541 |
{
|
|
|
542 |
#
|
|
|
543 |
# Filter output from the user
|
|
|
544 |
#
|
|
|
545 |
chomp;
|
|
|
546 |
Verbose($_);
|
|
|
547 |
push @error_list, $_ if ( m~Error:~ );
|
|
|
548 |
}
|
|
|
549 |
close(CMD);
|
|
|
550 |
if ( @error_list )
|
|
|
551 |
{
|
|
|
552 |
ReportError ($_) foreach ( @error_list );
|
|
|
553 |
Error("Problem encountered saving package image");
|
|
|
554 |
}
|
|
|
555 |
|
|
|
556 |
#
|
|
|
557 |
# Apply label to all directories upto the root of the VOB
|
|
|
558 |
# The label will have been applied to the TIP
|
|
|
559 |
#
|
|
|
560 |
Verbose ("Label package path");
|
|
|
561 |
my $lpath = $opt_vob;
|
|
|
562 |
foreach ( split ('/', $target_path) )
|
|
|
563 |
{
|
|
|
564 |
$lpath = $lpath . '/' . $_;
|
|
|
565 |
Verbose ("Label package path: $lpath");
|
|
|
566 |
ClearCmd ("mklabel -replace $opt_label $lpath" ) unless $opt_test;
|
|
|
567 |
Error ("Program Terminated") if ( @error_list );
|
|
|
568 |
}
|
|
|
569 |
|
|
|
570 |
#
|
|
|
571 |
# Lock the label
|
|
|
572 |
#
|
|
|
573 |
Message ("Locking label: $opt_label");
|
|
|
574 |
ClearCmd ("lock lbtype:$opt_label\@/$vob_name" ) unless $opt_test;
|
|
|
575 |
Error ("Program Terminated") if ( @error_list );
|
|
|
576 |
}
|
|
|
577 |
|
|
|
578 |
#-------------------------------------------------------------------------------
|
|
|
579 |
# Function : SubversionImport
|
|
|
580 |
#
|
|
|
581 |
# Description : Import the generated package into Subversion
|
|
|
582 |
# Label and all
|
|
|
583 |
#
|
|
|
584 |
# Inputs :
|
|
|
585 |
#
|
|
|
586 |
# Returns :
|
|
|
587 |
#
|
|
|
588 |
sub SubversionImport
|
|
|
589 |
{
|
|
|
590 |
return if ( $opt_test );
|
|
|
591 |
|
|
|
592 |
unless ($svnPackageExists)
|
|
|
593 |
{
|
|
|
594 |
#
|
|
|
595 |
# Create the package if it does not already exist
|
|
|
596 |
# This is the simple process
|
|
|
597 |
#
|
|
|
598 |
$svnSession->{PRINTDATA} = 0;
|
|
|
599 |
$svnSession->SvnCreatePackage (
|
|
|
600 |
'import' => $dest_dir,
|
|
|
601 |
'label' => $opt_label,
|
|
|
602 |
'new' => 1,
|
|
|
603 |
'printdata' => $opt_verbose,
|
|
|
604 |
);
|
|
|
605 |
$svnRmRef = $svnSession->SvnTag();
|
|
|
606 |
}
|
|
|
607 |
else
|
|
|
608 |
{
|
|
|
609 |
#
|
|
|
610 |
# Package exists
|
|
|
611 |
# Hard bit: Need to merge the existing trunk with this version
|
|
|
612 |
# and label the entire lot
|
|
|
613 |
# We already have a program to do that.
|
|
|
614 |
#
|
|
|
615 |
my $workdir = "$dest_root/SvnImport";
|
|
|
616 |
my $datafile = "$dest_root/svnData.txt";
|
|
|
617 |
my $rv = JatsTool ('jats_svn', 'import',
|
|
|
618 |
"-package=$svnPackageName",
|
|
|
619 |
"-dir=$dest_dir",
|
|
|
620 |
"-label=$opt_label",
|
|
|
621 |
"-datafile=$datafile",
|
|
|
622 |
"workspace=$workdir",
|
|
|
623 |
"-replace",
|
|
|
624 |
"-printfiles=$opt_verbose"
|
|
|
625 |
);
|
|
|
626 |
if ( $rv )
|
|
|
627 |
{
|
|
|
628 |
Error ("Error importing package");
|
|
|
629 |
}
|
|
|
630 |
|
|
|
631 |
if ( -f $datafile )
|
|
|
632 |
{
|
|
|
633 |
my $rmData = JatsProperties::New($datafile);
|
|
|
634 |
$svnRmRef = $rmData->getProperty('subversion.tag');
|
|
|
635 |
}
|
|
|
636 |
}
|
|
|
637 |
unless ( $svnRmRef )
|
|
|
638 |
{
|
|
|
639 |
Error ('Failed to determin RM Reference');;
|
|
|
640 |
}
|
|
|
641 |
}
|
|
|
642 |
|
|
|
643 |
#-------------------------------------------------------------------------------
|
|
|
644 |
# Function : locate_vob
|
|
|
645 |
#
|
|
|
646 |
# Description : Locate the target VOB
|
|
|
647 |
# This is a bit tricky as it makes a few assumptions
|
|
|
648 |
# 1) That clearcase dynamic views are mounted through the "o" drive
|
|
|
649 |
# This appears to be a standard(ish) configuration.
|
|
|
650 |
#
|
|
|
651 |
# 2) There must be a dynamic view on the machine that does have the
|
|
|
652 |
# required VOB mounted
|
|
|
653 |
#
|
|
|
654 |
# Note: Assumes that the user is NOT trying to place the package
|
|
|
655 |
# into a subdir of the VOB.
|
|
|
656 |
#
|
|
|
657 |
# Inputs : None
|
|
|
658 |
#
|
|
|
659 |
# Returns : Global: $opt_vob
|
|
|
660 |
#
|
|
|
661 |
|
|
|
662 |
sub locate_vob
|
|
|
663 |
{
|
|
|
664 |
#
|
|
|
665 |
# If the user has specified an absolute path then use the users VOB
|
|
|
666 |
#
|
|
|
667 |
$opt_vob =~ tr~\\/~/~s;
|
|
|
668 |
if ( $opt_vob =~ m~[A-Za-z]\:/~ || $opt_vob =~ m~/~ )
|
|
|
669 |
{
|
|
|
670 |
Error ("User VOB does not exist: $opt_vob") unless ( -d $opt_vob );
|
|
|
671 |
|
|
|
672 |
$opt_vob =~ m~(.*/)(.*)~;
|
|
|
673 |
$vob_dir = $1;
|
|
|
674 |
$vob_name = $2;
|
|
|
675 |
return;
|
|
|
676 |
}
|
|
|
677 |
|
|
|
678 |
#
|
|
|
679 |
# Scan for a dynamic view
|
|
|
680 |
#
|
|
|
681 |
Message ("Scanning for suitable dynamic view");
|
|
|
682 |
my @search_list = glob ("O:/*");
|
|
|
683 |
my $found_vob;
|
|
|
684 |
foreach my $dir ( @search_list )
|
|
|
685 |
{
|
|
|
686 |
my $test_vob = "$dir/$opt_vob";
|
|
|
687 |
Verbose ("Testing vob: $test_vob" );
|
|
|
688 |
next if ( $dir =~ m~solaris~i ); # Take the hint
|
|
|
689 |
next if ( $dir =~ '/administration_view$' ); # Known read-only VOB
|
|
|
690 |
|
|
|
691 |
if ( -d $test_vob )
|
|
|
692 |
{
|
|
|
693 |
$found_vob = $dir;
|
|
|
694 |
last;
|
|
|
695 |
}
|
|
|
696 |
}
|
|
|
697 |
Error ("Cannot find a suitable view with the $opt_vob VOB mounted") unless ( $found_vob );
|
|
|
698 |
|
|
|
699 |
$vob_dir = $found_vob;
|
|
|
700 |
$vob_name = $opt_vob;
|
|
|
701 |
$opt_vob = "$vob_dir/$vob_name";
|
|
|
702 |
Message ("Using VOB: $opt_vob");
|
|
|
703 |
}
|
|
|
704 |
|
|
|
705 |
#-------------------------------------------------------------------------------
|
|
|
706 |
# Function : ClearCmd
|
|
|
707 |
#
|
|
|
708 |
# Description : Similar to the system command
|
|
|
709 |
# Does allow standard output and standard error to be captured
|
|
|
710 |
# to a log file
|
|
|
711 |
#
|
|
|
712 |
# Used since I was having problems with calling other programs
|
|
|
713 |
# and control-C. It could hang the terminal session.
|
|
|
714 |
#
|
|
|
715 |
# Inputs :
|
|
|
716 |
#
|
|
|
717 |
# Returns :
|
|
|
718 |
#
|
|
|
719 |
sub ClearCmd
|
|
|
720 |
{
|
|
|
721 |
my( $cmd ) = @_;
|
|
|
722 |
Verbose2 "cleartool $cmd";
|
|
|
723 |
|
|
|
724 |
@error_list = ();
|
|
|
725 |
open(CMD, "cleartool $cmd 2>&1 |") || Error "can't run command: $!";
|
|
|
726 |
while (<CMD>)
|
|
|
727 |
{
|
|
|
728 |
chomp;
|
|
|
729 |
$last_result = $_;
|
|
|
730 |
Verbose ( "cleartool resp:" . $_);
|
|
|
731 |
push @error_list, $_ if ( m~Error:~ );
|
|
|
732 |
}
|
|
|
733 |
close(CMD);
|
|
|
734 |
|
|
|
735 |
Verbose2 "Exit Status: $?";
|
|
|
736 |
return $? / 256;
|
|
|
737 |
}
|
|
|
738 |
|
|
|
739 |
########################################################################
|
|
|
740 |
#
|
|
|
741 |
# The following text contains two templates used in the creation
|
|
|
742 |
# of a build.pl and a makefile.pl
|
|
|
743 |
#
|
|
|
744 |
# The text is read and keywords are processed
|
|
|
745 |
#
|
|
|
746 |
|
|
|
747 |
__DATA__
|
|
|
748 |
########################################################################
|
|
|
749 |
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
|
|
|
750 |
#
|
|
|
751 |
# Module name : build.pl
|
|
|
752 |
# Module type : JATS Build File
|
|
|
753 |
# Environment(s): JATS Build System
|
|
|
754 |
#
|
|
|
755 |
# Description: build.pl for package __PACKAGENAME__
|
|
|
756 |
#.........................................................................#
|
|
|
757 |
|
|
|
758 |
#.. Build system
|
|
|
759 |
#
|
|
|
760 |
$MAKELIB_PL = "$ENV{ GBE_TOOLS }/makelib.pl";
|
|
|
761 |
$BUILDLIB_PL = "$ENV{ GBE_TOOLS }/buildlib.pl";
|
|
|
762 |
|
|
|
763 |
require "$BUILDLIB_PL";
|
|
|
764 |
require "$MAKELIB_PL";
|
|
|
765 |
|
|
|
766 |
#.. Product configuration
|
|
|
767 |
#
|
|
|
768 |
BuildPlatforms ( 'GENERIC' );
|
|
|
769 |
|
|
|
770 |
__BUILDNAME__ BuildName ( '__PACKAGENAME__', '__PACKAGEVERSION__' );
|
|
|
771 |
BuildInterface ( 'interface' );
|
|
|
772 |
|
|
|
773 |
#
|
|
|
774 |
# Specify subdirectories to process
|
|
|
775 |
#
|
|
|
776 |
BuildSubDir ( 'src' );
|
|
|
777 |
|
|
|
778 |
#
|
|
|
779 |
# Generate Files
|
|
|
780 |
BuildDescpkg ();
|
|
|
781 |
BuildMake ();
|
|
|
782 |
__ENDBUILD
|
|
|
783 |
########################################################################
|
|
|
784 |
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
|
|
|
785 |
#
|
|
|
786 |
# Module name : Makefile.pl
|
|
|
787 |
# Module type : JATS Make File
|
|
|
788 |
# Environment(s): JATS Build System
|
|
|
789 |
#
|
|
|
790 |
# Description: makefile.pl for package __PACKAGENAME__
|
|
|
791 |
#
|
|
|
792 |
#.........................................................................#
|
|
|
793 |
|
|
|
794 |
die "Usage: Makefile.pl rootdir Makelib.pl\n"
|
|
|
795 |
unless( $#ARGV+1 >= 2 );
|
|
|
796 |
require "$ARGV[1]";
|
|
|
797 |
|
|
|
798 |
#
|
|
|
799 |
# Build platform definitions ..
|
|
|
800 |
#
|
|
|
801 |
Platform( '*' );
|
|
|
802 |
|
|
|
803 |
############################################################################
|
|
|
804 |
# Define the source files
|
|
|
805 |
#
|
|
|
806 |
|
|
|
807 |
#.............................................................................
|
|
|
808 |
# Packaging definitions
|
|
|
809 |
#
|
|
|
810 |
__PACKAGEFILE__ PackageFile ( '*', '--DirTree=jar' );
|
|
|
811 |
|
|
|
812 |
#..
|
|
|
813 |
#
|
|
|
814 |
PackageFile ( '*' , 'descpkg' );
|
|
|
815 |
|
|
|
816 |
#.............................................................................
|
|
|
817 |
# Finally generate the makefile
|
|
|
818 |
#
|
|
|
819 |
MakefileGenerate();
|
|
|
820 |
|
|
|
821 |
#.. Successful termination
|
|
|
822 |
1;
|
|
|
823 |
__ENDMAKE
|
|
|
824 |
|
|
|
825 |
#-------------------------------------------------------------------------------
|
|
|
826 |
# Documentation
|
|
|
827 |
#
|
|
|
828 |
|
|
|
829 |
=pod
|
|
|
830 |
|
|
|
831 |
=head1 NAME
|
|
|
832 |
|
|
|
833 |
gen_cots - Create a buildable package from dpkg_archive and place it under
|
|
|
834 |
version control
|
|
|
835 |
|
|
|
836 |
=head1 SYNOPSIS
|
|
|
837 |
|
|
|
838 |
jats gen_cots package version [-vob=aa|-repo=aa|-keep]
|
|
|
839 |
|
|
|
840 |
Options:
|
|
|
841 |
-help - brief help message
|
|
|
842 |
-help -help - Detailed help message
|
|
|
843 |
-man - Full documentation
|
|
|
844 |
-vob=vvv - VOB to use, may be a full path.
|
|
|
845 |
-repository=path - Subversion Repository
|
|
|
846 |
-keep - Keep the creating dpkg_archive image
|
|
|
847 |
-label=name - Specify a label for the versions source
|
|
|
848 |
-subdir=nnn - Named subdir in VOB
|
|
|
849 |
-test - Do not perform operations that modify Version Control
|
|
|
850 |
-image=path - Path to alternate source image
|
|
|
851 |
-dest=path - Output location
|
|
|
852 |
|
|
|
853 |
=head1 OPTIONS
|
|
|
854 |
|
|
|
855 |
=over 8
|
|
|
856 |
|
|
|
857 |
=item B<-help>
|
|
|
858 |
|
|
|
859 |
Print a brief help message and exits.
|
|
|
860 |
|
|
|
861 |
=item B<-help -help>
|
|
|
862 |
|
|
|
863 |
Print a detailed help message with an explanation for each option.
|
|
|
864 |
|
|
|
865 |
=item B<-man>
|
|
|
866 |
|
|
|
867 |
Prints the manual page and exits.
|
|
|
868 |
|
|
|
869 |
=item B<-label=name>
|
|
|
870 |
|
|
|
871 |
This option specifies an alternate label for the checked in source. The
|
|
|
872 |
default label is based on package and version.
|
|
|
873 |
|
|
|
874 |
=item B<-vob=vvv>
|
|
|
875 |
|
|
|
876 |
This option invokes the ClearCase mode of operation. The generated code
|
|
|
877 |
will be checked into ClearCase. This is only available under Windows.
|
|
|
878 |
|
|
|
879 |
This option specifies the VOB into which the saved package will be placed.
|
|
|
880 |
|
|
|
881 |
There are two ways that this option may be used.
|
|
|
882 |
|
|
|
883 |
=over 8
|
|
|
884 |
|
|
|
885 |
=item 1
|
|
|
886 |
|
|
|
887 |
Simply name the VOB. (ie: COTS) The script will locate a dynamic view on the
|
|
|
888 |
users machine that contains the view. This is done by scanning dynamic views in
|
|
|
889 |
the "O:" drive.
|
|
|
890 |
|
|
|
891 |
=item 2
|
|
|
892 |
|
|
|
893 |
The full path to a VOB, including driver is provided. (ie: z:/COTS). This will
|
|
|
894 |
prevent the script from locating the VOB. It will use the named view.
|
|
|
895 |
|
|
|
896 |
=back
|
|
|
897 |
|
|
|
898 |
=item B<-repository=path>
|
|
|
899 |
|
|
|
900 |
This option invokes the Subversion mode of operation. The generated code
|
|
|
901 |
will be checked into Subversion.
|
|
|
902 |
|
|
|
903 |
The argument is the path to the base of the package. The package name
|
|
|
904 |
will be appended by this program.
|
|
|
905 |
|
|
|
906 |
=item B<-keep>
|
|
|
907 |
|
|
|
908 |
If this option is selected then the program will retain the working directory
|
|
|
909 |
that it has created.
|
|
|
910 |
|
|
|
911 |
If neither -vob or -repository is used, then this option must be provided.
|
|
|
912 |
|
|
|
913 |
=item B<-subdir=name>
|
|
|
914 |
|
|
|
915 |
This option specifies the name of a subdirectory in which the package will be created.
|
|
|
916 |
The default name it taken from the package name.
|
|
|
917 |
|
|
|
918 |
=item B<-test>
|
|
|
919 |
|
|
|
920 |
This option will suppress the Version Control operations.
|
|
|
921 |
No files will be checked in and the label will not be locked.
|
|
|
922 |
|
|
|
923 |
=item B<-image=path>
|
|
|
924 |
|
|
|
925 |
If this option is specified then the package will be created using the
|
|
|
926 |
specified source path, otherwise the package will be extracted from dpkg_archive.
|
|
|
927 |
|
|
|
928 |
This option allows a locally created image to be stored as a COTS package
|
|
|
929 |
before it is placed in dpkg_archive.
|
|
|
930 |
|
|
|
931 |
=back
|
|
|
932 |
|
|
|
933 |
=head1 DESCRIPTION
|
|
|
934 |
|
|
|
935 |
This program will create a version controlled and JATS buildable package from
|
|
|
936 |
a dpkg_archive package version.
|
|
|
937 |
|
|
|
938 |
In doing this the program will:
|
|
|
939 |
|
|
|
940 |
=over 8
|
|
|
941 |
|
|
|
942 |
=item *
|
|
|
943 |
|
|
|
944 |
Create a temporary directory in the users current directory. This will
|
|
|
945 |
be used to contain a copy of the package.
|
|
|
946 |
|
|
|
947 |
=item *
|
|
|
948 |
|
|
|
949 |
Transfer the named package and version into the temp directory. The files will
|
|
|
950 |
be transferred in the a 'src' directory within the temp directory.
|
|
|
951 |
|
|
|
952 |
=item *
|
|
|
953 |
|
|
|
954 |
Create JATS build.pl and makefile.pls to support the creation of the
|
|
|
955 |
package. The build.pl file will contain the package name and the package
|
|
|
956 |
version.
|
|
|
957 |
|
|
|
958 |
=item *
|
|
|
959 |
|
|
|
960 |
Transfer the entire image into the named ClearCase VOB or Subversion Repository.
|
|
|
961 |
The files will be labeled and the Version Control System target modified to
|
|
|
962 |
mimic the temp directory view.
|
|
|
963 |
|
|
|
964 |
=item *
|
|
|
965 |
|
|
|
966 |
Lock the label used to mark the files (ClearCase Only).
|
|
|
967 |
|
|
|
968 |
=item *
|
|
|
969 |
|
|
|
970 |
Remove the temp work space.
|
|
|
971 |
|
|
|
972 |
=item *
|
|
|
973 |
|
|
|
974 |
Display information to be entered into Release Manager.
|
|
|
975 |
|
|
|
976 |
=back
|
|
|
977 |
|
|
|
978 |
=head1 EXAMPLE
|
|
|
979 |
|
|
|
980 |
=head2 ClearCase
|
|
|
981 |
|
|
|
982 |
jats etool gen_cots -vob=z:/COTS mos_api 5.6.0.cr
|
|
|
983 |
|
|
|
984 |
This will take the version 5.6.0.cr of the mos_api package from dpkg_archive
|
|
|
985 |
place it under version control within the COTS vob and add files to allow the
|
|
|
986 |
dpkg_archive package to be recreated in an JATS buildable manner.
|
|
|
987 |
|
|
|
988 |
=head2 Subversion
|
|
|
989 |
|
|
|
990 |
jats etool gen_cots -repository=AUPERASVN01/COTS mos_api 5.6.0.cr
|
|
|
991 |
|
|
|
992 |
This will take the version 5.6.0.cr of the mos_api package from dpkg_archive
|
|
|
993 |
place it under version control within the COTS Repository and add files to allow
|
|
|
994 |
the dpkg_archive package to be recreated in an JATS buildable manner.
|
|
|
995 |
|
|
|
996 |
=cut
|
|
|
997 |
|