~ubuntu-branches/ubuntu/trusty/enigmail/trusty

« back to all changes in this revision

Viewing changes to mozilla/toolkit/mozapps/installer/xptlink.pl

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2013-09-13 16:02:15 UTC
  • mfrom: (0.12.16)
  • Revision ID: package-import@ubuntu.com-20130913160215-mpeaob8bhtk42aun
Tags: 2:1.5.2-0ubuntu1
* New upstream release v1.5.2 for Thunderbird 24

* Build enigmail using a stripped down Thunderbird 17 build system, as it's
  now quite difficult to build the way we were doing previously, with the
  latest Firefox build system
* Add debian/patches/no_libxpcom.patch - Don't link against libxpcom, as it
  doesn't exist anymore (but exists in the build system)
* Add debian/patches/use_sdk.patch - Use the SDK version of xpt.py and
  friends
* Drop debian/patches/ipc-pipe_rename.diff (not needed anymore)
* Drop debian/patches/makefile_depth.diff (not needed anymore)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
 
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/.
 
6
 
 
7
# xptlink.pl -
 
8
#
 
9
# traverse directories created by pkgcp.pl and merge multiple .xpt files into
 
10
# a single .xpt file to improve startup performance.
 
11
#
 
12
 
 
13
use Getopt::Long;
 
14
 
 
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
 
23
 
 
24
# get command line options
 
25
$return = GetOptions(   "source|s=s",           \$srcdir,
 
26
                        "destination|d=s",      \$destdir,
 
27
      "final|f=s",            \$finaldir,
 
28
                        "help|h",               \$help,
 
29
                        "debug=i",              \$debug,
 
30
                        "verbose|v",            \$verbose,
 
31
                        "xptlink|x=s",          \$xptlink,
 
32
                        "<>",                   \&do_badargument
 
33
                        );
 
34
 
 
35
if ($finaldir eq "") {
 
36
  die "Error: -f is required";
 
37
}
 
38
 
 
39
my $bindir = "";
 
40
 
 
41
# remove extra slashes from $destdir
 
42
$destdir =~ s:/+:/:g;
 
43
 
 
44
# set debug level
 
45
if ($verbose && !($debug)) {
 
46
        $debug = 1;
 
47
} elsif ($debug != 0) {
 
48
        $debug = abs ($debug);
 
49
        ($debug >= 2) && print "debug level: $debug\n";
 
50
}
 
51
 
 
52
# check usage
 
53
if (! $return)
 
54
{
 
55
        die "Error: couldn't parse command line options.  See \'$0 --help' for options.\nExiting...\n";
 
56
} else {
 
57
        check_arguments();
 
58
}
 
59
 
 
60
$xptdirs = ();  # directories in the destination directory
 
61
 
 
62
($debug >= 1) && print "\nLinking .xpt files...\n";
 
63
($debug >= 2) && print "do_xptlink():\n";
 
64
 
 
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";
 
70
closedir (DESTDIR);
 
71
 
 
72
foreach my $component (@xptdirs) {
 
73
        ($debug >= 1) && print "[$component]\n";
 
74
 
 
75
  print ("Checking for '$destdir/$component/$bindir"."components'\n") if $debug >= 3;
 
76
 
 
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";
 
80
 
 
81
                # create list of .xpt files in cwd
 
82
   my @xptfiles;
 
83
 
 
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";
 
94
                        }
 
95
                }
 
96
                closedir (COMPDIR);
 
97
 
 
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";
 
103
 
 
104
      my @realxptfiles;
 
105
      my $realmerged;
 
106
      if ($^O eq "cygwin") {
 
107
          @realxptfiles = map {my $file = `cygpath -t mixed $_`;
 
108
                               chomp $file;
 
109
                               $file} @xptfiles;
 
110
          $realmerged = `cygpath -t mixed $merged`;
 
111
          chomp $realmerged;
 
112
      }
 
113
      else {
 
114
          @realxptfiles = @xptfiles;
 
115
          $realmerged = $merged;
 
116
      }
 
