Subversion Repositories DevTools

Rev

Rev 361 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
341 dpurdie 1
########################################################################
2
# Copyright (C) 1998-2010 VIX-ERG Limited, All rights reserved
3
#
4
# Module name   : jats_ccmerge_build
5
# Module type   : JATS Utility
6
# Environment(s): JATS
7
#
8
# Description   : A script to merge a build.pl from an autobuilder branch back
9
#                 to the main line.
10
#                 a build.
11
#
12
#......................................................................#
13
 
14
require 5.006_001;
15
use strict;
16
use warnings;
17
use JatsError;
18
use JatsSystem;
19
use FileUtils;
20
 
21
use Pod::Usage;                             # required for help support
22
use Getopt::Long;
23
use File::Copy;
24
use Cwd;
25
 
26
my $VERSION = "1.5.5";                      # Update this
27
 
28
#
29
#   Options
30
#
31
my $opt_debug   = $ENV{'GBE_DEBUG'};        # Allow global debug
32
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
33
my $opt_help = 0;
34
 
35
#
36
#   Global Data
37
#
38
my $UNIX = $ENV{'GBE_UNIX'};
39
my @error_list;
40
my $last_result;
41
my @last_results;
42
 
43
#-------------------------------------------------------------------------------
44
# Function        : Mainline Entry Point
45
#
46
# Description     :
47
#
48
# Inputs          :
49
#
50
 
51
#
52
#   Parse the user options
53
#
54
my $result = GetOptions (
55
                "help|h:+"          => \$opt_help,
56
                "manual:3"          => \$opt_help,
57
                "verbose|v:+"       => \$opt_verbose,           # flag, multiple use allowed
58
                );
59
 
60
                #
61
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
62
                #
63
 
