Subversion Repositories DevTools

Rev

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