|
1 #!/usr/bin/perl |
|
2 |
|
3 # Copyright (C) 2006, 2007 Apple Inc. All rights reserved. |
|
4 # |
|
5 # Redistribution and use in source and binary forms, with or without |
|
6 # modification, are permitted provided that the following conditions |
|
7 # are met: |
|
8 # |
|
9 # 1. Redistributions of source code must retain the above copyright |
|
10 # notice, this list of conditions and the following disclaimer. |
|
11 # 2. Redistributions in binary form must reproduce the above copyright |
|
12 # notice, this list of conditions and the following disclaimer in the |
|
13 # documentation and/or other materials provided with the distribution. |
|
14 # 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
|
15 # its contributors may be used to endorse or promote products derived |
|
16 # from this software without specific prior written permission. |
|
17 # |
|
18 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
|
19 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
20 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
21 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
|
22 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
23 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
24 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|
25 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|
27 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
28 |
|
29 # "check-for-global-initializers" script for Web Kit Open Source Project |
|
30 |
|
31 # Intended to be invoked from an Xcode build step to check if there are |
|
32 # any global initializers in a target. |
|
33 |
|
34 use warnings; |
|
35 use strict; |
|
36 |
|
37 my $arch = $ENV{'CURRENT_ARCH'}; |
|
38 my $configuration = $ENV{'CONFIGURATION'}; |
|
39 my $target = $ENV{'TARGET_NAME'}; |
|
40 my $variant = $ENV{'CURRENT_VARIANT'}; |
|
41 my $coverageBuild = $ENV{'WEBKIT_COVERAGE_BUILD'}; |
|
42 |
|
43 $arch = $ENV{'NATIVE_ARCH'} if !$arch; # for Xcode 2.1, which does not have CURRENT_ARCH |
|
44 $variant = "normal" if !$variant; # for Xcode 2.1, which does not have CURRENT_VARIANT |
|
45 |
|
46 my $executablePath = "$ENV{'TARGET_BUILD_DIR'}/$ENV{'EXECUTABLE_PATH'}"; |
|
47 my $executableAge = -M $executablePath; |
|
48 |
|
49 my $list = $ENV{"LINK_FILE_LIST_${variant}_${arch}"}; |
|
50 |
|
51 if (!open LIST, $list) { |
|
52 print "Could not open $list\n"; |
|
53 exit 1; |
|
54 } |
|
55 |
|
56 my @files = <LIST>; |
|
57 chomp @files; |
|
58 close LIST; |
|
59 |
|
60 my $sawError = 0; |
|
61 |
|
62 for my $file (sort @files) { |
|
63 if (defined $executableAge) { |
|
64 my $fileAge = -M $file; |
|
65 next if defined $fileAge && $fileAge > $executableAge; |
|
66 } |
|
67 if (!open NM, "(nm '$file' | sed 's/^/STDOUT:/') 2>&1 |") { |
|
68 print "Could not open $file\n"; |
|
69 $sawError = 1; |
|
70 next; |
|
71 } |
|
72 my $sawGlobal = 0; |
|
73 while (<NM>) { |
|
74 if (/^STDOUT:/) { |
|
75 $sawGlobal = 1 if /__GLOBAL__I/; |
|
76 } else { |
|
77 print STDERR if $_ ne "nm: no name list\n"; |
|
78 } |
|
79 } |
|
80 close NM; |
|
81 if ($sawGlobal) { |
|
82 my $shortName = $file; |
|
83 $shortName =~ s/.*\///; |
|
84 |
|
85 # Special cases for files that have initializers in debug builds. |
|
86 if ($configuration eq "Debug") { |
|
87 if ($target eq "JavaScriptCore") { |
|
88 next if $shortName eq "nodes.o"; |
|
89 next if $shortName eq "AllInOneFile.o"; |
|
90 } |
|
91 if ($target eq "WebCore") { |
|
92 next if $shortName eq "CachedPage.o"; |
|
93 next if $shortName eq "Frame.o"; |
|
94 next if $shortName eq "Node.o"; |
|
95 next if $shortName eq "Page.o"; |
|
96 next if $shortName eq "Range.o"; |
|
97 next if $shortName eq "RenderObject.o"; |
|
98 next if $shortName eq "SubresourceLoader.o"; |
|
99 next if $shortName eq "bidi.o"; |
|
100 next if $shortName eq "kjs_events.o"; |
|
101 } |
|
102 } |
|
103 |
|
104 print "$shortName has a global initializer in it! ($file)\n"; |
|
105 $sawError = 1; |
|
106 } |
|
107 } |
|
108 |
|
109 if ($sawError and !$coverageBuild) { |
|
110 unlink $executablePath; |
|
111 exit 1; |
|
112 } |