Subversion Repositories DevTools

Rev

Rev 363 | Rev 1403 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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