summaryrefslogtreecommitdiff
path: root/solenv/bin/oochkpatch.pl
blob: 4b2e08ad2a744f85b51fd189ca97cfc274a7cb9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
:
    eval 'exec perl -S $0 ${1+"$@"}'
        if 0;
#*************************************************************************
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# 
# Copyright 2000, 2010 Oracle and/or its affiliates.
#
# OpenOffice.org - a multi-platform office productivity suite
#
# This file is part of OpenOffice.org.
#
# OpenOffice.org is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# only, as published by the Free Software Foundation.
#
# OpenOffice.org is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License version 3 for more details
# (a copy is included in the LICENSE file that accompanied this code).
#
# You should have received a copy of the GNU Lesser General Public License
# version 3 along with OpenOffice.org.  If not, see
# <http://www.openoffice.org/license.html>
# for a copy of the LGPLv3 License.
#
#*************************************************************************
#
# oochkpatch - check patch flags against CWS modules
#

require File::Temp;
require File::Find;
require Getopt::Long;
require Pod::Usage;
use Pod::Usage;
use Getopt::Long;
use File::Temp qw/ tempfile tempdir /;
use File::Find;


# configuration goes here
##########################################################

# uncomment this, if in pure OOo environment
#my $toplevel_module = "instsetoo_native";
#my $scp_module	    = "scp2";
#my $setup_file	    = "setup_osl";

# uncomment this, if within the StarOffice environment
my $toplevel_module = "instset_native";
my $scp_module	    = "scp2so";
my $setup_file	    = "setup";

my $deliver = "solenv/bin/deliver.pl";
my $build	= "solenv/bin/build.pl";

# list of hardcoded exceptions (files that are _never_ considered
# missing from the patch)
my %hardcoded_exceptions = ('build.lst' => 1);


# no configuration below this point, please!
##########################################################

# defaults
my $from_module = "";
my $verbose		= '';
my $help		= '';
my $man			= '';
my $modules		= '';
my $from		= '';
my $perl		= '';

GetOptions('help|?'  => \$help,
           'man'     => \$man,
           'verbose' => \$verbose,
           'from=s'  => \$from_module ) or pod2usage(2);
pod2usage(1) if $help;
pod2usage(-exitstatus => 0, -verbose => 2) if $man;

# process remaining args
print "Processing args...\n" if $verbose;
foreach my $argument (@ARGV)
{
    print " Checking module ", $argument, "\n" if $verbose;
    push @modules, $argument;
}

# platform-dependent stuff
if( $^O eq 'MSWin32' )
{
    $perl = "$ENV{COMSPEC} -c $ENV{PERL}";
    $setup_file = $setup_file . ".inf";
} 
else 
{
    $perl = 'perl';
    $setup_file = $setup_file . ".ins";
};

# read some SOLAR stuff from env
my $SRC_ROOT = $ENV{"SRC_ROOT"};
my $INPATH = $ENV{"INPATH"};

# process --from modules
if( $from_module )
{
    print "Checking all modules upwards and including ", $from_module, "\n" if $verbose;

    # append build.pl-generated list of modules
    chdir "$SRC_ROOT/$toplevel_module" or 
        chdir "$SRC_ROOT/$toplevel_module.lnk" or die "ERROR: cannot cd to $SRC_ROOT/$toplevel_module!";
    open(ALLMODULES,
         "$perl $SRC_ROOT/$build --all:$from_module --show 2>&1 |") or die "ERROR: cannot build --show!\n";
    while(<ALLMODULES>)
    {
        if( /Building project/ )
        {
            my @module = split( /\s+/, $_ );
            print " which is ", $module[2], "\n" if $verbose;
            push(@modules,$module[2]);
        }
    }
}

die "ERROR: no modules to check!\n" if !@modules;

$tempdir = tempdir( TMPDIR => 1, CLEANUP => 1);

# generate list of files with PATCH flag
print "Generating list of files which have the PATCH flag...\n" if $verbose;

my $path_to_setup_file = $SRC_ROOT."/".$scp_module."/".$INPATH."/bin/osl/".$setup_file;
my $alternate_path_to_setup_file = $SRC_ROOT."/".$scp_module.".lnk/".$INPATH."/bin/osl/".$setup_file;
my $in_file_block=0;
my $patch_flag=0;
my $file_name='';
my $base;
my $ext;
my %pack_files;
open(SETUP, "<".$path_to_setup_file) or
   open(SETUP, "<".$alternate_path_to_setup_file) or die "ERROR: cannot open $path_to_setup_file!\n";
