3 # Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
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.
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.
29 # "check-for-global-initializers" script for WebKit Open Source Project
31 # Intended to be invoked from an Xcode build step to check if there are
32 # any global initializers in a target.
42 my $arch = $ENV{'CURRENT_ARCH'};
43 my $configuration = $ENV{'CONFIGURATION'};
44 my $target = $ENV{'TARGET_NAME'};
45 my $variant = $ENV{'CURRENT_VARIANT'};
46 my $coverageBuild = $ENV{'WEBKIT_COVERAGE_BUILD'};
47 my $debugRoot = $ENV{'WEBKIT_DEBUG_ROOT'};
49 $arch = $ENV{'NATIVE_ARCH'} if !$arch; # for Xcode 2.1, which does not have CURRENT_ARCH
50 $variant = "normal" if !$variant; # for Xcode 2.1, which does not have CURRENT_VARIANT
52 my $executablePath = "$ENV{'TARGET_BUILD_DIR'}/$ENV{'EXECUTABLE_PATH'}";
54 my $buildTimestampPath = $ENV{'TARGET_TEMP_DIR'} . "/" . basename($0) . ".timestamp";
55 my $buildTimestampAge = -M $buildTimestampPath;
56 my $scriptAge = -M $0;
58 my $list = $ENV{"LINK_FILE_LIST_${variant}_${arch}"};
60 if (!open LIST, $list) {
61 print "ERROR: Could not open $list\n";
71 for my $file (sort @files) {
72 if (defined $buildTimestampAge && $buildTimestampAge < $scriptAge) {
73 my $fileAge = -M $file;
74 next if defined $fileAge && $fileAge > $buildTimestampAge;
76 if (!open NM, "(nm '$file' | sed 's/^/STDOUT:/') 2>&1 |") {
77 print "ERROR: Could not open $file\n";
86 if ($line =~ /__GLOBAL__I(.+)$/) {
88 push(@globals, demangle($1));
91 print STDERR if $_ ne "nm: no name list\n";
96 my $shortName = $file;
97 $shortName =~ s/.*\///;
99 # Special cases for files that have initializers in debug builds.
100 if ($configuration eq "Debug" or $variant eq "debug" or $debugRoot) {
101 if ($target eq "JavaScriptCore") {
102 next if $shortName eq "AllInOneFile.o";
103 next if $shortName eq "Opcode.o";
104 next if $shortName eq "Structure.o";
105 next if $shortName eq "nodes.o";
107 if ($target eq "WebCore") {
108 next if $shortName eq "BidiRun.o";
109 next if $shortName eq "CachedPage.o";
110 next if $shortName eq "CachedResource.o";
111 next if $shortName eq "FEGaussianBlur.o";
112 next if $shortName eq "Frame.o";
113 next if $shortName eq "JSCustomSQLTransactionCallback.o";
114 next if $shortName eq "JSLazyEventListener.o";
115 next if $shortName eq "Node.o";
116 next if $shortName eq "Page.o";
117 next if $shortName eq "Range.o";
118 next if $shortName eq "RenderObject.o";
119 next if $shortName eq "SVGElementInstance.o";
120 next if $shortName eq "SubresourceLoader.o";
121 next if $shortName eq "XMLHttpRequest.o";
123 if ($target eq "WebKit") {
124 next if $shortName eq "HostedNetscapePluginStream.o";
125 next if $shortName eq "NetscapePluginInstanceProxy.o";
127 if ($target eq "WebKit2") {
128 next if $shortName eq "WebContext.o";
129 next if $shortName eq "WebFrame.o";
130 next if $shortName eq "WebPage.o";
131 next if $shortName eq "WebPageProxy.o";
135 print "ERROR: $shortName has one or more global initializers in it! ($file), near @globals\n";
140 if ($sawError and !$coverageBuild) {
141 unlink $executablePath;
145 touch($buildTimestampPath);
151 open(TOUCH, ">", $path) or die "$!";
158 if (!open FILT, "c++filt $symbol |") {
159 print "ERROR: Could not open c++filt\n";