3
# This Source Code Form is subject to the terms of the Mozilla Public
4
# License, v. 2.0. If a copy of the MPL was not distributed with this
5
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
# traverse directories created by pkgcp.pl and merge multiple .xpt files into
10
# a single .xpt file to improve startup performance.
15
# initialize variables
16
$srcdir = ""; # root directory being copied from
17
$destdir = ""; # root directory being copied to
18
$finaldir = ""; # where to put the final linked XPT
19
$verbose = 0; # shorthand for --debug 1
20
$debug = 0; # controls amount of debug output
21
$help = 0; # flag: if set, print usage
22
$xptlink = ""; # path to the xpt_link binary
24
# get command line options
25
$return = GetOptions( "source|s=s", \$srcdir,
26
"destination|d=s", \$destdir,
27
"final|f=s", \$finaldir,
30
"verbose|v", \$verbose,
31
"xptlink|x=s", \$xptlink,
32
"<>", \&do_badargument
35
if ($finaldir eq "") {
36
die "Error: -f is required";
41
# remove extra slashes from $destdir
45
if ($verbose && !($debug)) {
47
} elsif ($debug != 0) {
48
$debug = abs ($debug);
49
($debug >= 2) && print "debug level: $debug\n";
55
die "Error: couldn't parse command line options. See \'$0 --help' for options.\nExiting...\n";
60
$xptdirs = (); # directories in the destination directory
62
($debug >= 1) && print "\nLinking .xpt files...\n";
63
($debug >= 2) && print "do_xptlink():\n";
65
# get list of directories on which to run xptlink
66
opendir (DESTDIR, "$destdir") ||
67
die "Error: could not open directory $destdir. Exiting...\n";
68
@xptdirs = sort ( grep (!/^\./, readdir (DESTDIR) ) );
69
($debug >= 4) && print "xptdirs: @xptdirs\n";
72
foreach my $component (@xptdirs) {
73
($debug >= 1) && print "[$component]\n";
75
print ("Checking for '$destdir/$component/$bindir"."components'\n") if $debug >= 3;
77
if (-d "$destdir/$component/$bindir"."components") {
78
warn "File '$destdir/$component/$bindir"."components/$component.xpt' already exists."
79
if -f "$destdir/$component/$bindir"."components/$component.xpt";
81
# create list of .xpt files in cwd
84
($debug >= 4) && print "opendir: $destdir/$component/$bindir"."components\n";
85
opendir (COMPDIR, "$destdir/$component/$bindir"."components") ||
86
die "Error: cannot open $destdir/$component/$bindir"."components. Exiting...\n";
87
($debug >= 3) && print "Creating list of .xpt files...\n";
88
my @files = sort ( grep (!/^\./, readdir (COMPDIR)));
89
foreach my $file (@files) {
90
($debug >= 6) && print "$file\n";
91
if ( $file =~ /\.xpt$/ ) {
92
push @xptfiles, "$destdir/$component/$bindir"."components/$file";
93
($debug >= 8) && print "xptfiles:\t@xptfiles\n";
98
# merge .xpt files into one if we found any in the dir
99
if ( scalar(@xptfiles) ) {
100
my ($merged, $manifest);
101
$merged = "$finaldir/$component.xpt";
102
$manifest = "$finaldir/interfaces.manifest";
106
if ($^O eq "cygwin") {
107
@realxptfiles = map {my $file = `cygpath -t mixed $_`;
110
$realmerged = `cygpath -t mixed $merged`;
114
@realxptfiles = @xptfiles;
115
$realmerged = $merged;
118
my $cmdline = "$xptlink $realmerged @realxptfiles";
119
($debug >= 4) && print "$cmdline\n";
120
system($cmdline) == 0 || die ("'$cmdline' failed");
122
print "Manifest file: $manifest";
123
open MANIFEST, '>>', $manifest;
124
print MANIFEST "interfaces $component.xpt\n";
129
($debug >= 1) && print "Linking .xpt files completed.\n";
135
# Check that arguments to script are valid.
141
($debug >= 2) && print "check_arguments():\n";
143
# if --help print usage
149
# make sure required variables are set:
150
# check source directory
151
if ( $srcdir eq "" ) {
152
print "Error: source directory (--source) not specified.\n";
154
} elsif ((! -d $srcdir) || (! -r $srcdir)) {
155
print "Error: source directory \"$srcdir\" is not a directory or is unreadable.\n";
160
if ( $destdir eq "" ) {
161
print "Error: destination directory (--destdir) not specified.\n";
163
} elsif ((! -d $destdir) || (! -w $destdir)) {
164
print "Error: destination directory \"$destdir\" is not a directory or is not writeable.\n";
169
print "See \'$0 --help\' for more information.\n";
170
print "Exiting...\n";
174
if ($xptlink eq "") {
175
$xptlink = "$srcdir/bin/xpt_link";
181
# This is called by GetOptions when there are extra command line arguments
182
# it doesn't understand.
186
warn "Warning: unknown command line option specified: @_.\n";
191
# display usage information
195
($debug >= 2) && print "print_usage():\n";
200
Traverse component directory specified and merge multiple existing
201
.xpt files into single new .xpt files for improved startup time.
205
-s, --source <directory>
206
Specifies the directory from which the component files were
207
copied. Typically, this will be the same directory used by
211
-d, --destination <directory>
212
Specifies the directory in which the component directories are
213
located. Typically, this will be the same directory used by
218
Specifies which type of system this is. Used for setting path
219
delimiters correctly.
223
Prints this information.
227
Controls verbosity of debugging output, 10 being most verbose.
228
1 : same as --verbose.
229
2 : includes function calls.
230
3 : includes source and destination for each copy.
234
Print component names and files copied/deleted.
240
$0 --os unix -source /builds/mozilla/dist --destination /h/lithium/install --os unix --verbose
242
Note: options can be specified by either a leading '--' or '-'.