Subversion Repositories DevTools

Rev

Rev 309 | Rev 353 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
267 dpurdie 1
########################################################################
2
# Copyright ( C ) 2008 ERG Limited, All rights reserved
3
#
4
# Module name   : jats_svnasave_build.pl
5
# Module type   : JATS Utility
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Build Daemon Support Utility
10
#                 This utility will:
341 dpurdie 11
#                   +   Assume the CWD is where the build file is located
12
#                   +   Within a version controlled view
267 dpurdie 13
#                   +   Determine a suitable label for the package
14
#                   +   Save the build file in the view
15
#                   +   Label the resultant view
16
#
17
# Usage:        : See POD at end of this file
18
#
19
#               jats etool  jats_svnasave_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)
341 dpurdie 26
#                   -baselabel  View label
267 dpurdie 27
#
28
#......................................................................#
29
 
30
use strict;
31
use warnings;
32
use JatsError;
33
use JatsBuildFiles;
34
use JatsSystem;
35
use JatsProperties;
36
use Getopt::Long;
37
use Pod::Usage;                             # required for help support
38
use File::Copy;
39
use JatsSvn;
40
use Cwd;
41
 
42
################################################################################
43
#   Option variables
44
#
45
 
46
my $VERSION = "2.0.0";                      # Update this
47
my $opt_debug   = $ENV{'GBE_DEBUG'};        # Allow global debug
48
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
49
my $opt_infile  = "auto.pl";
50
my $opt_ofile = "build.pl";
51
my $opt_help = 0;
52
my $opt_infofile;
53
my $opt_pname;
54
my $opt_pversion;
55
my $opt_wiplabel;
341 dpurdie 56
my $opt_baselabel;
267 dpurdie 57
 
58
#
59
#   Globals
60
#
61
my $root_dir;
62
my $pkg_label;
63
my $tag_label;
64
 
65
my $ws_root;
66
my $pkg_root;
67
 
68
#
69
#   Configuration options
70
#
71
my $result = GetOptions (
72
                "help:+"        => \$opt_help,              # flag, multiple use allowed
73
                "manual:3"      => \$opt_help,              # flag
74
                "verbose:+"     => \$opt_verbose,           # flag
75
 
76
                "outfile=s"     => \$opt_ofile,             # string
77
                "infile=s"      => \$opt_infile,            # string
78
 
79
                "infofile=s"    => \$opt_infofile,          # string
80
                "pname=s"       => \$opt_pname,             # string
81
                "pversion=s"    => \$opt_pversion,          # string
82
                "wiplabel=s"    => \$opt_wiplabel,          # string
341 dpurdie 83
                "baselabel=s"   => \$opt_baselabel,         # string
267 dpurdie 84
 
85
                #
86
                #   Update documentation at the end of the file
87
                #
88
                );
89
 
90
#
91
#   Process help and manual options
92
#
93
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
94
pod2usage(-verbose => 1)  if ( $opt_help == 2 );
95
pod2usage(-verbose => 2)  if ( $opt_help > 2 );
96
 
97
#
98
#   Configure the error reporting process now that we have the user options
99
#
100
ErrorConfig( 'name'    =>'SVNABTSAVE',
101
             'verbose' => $opt_verbose,
102
           );
103
 
104
Error ("Input and output file are the same: $opt_infile" )
105
    if ( $opt_infile eq $opt_ofile );
106
 
341 dpurdie 107
Error ("Base Label not provided")
108
    unless ( $opt_baselabel );
109
 
267 dpurdie 110
Error ("Package Name not provided")
111
    unless ( $opt_pname );
112
 
113
Error ("Package Version not provided")
114
    unless ( $opt_pversion );
115
 
116
Warning("Path to info file not provided")
117
    unless ( $opt_infofile );
118
 
119
unlink ($opt_infofile) if $opt_infofile;
120
 
121
#
341 dpurdie 122
#   User must have changed to the directory with build files
267 dpurdie 123
#   Continue with user argument sanity check
124
#
125
Error ("Input file not found: $opt_infile" )
126
    unless ( -f $opt_infile );
127
 
128
Error ("Output file not found: $opt_ofile" )
129
    unless ( -f $opt_ofile );
130
 
131
 
132
#
133
#   Create a SubVersion Session using the current workspace
134
#   as a basis. Error if not a workspace
135
#
136
my $session = NewSessionByWS( '.' );
137
 
138
Verbose ("Determine the current workspace root" );
139
$ws_root = $session->SvnLocateWsRoot(1) || '';
140
$pkg_root = $session->Full;
141
 
142
Verbose ("Workspace root: $ws_root");
143
Verbose ("Package root  : $pkg_root");
144
 
145
#
146
#   Determine the desired label for the package
147
#   May need to pick an unassigned label
148
#
149
determine_package_label();
150
 
