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