117
 
 
118
      my $cmdline = "$xptlink $realmerged @realxptfiles";
 
119
                        ($debug >= 4) && print "$cmdline\n";
 
120
                        system($cmdline) == 0 || die ("'$cmdline' failed");
 
121
 
 
122
      print "Manifest file: $manifest";
 
123
      open MANIFEST, '>>', $manifest;
 
124
      print MANIFEST "interfaces $component.xpt\n";
 
125
      close MANIFEST;
 
126
                }
 
127
  }
 
128
}
 
129
($debug >= 1) && print "Linking .xpt files completed.\n";
 
130
 
 
131
exit (0);
 
132
 
 
133
 
 
134
#
 
135
# Check that arguments to script are valid.
 
136
#
 
137
sub check_arguments
 
138
{
 
139
        my ($exitval) = 0;
 
140
 
 
141
        ($debug >= 2) && print "check_arguments():\n";
 
142
 
 
143
        # if --help print usage
 
144
        if ($help) {
 
145
                print_usage();
 
146
                exit (1);
 
147
        }
 
148
 
 
149
        # make sure required variables are set:
 
150
        # check source directory
 
151
        if ( $srcdir eq "" ) {
 
152
                print "Error: source directory (--source) not specified.\n";
 
153
                $exitval += 8;
 
154
        } elsif ((! -d $srcdir) || (! -r $srcdir)) {
 
155
                print "Error: source directory \"$srcdir\" is not a directory or is unreadable.\n";
 
156
                $exitval = 1;
 
157
        }
 
158
 
 
159
        # check directory
 
160
        if ( $destdir eq "" ) {
 
161
                print "Error: destination directory (--destdir) not specified.\n";
 
162
                $exitval += 8;
 
163
        } elsif ((! -d $destdir) || (! -w $destdir)) {
 
164
                print "Error: destination directory \"$destdir\" is not a directory or is not writeable.\n";
 
165
                $exitval += 2;
 
166
        }
 
167
 
 
168
        if ($exitval) {
 
169
                print "See \'$0 --help\' for more information.\n";
 
170
                print "Exiting...\n";
 
171
                exit ($exitval);
 
172
        }
 
173
 
 
174
        if ($xptlink eq "") {
 
175
                $xptlink = "$srcdir/bin/xpt_link";
 
176
        }
 
177
}
 
178
 
 
179
 
 
180
#
 
181
# This is called by GetOptions when there are extra command line arguments
 
182
# it doesn't understand.
 
183
#
 
184
sub do_badargument
 
185
{
 
186
        warn "Warning: unknown command line option specified: @_.\n";
 
187
}
 
188
 
 
189
 
 
190
#
 
191
# display usage information
 
192
#
 
193
sub print_usage
 
194
{
 
195
        ($debug >= 2) && print "print_usage():\n";
 
196
 
 
197
        print <<EOC
 
198
 
 
199
$0
 
200
        Traverse component directory specified and merge multiple existing
 
201
        .xpt files into single new .xpt files for improved startup time.
 
202
 
 
203
Options:
 
204
 
 
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
 
208
                pkgcp.pl.
 
209
                Required.
 
210
 
 
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
 
214
                pkgcp.pl.
 
215
                Required.
 
216
 
 
217
        -o, --os [dos|unix]
 
218
                Specifies which type of system this is.  Used for setting path
 
219
                delimiters correctly.
 
220
                Required.
 
221
 
 
222
        -h, --help
 
223
                Prints this information.
 
224
                Optional.
 
225
 
 
226
        --debug [1-10]
 
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.
 
231
                Optional.
 
232
 
 
233
        -v, --verbose
 
234
                Print component names and files copied/deleted.
 
235
                Optional. 
 
236
 
 
237
 
 
238
e.g.
 
239
 
 
240
$0 --os unix -source /builds/mozilla/dist --destination /h/lithium/install --os unix --verbose
 
241
 
 
242
Note: options can be specified by either a leading '--' or '-'.
 
243
 
 
244
EOC
 
245
}
 
246
 
 
247
# EOF