merge the formfield patch from ooo-build
[ooovba.git] / solenv / bin / oochkpatch.pl
blobe99d9aaa5d8da62a7a844501f9b2c9bd4a99db8d
2 eval 'exec perl -S $0 ${1+"$@"}'
3 if 0;
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 #
8 # Copyright 2008 by Sun Microsystems, Inc.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # $RCSfile: oochkpatch.pl,v $
14 # $Revision: 1.3 $
16 # This file is part of OpenOffice.org.
18 # OpenOffice.org is free software: you can redistribute it and/or modify
19 # it under the terms of the GNU Lesser General Public License version 3
20 # only, as published by the Free Software Foundation.
22 # OpenOffice.org is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU Lesser General Public License version 3 for more details
26 # (a copy is included in the LICENSE file that accompanied this code).
28 # You should have received a copy of the GNU Lesser General Public License
29 # version 3 along with OpenOffice.org. If not, see
30 # <http://www.openoffice.org/license.html>
31 # for a copy of the LGPLv3 License.
33 #*************************************************************************
35 # oochkpatch - check patch flags against CWS modules
38 require File::Temp;
39 require File::Find;
40 require Getopt::Long;
41 require Pod::Usage;
42 use Pod::Usage;
43 use Getopt::Long;
44 use File::Temp qw/ tempfile tempdir /;
45 use File::Find;
48 # configuration goes here
49 ##########################################################
51 # uncomment this, if in pure OOo environment
52 #my $toplevel_module = "instsetoo_native";
53 #my $scp_module = "scp2";
54 #my $setup_file = "setup_osl";
56 # uncomment this, if within the StarOffice environment
57 my $toplevel_module = "instset_native";
58 my $scp_module = "scp2so";
59 my $setup_file = "setup";
61 my $deliver = "solenv/bin/deliver.pl";
62 my $build = "solenv/bin/build.pl";
64 # list of hardcoded exceptions (files that are _never_ considered
65 # missing from the patch)
66 my %hardcoded_exceptions = ('build.lst' => 1);
69 # no configuration below this point, please!
70 ##########################################################
72 # defaults
73 my $from_module = "";
74 my $verbose = '';
75 my $help = '';
76 my $man = '';
77 my $modules = '';
78 my $from = '';
79 my $perl = '';
81 GetOptions('help|?' => \$help,
82 'man' => \$man,
83 'verbose' => \$verbose,
84 'from=s' => \$from_module ) or pod2usage(2);
85 pod2usage(1) if $help;
86 pod2usage(-exitstatus => 0, -verbose => 2) if $man;
88 # process remaining args
89 print "Processing args...\n" if $verbose;
90 foreach my $argument (@ARGV)
92 print " Checking module ", $argument, "\n" if $verbose;
93 push @modules, $argument;
96 # platform-dependent stuff
97 if( $^O eq 'MSWin32' )
99 $perl = "$ENV{COMSPEC} -c $ENV{PERL}";
100 $setup_file = $setup_file . ".inf";
102 else
104 $perl = 'perl';
105 $setup_file = $setup_file . ".ins";
108 # read some SOLAR stuff from env
109 my $SRC_ROOT = $ENV{"SRC_ROOT"};
110 my $INPATH = $ENV{"INPATH"};
112 # process --from modules
113 if( $from_module )
115 print "Checking all modules upwards and including ", $from_module, "\n" if $verbose;
117 # append build.pl-generated list of modules
118 chdir "$SRC_ROOT/$toplevel_module" or
119 chdir "$SRC_ROOT/$toplevel_module.lnk" or die "ERROR: cannot cd to $SRC_ROOT/$toplevel_module!";
120 open(ALLMODULES,
121 "$perl $SRC_ROOT/$build --all:$from_module --show 2>&1 |") or die "ERROR: cannot build --show!\n";
122 while(<ALLMODULES>)
124 if( /Building project/ )
126 my @module = split( /\s+/, $_ );
127 print " which is ", $module[2], "\n" if $verbose;
128 push(@modules,$module[2]);
133 die "ERROR: no modules to check!\n" if !@modules;
135 $tempdir = tempdir( TMPDIR => 1, CLEANUP => 1);
137 # generate list of files with PATCH flag
138 print "Generating list of files which have the PATCH flag...\n" if $verbose;
140 my $path_to_setup_file = $SRC_ROOT."/".$scp_module."/".$INPATH."/bin/osl/".$setup_file;
141 my $alternate_path_to_setup_file = $SRC_ROOT."/".$scp_module.".lnk/".$INPATH."/bin/osl/".$setup_file;
142 my $in_file_block=0;
143 my $patch_flag=0;
144 my $file_name='';
145 my $base;
146 my $ext;
147 my %pack_files;
148 open(SETUP, "<".$path_to_setup_file) or
149 open(SETUP, "<".$alternate_path_to_setup_file) or die "ERROR: cannot open $path_to_setup_file!\n";
150 while(<SETUP>)
152 if( /^File\s+/ && !$in_file_block )
154 $in_file_block = 1;
155 $patch_flag=0;
156 $file_name='';
158 elsif( /^End/ && $file_name ne '' && $in_file_block )
160 $file_name =~ s/["']//g;
161 $pack_files{$file_name} = $patch_flag;
163 if( $patch_flag )
165 print( " File $file_name included in patch\n") if $verbose;
167 else
169 print( " File $file_name NOT included in patch\n") if $verbose;
172 $in_file_block = 0;
174 elsif( /^\s+Styles\s*=\s*.*PATCH/ && $in_file_block )
176 $patch_flag = 1;
178 elsif( ($res) = /^\s+Name\s*=\s*(.*);/ )
180 $file_name = $res;
184 # generate list of delivered files
185 print "Generating list of delivered libs...\n" if $verbose;
187 # first, deliver all modules to tempdir
188 foreach my $module (@modules)
190 print " dummy-delivering $module...\n" if $verbose;
191 chdir "$SRC_ROOT/$module" or
192 chdir "$SRC_ROOT/$module.lnk" or die "ERROR: cannot cd to $SRC_ROOT/$module!";
193 `$perl $SRC_ROOT/$deliver $tempdir`;
196 # now, check all files in delivered dirs for containedness in PATCH
197 # set
198 print "Checking against delivered files...\n" if $verbose;
199 find(\&wanted, $tempdir );
201 sub wanted
203 my $fname;
205 if( -f )
207 $fname = $_;
208 if( !exists $pack_files{$fname} )
210 print " File $fname is not packed.\n" if $verbose;
212 elsif( $pack_files{$fname} == 0 )
214 if( !$hardcoded_exceptions{ $fname } )
216 # file not in patch set, and not in exception list
217 print " File $fname is packed, but NOT included in patch set and part of delivered output\n" if $verbose;
218 print "$fname\n" if !$verbose;
220 else
222 print " File $fname is NOT included in patch set, but member of hardcoded exception list\n" if $verbose;
225 elsif( $pack_files{$fname} == 1 )
227 print " File $fname packed and patched.\n" if $verbose;
233 __END__
235 =head1 NAME
237 oochkpatch.pl - Verify patch flags against module libraries
239 =head1 SYNOPSIS
241 oochkpatch.pl [options] [module-name ...]
243 Options:
244 --help|-h brief help message
245 --man|-m full documentation
246 --verbose|-v tell what's happening
247 --from=module check all modules from
248 given one upwards
250 =head1 OPTIONS
252 =over 8
254 =item B<--help>
256 Print a brief help message and exits.
258 =item B<--man>
260 Prints the manual page and exits.
262 =item B<--verbose>
264 Verbosely tell what's currently happening
266 =item B<--from=module>
268 Assumes OOo was built incompatibly from given module
269 upwards, and check against all libs from all upwards modules.
270 Further modules can be given at the command line, which are merged
271 with the ones generated from this option
273 =back
275 =head1 DESCRIPTION
277 B<This program> will compare all libs delivered from the specified modules
278 against the set of files marked with the B<patch> flag in scp2. Useful to check
279 if the patch set is complete. Please note that this program needs to be run in
280 a solar shell, i.e. the OOo build environment needs to be set up in the shell.
282 There's kind of a heuristic involved, to determine exactly which files
283 to check against includedness in the patch set (since e.g. all headers
284 are delivered, but clearly need not be checked against patch
285 flags). It works by first collecting all files that are mentioned in
286 the pack master file, and then checking all files delivered from the
287 specified modules against that pack list: if the file is not packed,
288 or if it's packed and has the patch flag set, all is well. Otherwise,
289 the file in question potentially misses the patch flag (because one of
290 the modified modules contains it).
292 =head1 EXAMPLE
294 To determine the set of libs not yet carrying the patch flag for a CWS
295 containing sfx2, svx, and vcl, which is incompatible from sfx2
296 upwards, use something like this:
298 oochkpatch.pl --from=sfx2 `cwsquery modules`
300 This puts every module upwards and including sfx2 in the check list,
301 plus vcl. Note that with this approach, you'll usually get a larger
302 set of files for the patch than necessary - but at least you get all
303 files that might have changed theoretically.
305 =cut