while(<SETUP>)
{
    if( /^File\s+/ && !$in_file_block )
    {
        $in_file_block = 1;
        $patch_flag=0;
        $file_name='';
    }
    elsif( /^End/ && $file_name ne '' && $in_file_block )
    {
        $file_name =~ s/["']//g;
        $pack_files{$file_name} = $patch_flag;

        if( $patch_flag )
        {
            print( " File $file_name included in patch\n") if $verbose;
        }
        else
        {
            print( " File $file_name NOT included in patch\n") if $verbose;
        }

        $in_file_block = 0;
    }
    elsif( /^\s+Styles\s*=\s*.*PATCH/ && $in_file_block )
    {
        $patch_flag = 1;
    }
    elsif( ($res) = /^\s+Name\s*=\s*(.*);/ )
    {
        $file_name = $res;
    }
}

# generate list of delivered files
print "Generating list of delivered libs...\n" if $verbose;

# first, deliver all modules to tempdir
foreach my $module (@modules)
{
    print " dummy-delivering $module...\n" if $verbose;
    chdir "$SRC_ROOT/$module" or 
        chdir "$SRC_ROOT/$module.lnk" or die "ERROR: cannot cd to $SRC_ROOT/$module!";
    `$perl $SRC_ROOT/$deliver $tempdir`;
}

# now, check all files in delivered dirs for containedness in PATCH
# set
print "Checking against delivered files...\n" if $verbose;
find(\&wanted, $tempdir );

sub wanted
{
    my $fname;

    if( -f )
    {
        $fname = $_;
        if( !exists $pack_files{$fname} )
        {
            print " File $fname is not packed.\n" if $verbose;
        }
        elsif( $pack_files{$fname} == 0 )
        {
            if( !$hardcoded_exceptions{ $fname } )
            {
                # file not in patch set, and not in exception list
                print " File $fname is packed, but NOT included in patch set and part of delivered output\n" if $verbose;
                print "$fname\n" if !$verbose;
            }
            else
            {
                print " File $fname is NOT included in patch set, but member of hardcoded exception list\n" if $verbose;
            }
        }
        elsif( $pack_files{$fname} == 1 )
        {
            print " File $fname packed and patched.\n" if $verbose;
        }
    }
}


__END__

=head1 NAME

oochkpatch.pl - Verify patch flags against module libraries

=head1 SYNOPSIS

oochkpatch.pl [options] [module-name ...]

 Options:
   --help|-h         brief help message
   --man|-m          full documentation
   --verbose|-v      tell what's happening
   --from=module     check all modules from
                     given one upwards

=head1 OPTIONS

=over 8

=item B<--help>

Print a brief help message and exits.

=item B<--man>

Prints the manual page and exits.

=item B<--verbose>

Verbosely tell what's currently happening

=item B<--from=module>

Assumes OOo was built incompatibly from given module 
upwards, and check against all libs from all upwards modules.
Further modules can be given at the command line, which are merged 
with the ones generated from this option

=back

=head1 DESCRIPTION

B<This program> will compare all libs delivered from the specified modules
against the set of files marked with the B<patch> flag in scp2. Useful to check 
if the patch set is complete. Please note that this program needs to be run in 
a solar shell, i.e. the OOo build environment needs to be set up in the shell.

There's kind of a heuristic involved, to determine exactly which files
to check against includedness in the patch set (since e.g. all headers
are delivered, but clearly need not be checked against patch
flags). It works by first collecting all files that are mentioned in
the pack master file, and then checking all files delivered from the
specified modules against that pack list: if the file is not packed,
or if it's packed and has the patch flag set, all is well. Otherwise,
the file in question potentially misses the patch flag (because one of
the modified modules contains it).

=head1 EXAMPLE

To determine the set of libs not yet carrying the patch flag for a CWS
containing sfx2, svx, and vcl, which is incompatible from sfx2
upwards, use something like this:

oochkpatch.pl --from=sfx2 `cwsquery modules`

This puts every module upwards and including sfx2 in the check list,
plus vcl. Note that with this approach, you'll usually get a larger
set of files for the patch than necessary - but at least you get all
files that might have changed theoretically.

=cut