xref: /aoo4110/main/solenv/bin/oochkpatch.pl (revision b1cdbd2c)
1:
2    eval 'exec perl -S $0 ${1+"$@"}'
3        if 0;
4#**************************************************************
5#
6#  Licensed to the Apache Software Foundation (ASF) under one
7#  or more contributor license agreements.  See the NOTICE file
8#  distributed with this work for additional information
9#  regarding copyright ownership.  The ASF licenses this file
10#  to you under the Apache License, Version 2.0 (the
11#  "License"); you may not use this file except in compliance
12#  with the License.  You may obtain a copy of the License at
13#
14#    http://www.apache.org/licenses/LICENSE-2.0
15#
16#  Unless required by applicable law or agreed to in writing,
17#  software distributed under the License is distributed on an
18#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19#  KIND, either express or implied.  See the License for the
20#  specific language governing permissions and limitations
21#  under the License.
22#
23#**************************************************************
24
25
26#
27# oochkpatch - check patch flags against CWS modules
28#
29
30require File::Temp;
31require File::Find;
32require Getopt::Long;
33require Pod::Usage;
34use Pod::Usage;
35use Getopt::Long;
36use File::Temp qw/ tempfile tempdir /;
37use File::Find;
38
39
40# configuration goes here
41##########################################################
42
43# uncomment this, if in pure OOo environment
44#my $toplevel_module = "instsetoo_native";
45#my $scp_module	    = "scp2";
46#my $setup_file	    = "setup_osl";
47
48# uncomment this, if within the StarOffice environment
49my $toplevel_module = "instset_native";
50my $scp_module	    = "scp2so";
51my $setup_file	    = "setup";
52
53my $deliver = "solenv/bin/deliver.pl";
54my $build	= "solenv/bin/build.pl";
55
56# list of hardcoded exceptions (files that are _never_ considered
57# missing from the patch)
58my %hardcoded_exceptions = ('build.lst' => 1);
59
60
61# no configuration below this point, please!
62##########################################################
63
64# defaults
65my $from_module = "";
66my $verbose		= '';
67my $help		= '';
68my $man			= '';
69my $modules		= '';
70my $from		= '';
71my $perl		= '';
72
73GetOptions('help|?'  => \$help,
74		   'man'     => \$man,
75		   'verbose' => \$verbose,
76		   'from=s'  => \$from_module ) or pod2usage(2);
77pod2usage(1) if $help;
78pod2usage(-exitstatus => 0, -verbose => 2) if $man;
79
80# process remaining args
81print "Processing args...\n" if $verbose;
82foreach my $argument (@ARGV)
83{
84	print " Checking module ", $argument, "\n" if $verbose;
85	push @modules, $argument;
86}
87
88# platform-dependent stuff
89if( $^O eq 'MSWin32' )
90{
91	$perl = "$ENV{COMSPEC} -c $ENV{PERL}";
92	$setup_file = $setup_file . ".inf";
93}
94else
95{
96	$perl = 'perl';
97	$setup_file = $setup_file . ".ins";
98};
99
100# read some SOLAR stuff from env
101my $SRC_ROOT = $ENV{"SRC_ROOT"};
102my $INPATH = $ENV{"INPATH"};
103
104# process --from modules
105if( $from_module )
106{
107	print "Checking all modules upwards and including ", $from_module, "\n" if $verbose;
108
109	# append build.pl-generated list of modules
110	chdir "$SRC_ROOT/$toplevel_module" or
111		chdir "$SRC_ROOT/$toplevel_module.lnk" or die "ERROR: cannot cd to $SRC_ROOT/$toplevel_module!";
112	open(ALLMODULES,
113		 "$perl $SRC_ROOT/$build --all:$from_module --show 2>&1 |") or die "ERROR: cannot build --show!\n";
114	while(<ALLMODULES>)
115	{
116		if( /Building project/ )
117		{
118			my @module = split( /\s+/, $_ );
119			print " which is ", $module[2], "\n" if $verbose;
120			push(@modules,$module[2]);
121		}
122	}
123}
124
125die "ERROR: no modules to check!\n" if !@modules;
126
127$tempdir = tempdir( TMPDIR => 1, CLEANUP => 1);
128
129# generate list of files with PATCH flag
130print "Generating list of files which have the PATCH flag...\n" if $verbose;
131
132my $path_to_setup_file = $SRC_ROOT."/".$scp_module."/".$INPATH."/bin/osl/".$setup_file;
133my $alternate_path_to_setup_file = $SRC_ROOT."/".$scp_module.".lnk/".$INPATH."/bin/osl/".$setup_file;
134my $in_file_block=0;
135my $patch_flag=0;
136my $file_name='';
137my $base;
138my $ext;
139my %pack_files;
140open(SETUP, "<".$path_to_setup_file) or
141   open(SETUP, "<".$alternate_path_to_setup_file) or die "ERROR: cannot open $path_to_setup_file!\n";
142while(<SETUP>)
143{
144	if( /^File\s+/ && !$in_file_block )
145	{
146		$in_file_block = 1;
147		$patch_flag=0;
148		$file_name='';
149	}
150	elsif( /^End/ && $file_name ne '' && $in_file_block )
151	{
152		$file_name =~ s/["']//g;
153		$pack_files{$file_name} = $patch_flag;
154
155		if( $patch_flag )
156		{
157			print( " File $file_name included in patch\n") if $verbose;
158		}
159		else
160		{
161			print( " File $file_name NOT included in patch\n") if $verbose;
162		}
163
164		$in_file_block = 0;
165	}
166	elsif( /^\s+Styles\s*=\s*.*PATCH/ && $in_file_block )
167	{
168		$patch_flag = 1;
169	}
170	elsif( ($res) = /^\s+Name\s*=\s*(.*);/ )
171	{
172		$file_name = $res;
173	}
174}
175
176# generate list of delivered files
177print "Generating list of delivered libs...\n" if $verbose;
178
179# first, deliver all modules to tempdir
180foreach my $module (@modules)
181{
182	print " dummy-delivering $module...\n" if $verbose;
183	chdir "$SRC_ROOT/$module" or
184		chdir "$SRC_ROOT/$module.lnk" or die "ERROR: cannot cd to $SRC_ROOT/$module!";
185	`$perl $SRC_ROOT/$deliver $tempdir`;
186}
187
188# now, check all files in delivered dirs for containedness in PATCH
189# set
190print "Checking against delivered files...\n" if $verbose;
191find(\&wanted, $tempdir );
192
193sub wanted
194{
195	my $fname;
196
197	if( -f )
198	{
199		$fname = $_;
200		if( !exists $pack_files{$fname} )
201		{
202			print " File $fname is not packed.\n" if $verbose;
203		}
204		elsif( $pack_files{$fname} == 0 )
205		{
206			if( !$hardcoded_exceptions{ $fname } )
207			{
208				# file not in patch set, and not in exception list
209				print " File $fname is packed, but NOT included in patch set and part of delivered output\n" if $verbose;
210				print "$fname\n" if !$verbose;
211			}
212			else
213			{
214				print " File $fname is NOT included in patch set, but member of hardcoded exception list\n" if $verbose;
215			}
216		}
217		elsif( $pack_files{$fname} == 1 )
218		{
219			print " File $fname packed and patched.\n" if $verbose;
220		}
221	}
222}
223
224
225__END__
226
227=head1 NAME
228
229oochkpatch.pl - Verify patch flags against module libraries
230
231=head1 SYNOPSIS
232
233oochkpatch.pl [options] [module-name ...]
234
235 Options:
236   --help|-h         brief help message
237   --man|-m          full documentation
238   --verbose|-v      tell what's happening
239   --from=module     check all modules from
240                     given one upwards
241
242=head1 OPTIONS
243
244=over 8
245
246=item B<--help>
247
248Print a brief help message and exits.
249
250=item B<--man>
251
252Prints the manual page and exits.
253
254=item B<--verbose>
255
256Verbosely tell what's currently happening
257
258=item B<--from=module>
259
260Assumes OOo was built incompatibly from given module
261upwards, and check against all libs from all upwards modules.
262Further modules can be given at the command line, which are merged
263with the ones generated from this option
264
265=back
266
267=head1 DESCRIPTION
268
269B<This program> will compare all libs delivered from the specified modules
270against the set of files marked with the B<patch> flag in scp2. Useful to check
271if the patch set is complete. Please note that this program needs to be run in
272a solar shell, i.e. the OOo build environment needs to be set up in the shell.
273
274There's kind of a heuristic involved, to determine exactly which files
275to check against includedness in the patch set (since e.g. all headers
276are delivered, but clearly need not be checked against patch
277flags). It works by first collecting all files that are mentioned in
278the pack master file, and then checking all files delivered from the
279specified modules against that pack list: if the file is not packed,
280or if it's packed and has the patch flag set, all is well. Otherwise,
281the file in question potentially misses the patch flag (because one of
282the modified modules contains it).
283
284=head1 EXAMPLE
285
286To determine the set of libs not yet carrying the patch flag for a CWS
287containing sfx2, svx, and vcl, which is incompatible from sfx2
288upwards, use something like this:
289
290oochkpatch.pl --from=sfx2 `cwsquery modules`
291
292This puts every module upwards and including sfx2 in the check list,
293plus vcl. Note that with this approach, you'll usually get a larger
294set of files for the patch than necessary - but at least you get all
295files that might have changed theoretically.
296
297=cut
298