151
#
152
#   Update the build file
153
#   Under subversion this is a simple 'copy'
154
#
155
Verbose ("Update build files");
156
unlink $opt_ofile;
157
unless ( File::Copy::copy($opt_infile, $opt_ofile) )
158
{
159
    Error("Failed to copy file [$opt_infile] to [$opt_ofile]: $!");
160
    Error ("Updating build files","Reason: $!");
161
}
162
 
163
#
164
#   Change back to original directory
165
#
166
if ( $root_dir )
167
{
168
    chdir $root_dir || Error ("Cannot change directory: $root_dir");
169
}
170
 
171
#
172
#   Label the view
173
#
174
label_build_view();
175
 
176
exit 0;
177
 
178
#-------------------------------------------------------------------------------
179
# Function        : determine_package_label
180
#
181
# Description     : Determine the label that is to be applied to the package
182
#                   There are several cases to consider
183
#                       1) Compatability mode: User provides label
184
#                       2) WIP Mode. Determine name of label to use in rename
185
#                       3) Create a new label
186
#
187
# Inputs          : Globals
188
#
189
# Returns         : Globals
190
#                       $pkg_label
191
#
192
sub determine_package_label
193
{
194
 
195
    #
196
    #   Determine the desired label for the package
197
    #   This is a function of the package name and the package version
198
    #   The two are joined with a '.'
199
    #
200
    $tag_label = $opt_pname . '_' . $opt_pversion;
201
 
202
    #
203
    #   Ensure that desired label is "free", if not then hunt for a new one
204
    #   Determine the name of a 'new' label
205
    #
206
    my $base_label = $tag_label;
207
    my $index = 0;
208
 
209
    while ( ++$index )
210
    {
211
        if ( $index > 20 )
212
        {
213
            Error ("Cannot determine new label. Retry limit exceeded");
214
        }
215
        Verbose2 ("Trying $tag_label");
216
 
217
        if ( $session->SvnValidateTarget (
218
                    'target' => $session->BranchName($tag_label, 'tags' ),
219
                    'test' => 1,
220
                    ))
221
        {
222
            #
223
            #   Label found - so try another
224
            #
225
            Verbose2("Label found. Try another");
226
            $tag_label = $base_label . '.' . $index;
227
            next;
228
        }
229
 
230
        #
231
        #   Warn about non standard label
232
        #
233
        Verbose ("Package will be labeled: $tag_label");
234
        Warning ("Labeling with a non-standard label: $tag_label" )
235
            if ( $index > 1 );
236
        last;
237
    }
238
 
239
    #
240
    #   Free label has been found
241
    #
242
    unless ( $opt_wiplabel )
243
    {
244
        $pkg_label = $tag_label;
245
    }
246
    else
247
    {
248
        $pkg_label = $opt_wiplabel;
249
    }
250
}
251
 
252
#-------------------------------------------------------------------------------
253
# Function        : label_build_view
254
#
255
# Description     : Label the view
256
#
257
#                   Either:
258
#                       Rename the WIP label to required name
259
#                       Label all files in the view
260
#                   
261
#                   Use JATS to do the hard work
262
#
263
#
264
# Inputs          : Globals
265
#
266
# Returns         : 
267
#
268
sub label_build_view
269
{
270
    #
271
    #   Save the current workspace - with its modified build file
272
    #
273
    Verbose ("Apply new label to package: $tag_label");
274
    $session->SvnCopyWs (
275
               'target'   => $session->BranchName($tag_label, 'tags' ),
276
               'modified' => $opt_ofile,
277
               'noswitch' => 1,
278
               'replace'  => 0,
279
               'comment'  => 'Created by Jats SaveBuild',
280
               );
281
    Message ("Repository Ref: " . $session->RmRef);
282
 
283
    if ( $opt_wiplabel )
284
    {
285
        #
286
        #   If the build is based on a WIP, then we can delete the
287
        #   WIP if its based on a branch
288
        #
289
        if ( $session->WsType eq 'branches' )
290
        {
291
            $session->SvnDelete(
292
                    'target'  => $session->FullWs,
293
                    'comment' => ["Deleted by Jats SaveBuild","Replaced by: $tag_label"],
294
                    'noerror' => 1,
295
                     );
296
        }
297
        else
298
        {
299
            Message ("WIP not deleted.","Will not delete WIPS based on a :" . $session->WsType );
300
        }
301
    }
302
 
303
    #
304
    #   Write the label out to the specified file so that the user
305
    #   can do something with it
306
    #
307
    if ( $opt_infofile )
308
    {
309
 
310
        my $data = JatsProperties::New();
311
 
312
        $data->setProperty('Label', $tag_label);
313
        $data->setProperty('WipLabel', $opt_wiplabel ) if $opt_wiplabel;
314
        $data->setProperty('PackageName', $opt_pname);
315
        $data->setProperty('PackageVersion', $opt_pversion);
316
        $data->setProperty('subversion.tag', $session->RmRef);
341 dpurdie 317
        $data->setProperty('VCS.tag', 'SVN::' . $session->RmRef);
267 dpurdie 318
 
319
        $data->Dump('InfoFile') if ($opt_verbose);
320
        $data->store( $opt_infofile );
321
    }
322
}
323
 
