3 # Copyright (C) 2006, 2007, 2008, 2010, 2011 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
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 # THE POSSIBILITY OF SUCH DAMAGE.
26 # "check-for-inappropriate-objc-class-names" script for WebKit Open Source Project
28 # Intended to be invoked from an Xcode build step to check if a framework
29 # defines any Objective-C class whose name does not have one of the prefixes
30 # the framework is allowed to use.
39 my @allowedPrefixes = @ARGV;
41 die "No allowed prefixes passed on the command line" if !@allowedPrefixes;
43 my $arch = $ENV{'CURRENT_ARCH'};
44 my $target = $ENV{'TARGET_NAME'};
45 my $variant = $ENV{'CURRENT_VARIANT'};
46 my $coverageBuild = $ENV{'WEBKIT_COVERAGE_BUILD'};
48 my $executablePath = "$ENV{'TARGET_BUILD_DIR'}/$ENV{'EXECUTABLE_PATH'}";
50 my $buildTimestampPath = $ENV{'TARGET_TEMP_DIR'} . "/" . basename($0) . join('-', @allowedPrefixes) . ".timestamp";
51 my $buildTimestampAge = -M $buildTimestampPath;
52 my $executablePathAge = -M $executablePath;
53 my $scriptAge = -M $0;
55 my $pattern = "^(" . join('|', @allowedPrefixes) . ")";
59 if (!defined $executablePathAge || !defined $buildTimestampAge || $executablePathAge < $buildTimestampAge || $scriptAge < $buildTimestampAge) {
60 if (!open NM, "(nm -Ugjp '$executablePath' | sed 's/^/STDOUT:/') 2>&1 |") {
61 print "ERROR: Could not open $executablePath\n";
68 next unless /^STDOUT:_OBJC_CLASS_\$_/;
70 my $className = substr($_, 21);
71 push(@badNames, $className) unless $className =~ /$pattern/;
73 print STDERR if $_ ne "nm: no name list\n";
80 my $shortName = $executablePath;
81 $shortName =~ s/.*\///;
83 print "ERROR: $shortName defines one or more Objective-C classes with inappropriate names. ($executablePath)\n";
84 for my $className (@badNames) {
85 print "ERROR: Inappropriate Objective-C class name: $className.\n";
88 if (@allowedPrefixes > 1) {
89 print "ERROR: Objective-C class names in $target must have one of these prefixes: " . join(", ", map('"' . $_ . '"', @allowedPrefixes)) . ".\n";
91 print "ERROR: Objective-C class names in $target must have the prefix \"" . $allowedPrefixes[0] . "\".\n";
98 if ($sawError and !$coverageBuild) {
99 unlink $executablePath;
103 touch($buildTimestampPath);
109 open(TOUCH, ">", $path) or die "$!";