Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
392 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
my $branch = $last_result;
93
Verbose ("Branch: $branch");
94
 
95
#
96
#   Determine parent branch
97
#
98
my @parts = split( '/', $branch );
99
Error ("Build.pl is not on an AutoBuilder Branch." )
100
    unless ( $parts[-2] =~ m~^AutoBuilder\.~ );
101
my $parent = join ('/', @parts[0 .. $#parts - 2]);
102
Verbose "Parent Branch: $parent\n";
103
 
104
#
105
#   Checkout the build.pl file on the parent branch
106
#
107
File::Copy::copy( 'build.pl', 'build.pl.merge' );
108
ClearCmd ('co', '-unreserved', '-c', 'Merged back from AutoBuild', '-ndata', 'build.pl@@'.$parent.'/LATEST');
109
 
110
#
111
#   Draw a merge link to show what has been done
112
#
113
Verbose ("Creating Hyperlink" );
114
my $source_name = 'build.pl@@'.$branch;
115
my $target_name = 'build.pl@@'.$parent.'/CHECKEDOUT';
116
ClearCmd ('mkhlink', 'Merge', $source_name, $target_name);
117
 
118
#
119
#   Copy inthe base build.pl file and make it writable
120
#
121
File::Copy::move( 'build.pl.merge', 'build.pl' );
122
chmod( 0755, 'build.pl' );
123
 
124
exit 0;
125
 
126
#-------------------------------------------------------------------------------
127
# Function        : ClearCmd
128
#
129
# Description     : Execute a ClearCase command and capture the results
130
#                   Errors are held in one array
131
#                   Result are held in another
132
#
133
# Inputs          :
134
#
135
# Returns         :
136
#
137
sub ClearCmd
138
{
139
    my $cmd = QuoteCommand (@_);
140
    Verbose2( "cleartool $cmd" );
141
 
142
        @error_list = ();
143
        @last_results = ();
144
        $last_result = undef;
145
 
146
        open(CMD, "cleartool $cmd  2>&1 |")    || Error( "can't run command: $!" );
147
        while (<CMD>)
148
        {
149
            chomp;
150
            $last_result = $_;
151
            $last_result =~ tr~\\/~/~s;
152
            push @last_results, $last_result;
153
 
154
            Verbose2 ( "cleartool resp:" . $_);
155
            push @error_list, $_ if ( m~Error:~ );
156
        }
157
        close(CMD);
158
 
159
    Verbose2( "Exit Status: $?" );
160
    return $? / 256;
161
}
162
 
163
#-------------------------------------------------------------------------------
164
#   Documentation
165
#
166
 
167
=pod
168
 
169
=head1 NAME
170
 
171
jats_ccmerge_build - Merge autobuilt build.pl file to parent branch
172
 
173
=head1 SYNOPSIS
174
 
175
  jats jats_ccmerge_build [options]
176
 
177
 Options:
178
    -help              - brief help message
179
    -help -help        - Detailed help message
180
    -man[=n]           - Full documentation
181
    -verbose[=n]       - Control program verbosity
182
 
183
=head1 OPTIONS
184
 
185
=over 8
186
 
187
=item B<-help>
188
 
189
Print a brief help message and exits.
190
 
191
=item B<-help -help>
192
 
193
Print a detailed help message with an explanation for each option.
194
 
195
=item B<-man[=n]>
196
 
197
Prints the manual page and exits.
198
 
199
If a numeric manual level is provide then it will be used to control the
200
verbosity of help provided. This should be in the range of 1 to 3.
201
 
202
=item B<--verbose[=n]>
203
 
204
This option will increase the level of verbosity of the JATS command and command
205
invoked by the JATS shell.
206
 
207
If an argument is provided, then it will be used to set the level, otherwise the
208
existing level will be incremented. This option may be specified multiple times.
209
 
210
=back
211
 
212
=head1 DESCRIPTION
213
 
214
This program assists in the maintainance of the the JATS build.pl file.
215
 
216
When a package is rippled by the build daemons the resultant build.pl file is
217
placed on a ClearCase branch dedicated to the AutoBuild process. When a developer
218
manually modifies the build file it 'should' be on the packages main branch and
219
not on the daemons AutoBuild branch.
220
 
221
This utility simplifies this process. The utility will:
222
 
223
=over 8
224
 
225
=item * Ensure that the build.pl file exists
226
 
227
=item * Determine the full ClearCase branch of the build.pl file
228
 
229
This command can only be executed within a ClearCase view. Moreover the user
230
must have located the build.pl file. If the build.pl file is not on an
231
AutoBuilder branch then the utility will terminate.
232
 
233
=item * Determine the parent of the AutoBuiler branch
234
 
235
=item * Checkout the build.pl on the tail of the parent branch
236
 
237
The original 'build.pl' is preserved. At the end of the checkout the version
238
that is checkout will have the content of the current build.pl
239
 
240
=item * Draw a Merge Arraw from the build.pl to the checked out version.
241
 
242
=item * Mark the resultant file writable.
243
 
244
=back
245
 
246
=cut
247