324
#-------------------------------------------------------------------------------
325
#   Documentation
326
#
327
 
328
=pod
329
 
330
=head1 NAME
331
 
332
jats_svnsave_build - Save a build view to version control system
333
 
334
=head1 SYNOPSIS
335
 
336
  jats etool jats_save_build [options]
337
 
338
 Options:
339
    -help[=n]           - brief help message
340
    -help -help         - Detailed help message
341
    -man[=n]            - Full documentation
342
    -verbose[=n]        - Verbose operation
343
    -infile=xxx         - Input file (auto.pl)
344
    -outfile=xxx        - Output file (build.pl)
345
    -infofile=path      - Save label information in 'path'
346
    -pname=name         - Name of the package
347
    -pversion=text      - Package version
348
    -wiplabel=text      - Current package WIP label
341 dpurdie 349
    -baselabel=text     - Base label for sandbox
267 dpurdie 350
 
351
=head1 OPTIONS
352
 
353
=over 8
354
 
355
=item B<-help[=n]>
356
 
357
Print a brief help message and exits.
358
 
359
The verbosity of the help text can be controlled by setting the help level to a
360
number in the range of 1 to 3, or by invoking the option multiple times.
361
 
362
=item B<-man[=n]>
363
 
364
Without a numeric argument this is the same as -help=3. Full help will be
365
displayed.
366
 
367
With a numeric argument, this option is the same as -help=n.
368
 
369
=item B<-verbose[=n]>
370
 
371
This option will increase the level of verbosity of the utility.
372
 
373
If an argument is provided, then it will be used to set the level, otherwise the
374
existing level will be incremented. This option may be specified multiple times.
375
 
376
=item B<-infile=xxxx>
377
 
378
This option specifies the name of the generated build configuration file that
379
will be used as a data-source for the check-in build file.
380
 
381
The default file name is 'auto.pl'.
382
 
383
=item B<-outfile=xxxx>
384
 
385
This option specifies the name of the target build configuration file that
386
will be checked in to version-control. Data from from file specifies with '-
387
infile' will be used to update the file.
388
 
389
The default file name is 'build.pl'.
390
 
391
=item B<-infofile=path>
392
 
393
This option specifies a file that this utility will use to communicate with a
394
user script. It will write the new label text into the file.
395
 
396
The file path is relative to the current working directory.
397
 
398
The file will be deleted, and only created if the utility is successful.
399
 
400
=item B<-pname=name>
401
 
402
This option specifies the package name. It will be used to construct a new
403
label for the package.
404
 
405
=item B<-pversion=xxx>
406
 
407
This option specifies the package version. It will be used to construct a new
408
label for the package.
409
 
410
=item B<-wiplabel=text>
411
 
412
This option controls the manner in which this utility will label the build view.
413
 
414
If present, the label specifies a 'Work In Progress' label. The label will be
415
renamed. At the end of the process the wip label will be deleted from the
416
the repository.
417
 
418
If not present, then the view will be labeled with a new label.
419
 
341 dpurdie 420
=item B<-baselabel=text>
421
 
422
This option specifies the Version Control Label that the current workspace
423
is based on. This may be used to determine the new label for the package.
424
 
425
This parameter is mandatory.
426
 
267 dpurdie 427
=back
428
 
429
=head1 DESCRIPTION
430
 
431
This utility is used by the automated build system to place build view under
432
version control. The utility will:
433
 
434
=over 8
435
 
436
=item * Determine a suitable label for the package
437
 
438
The label is constructed from the package name and the package version. The
439
utility will ensure that the label does not already exist. If it does it will
440
use an alternate form of the label.
441
 
442
=item * Locate the build files within the package
443
 
444
JATS build files do not need to be at the root of the package. The utility
445
will locate the JATS build files.
446
 
447
=item * Update the build files and save them into the version control system
448
 
449
The build file will be updated with new version information as provided by a
450
secondary configuration file.
451
 
452
The updated file will be checked into version control.
453
 
454
=item * Ensure that the package is labeled
455
 
456
The build view will be labeled (tagged).
457
 
458
If a WIP label is provided then the WIP label will be removed if it is a branch.
459
 
460
=item * Return the label to the user
461
 
462
The label used to label the package will be returned to the user in an 'info'
463
file. This is a 'properties' file. The following properties are defined:
464
 
465
=over 8
466
 
467
=item   1) Label - The label used to tag the file
468
 
469
=item   3) WipLabel - The WIP label provided (optional)
470
 
471
=item   4) PackageName - The package name
472
 
473
=item   5) PackageVersion - The package version
474
 
475
=back
476
 
477
=back
478
 
479
=cut
480