2008-11-04 Anders Carlsson <andersca@apple.com>
[webkit/qt.git] / WebKitTools / Scripts / check-for-weak-vtables
blobd274b012aa7d23d98debfcd50d58ca7cef7a7190
1 #!/usr/bin/perl
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
7 # are met:
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-weak-vtables" script for WebKit Open Source Project
31 # Intended to be invoked from an Xcode build step to check if there are
32 # any weak vtables in a target.
34 use warnings;
35 use strict;
37 use File::Basename;
39 sub touch($);
41 my $arch = $ENV{'CURRENT_ARCH'};
42 my $configuration = $ENV{'CONFIGURATION'};
43 my $target = $ENV{'TARGET_NAME'};
44 my $variant = $ENV{'CURRENT_VARIANT'};
45 my $coverageBuild = $ENV{'WEBKIT_COVERAGE_BUILD'};
46 my $debugRoot = $ENV{'WEBKIT_DEBUG_ROOT'};
48 $arch = $ENV{'NATIVE_ARCH'} if !$arch; # for Xcode 2.1, which does not have CURRENT_ARCH
49 $variant = "normal" if !$variant; # for Xcode 2.1, which does not have CURRENT_VARIANT
51 my $executablePath = "$ENV{'TARGET_BUILD_DIR'}/$ENV{'EXECUTABLE_PATH'}";
53 my $buildTimestampPath = $ENV{'TARGET_TEMP_DIR'} . "/" . basename($0) . ".timestamp";
54 my $buildTimestampAge = -M $buildTimestampPath;
55 my $executablePathAge = -M $executablePath;
57 my $sawError = 0;
59 if (!defined $executablePathAge || !defined $buildTimestampAge || $executablePathAge > $buildTimestampAge) {
60 if (!open NM, "(nm -m '$executablePath' | c++filt | sed 's/^/STDOUT:/') 2>&1 |") {
61 print "Could not open $executablePath\n";
62 $sawError = 1;
63 next;
65 my @weakVTableClasses = ();
66 while (<NM>) {
67 if (/^STDOUT:/) {
68 push @weakVTableClasses, $1 if /weak external vtable for (.*)$/;
69 } else {
70 print STDERR if $_ ne "nm: no name list\n";
73 close NM;
74 if (@weakVTableClasses) {
75 my $shortName = $executablePath;
76 $shortName =~ s/.*\///;
78 print "$shortName has a weak vtable in it ($executablePath)\n";
79 print "Fix by making sure the first virtual function in each of these classes is not an inline:\n";
80 for my $class (sort @weakVTableClasses) {
81 print " $class\n";
83 $sawError = 1;
87 if ($sawError and !$coverageBuild) {
88 unlink $executablePath;
89 exit 1;
92 touch($buildTimestampPath);
94 exit 0;
96 sub touch($)
98 my ($path) = @_;
99 open(TOUCH, ">", $path) or die "$!";
100 close(TOUCH);