64
#
65
#   Process help and manual options
66
#
67
pod2usage(-verbose => 0, -message => "Version: $VERSION")
68
    if ($opt_help == 1 || ! $result || $#ARGV >= 0);
69
pod2usage(-verbose => 1)  if ($opt_help == 2 );
70
pod2usage(-verbose => 2)  if ($opt_help > 2);
71
 
72
#
73
#   Configure the error reporting process now that we have the user options
74
#
75
ErrorConfig( 'name'    => 'MERGBUILD',
76
             'verbose' => $opt_verbose );
77
 
78
#
79
#   Only for windows
80
#
81
Error ("This program only works under Windows")
82
    if ( $UNIX );
83
 
84
#
85
#   Determine the branch of the build.pl file
86
#
87
Error ("No build.pl file found" )
88
    unless ( -f 'build.pl' );
89
 
90
ClearCmd ('describe', '-fmt', '%Sn', 'build.pl' );
91
Error ('Can\'t describe build.pl', @error_list) if @error_list;
92
Error ('build.pl may be hijacked. It is not a Vob Object') unless ( $last_result );
93
my $branch = $last_result;
94
Verbose ("Branch: $branch");
95
 
96
#
97
#   Determine parent branch
98
#
99
my @parts = split( '/', $branch );
100
Error ("Build.pl is not on an AutoBuilder Branch." )
101
    unless ( $parts[-2] =~ m~^AutoBuilder\.~ );
102
my $parent = join ('/', @parts[0 .. $#parts - 2]);
103
Verbose "Parent Branch: $parent\n";
104
 
105
#
106
#   Checkout the build.pl file on the parent branch
107
#
108
File::Copy::copy( 'build.pl', 'build.pl.merge' );
109
ClearCmd ('co', '-unreserved', '-c', 'Merged back from AutoBuild', '-ndata', 'build.pl@@'.$parent.'/LATEST');
110
Error ('Can\'t checkout build.pl', @error_list) if @error_list;
111
 
112
#
113
#   Draw a merge link to show what has been done
114
#
115
Verbose ("Creating Hyperlink" );
116
my $source_name = 'build.pl@@'.$branch;
117
my $target_name = 'build.pl@@'.$parent.'/CHECKEDOUT';
118
ClearCmd ('mkhlink', 'Merge', $source_name, $target_name);
119
Warning ('Can\'t create merge arrows', @error_list) if @error_list;
120
 
121
#
122
#   Copy in the base build.pl file and make it writable
123
#
124
Verbose ('Copy original build.pl file');
125
File::Copy::move( 'build.pl.merge', 'build.pl' );
126
chmod( 0755, 'build.pl' );
127
 
128
exit 0;
129
 
130
#-------------------------------------------------------------------------------
131
# Function        : ClearCmd
132
#
133
# Description     : Execute a ClearCase command and capture the results
134
#                   Errors are held in one array
135
#                   Result are held in another
136
#
137
# Inputs          :
138
#
139
# Returns         :
140
#
141
sub ClearCmd
142
{
143
    my $cmd = QuoteCommand (@_);
144
    Verbose2( "cleartool $cmd" );
145
 
146
        @error_list = ();
147
        @last_results = ();
148
        $last_result = undef;
149
 
150
        open(CMD, "cleartool $cmd  2>&1 |")    || Error( "can't run command: $!" );
151
        while (<CMD>)
152
        {
153
            chomp;
154
            $last_result = $_;
155
            $last_result =~ tr~\\/~/~s;
156
            push @last_results, $last_result;
157
 
158
            Verbose2 ( "cleartool resp:" . $_);
159
            push @error_list, $_ if ( m~Error:~ );
160
        }
161
        close(CMD);
162
 
163
    Verbose2( "Exit Status: $?" );
164
    return $? / 256;
165
}
166
 
167
#-------------------------------------------------------------------------------
168
#   Documentation
169
#
170
 
171
=pod
172
 
173
=head1 NAME
174
 
175
jats_ccmerge_build - Merge autobuilt build.pl file to parent branch
176
 
177
=head1 SYNOPSIS
178
 
179
  jats jats_ccmerge_build [options]
180
 
181
 Options:
182
    -help              - brief help message
183
    -help -help        - Detailed help message
184
    -man[=n]           - Full documentation
185
    -verbose[=n]       - Control program verbosity
186
 
187
=head1 OPTIONS
188
 
189
=over 8
190
 
191
=item B<-help>
192
 
193
Print a brief help message and exits.
194
 
195
=item B<-help -help>
196
 
197
Print a detailed help message with an explanation for each option.
198
 
199
=item B<-man[=n]>
200
 
201
Prints the manual page and exits.
202
 
203
If a numeric manual level is provide then it will be used to control the
204
verbosity of help provided. This should be in the range of 1 to 3.
205
 
206
=item B<--verbose[=n]>
207
 
208
This option will increase the level of verbosity of the JATS command and command
209
invoked by the JATS shell.
210
 
211
If an argument is provided, then it will be used to set the level, otherwise the
212
existing level will be incremented. This option may be specified multiple times.
213
 
214
=back
215
 
216
=head1 DESCRIPTION
217
 
218
This program assists in the maintainance of the the JATS build.pl file.
219
 
220
When a package is rippled by the build daemons the resultant build.pl file is
221
placed on a ClearCase branch dedicated to the AutoBuild process. When a developer
222
manually modifies the build file it 'should' be on the packages main branch and
223
not on the daemons AutoBuild branch.
224
 
225
This utility simplifies this process. The utility will:
226
 
227
=over 8
228
 
229
=item * Ensure that the build.pl file exists
230
 
231
=item * Determine the full ClearCase branch of the build.pl file
232
 
233
This command can only be executed within a ClearCase view. Moreover the user
234
must have located the build.pl file. If the build.pl file is not on an
235
AutoBuilder branch then the utility will terminate.
236
 
237
=item * Determine the parent of the AutoBuiler branch
238
 
239
=item * Checkout the build.pl on the tail of the parent branch
240
 
241
The original 'build.pl' is preserved. At the end of the checkout the version
242
that is checkout will have the content of the original build.pl
243
 
244
=item * Draw a Merge Arraw from the build.pl to the checked out version.
245
 
246
=item * Mark the resultant file writable.
247
 
248
=back
249
 
250
=cut
251