Source/JavaScriptCore: JavaScriptCore Part of: Prevent the WebKit frameworks from...
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Sep 2011 18:48:16 +0000 (18:48 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Sep 2011 18:48:16 +0000 (18:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=68451

Reviewed by Darin Adler.

* JavaScriptCore.xcodeproj/project.pbxproj: Added a script build phase that invokes
check-for-inappropriate-objc-class-names, allowing only class names prefixed with "JS".

Source/WebCore: WebCore part of: Prevent the WebKit frameworks from defining inappropriately-named Objective-C classes
https://bugs.webkit.org/show_bug.cgi?id=68451

Reviewed by Darin Adler.

* WebCore.xcodeproj/project.pbxproj: Added a script build phase that invokes
check-for-inappropriate-objc-class-names, allowing only class names prefixed with "DOM" or "Web".

Source/WebKit: WebKit part of: Prevent the WebKit frameworks from defining inappropriately-named Objective-C classes
https://bugs.webkit.org/show_bug.cgi?id=68451

Reviewed by Darin Adler.

* WebKit.xcodeproj/project.pbxproj: Added a script build phase that invokes
check-for-inappropriate-objc-class-names, allowing only class names prefixed with "Web" or "_Web".

Source/WebKit2: WebKit2 part of: Prevent the WebKit frameworks from defining inappropriately-named Objective-C classes
https://bugs.webkit.org/show_bug.cgi?id=68451

Reviewed by Darin Adler.

* WebKit2.xcodeproj/project.pbxproj: Added a script build phase that invokes
check-for-inappropriate-objc-class-names, allowing only class names prefixed with "WK" or "Web".

Tools: Tools part of: Prevent the WebKit frameworks from defining inappropriately-named Objective-C classes
https://bugs.webkit.org/show_bug.cgi?id=68451

Reviewed by Darin Adler.

* Scripts/check-for-inappropriate-objc-class-names: Added. Checks for
Objective-C classes with names not having one of a list of prefixes
passed on the command line.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@95655 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebKit/ChangeLog
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit2/ChangeLog
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Tools/ChangeLog
Tools/Scripts/check-for-inappropriate-objc-class-names [new file with mode: 0755]

index 57679e109f16f9b53d020c13901e4ad774d72955..606b92b9cbaacbcbc30b5577887d9a3e469bd025 100644 (file)
@@ -1,3 +1,13 @@
+2011-09-21  Dan Bernstein  <mitz@apple.com>
+
+        JavaScriptCore Part of: Prevent the WebKit frameworks from defining inappropriately-named Objective-C classes
+        https://bugs.webkit.org/show_bug.cgi?id=68451
+
+        Reviewed by Darin Adler.
+
+        * JavaScriptCore.xcodeproj/project.pbxproj: Added a script build phase that invokes
+        check-for-inappropriate-objc-class-names, allowing only class names prefixed with "JS".
+
 2011-09-20  Gavin Barraclough  <barraclough@apple.com>
 
         MacroAssembler fixes.
index dc0b76215705a6ceed2b8fc890ad08e5a9c14bd3..c6d7f3c7d22da4c0512b261499e75c1ffaad84b2 100644 (file)
                                9319586B09D9F91A00A56FD4 /* Check For Global Initializers */,
                                933457200EBFDC3F00B80894 /* Check For Exit Time Destructors */,
                                5D29D8BE0E9860B400C3D2D0 /* Check For Weak VTables and Externals */,
+                               3713F014142905240036387F /* Check For Inappropriate Objective-C Class Names */,
                        );
                        buildRules = (
                        );
 /* End PBXProject section */
 
 /* Begin PBXShellScriptBuildPhase section */
+               3713F014142905240036387F /* Check For Inappropriate Objective-C Class Names */ = {
+                       isa = PBXShellScriptBuildPhase;
+                       buildActionMask = 2147483647;
+                       files = (
+                       );
+                       inputPaths = (
+                               "$(TARGET_BUILD_DIR)/$(EXECUTABLE_PATH)",
+                       );
+                       name = "Check For Inappropriate Objective-C Class Names";
+                       outputPaths = (
+                       );
+                       runOnlyForDeploymentPostprocessing = 0;
+                       shellPath = /bin/sh;
+                       shellScript = "if [ \"${ACTION}\" = \"installhdrs\" ]; then\n    exit 0;\nfi\n\nif [ -f ../../Tools/Scripts/check-for-inappropriate-objc-class-names ]; then\n    ../../Tools/Scripts/check-for-inappropriate-objc-class-names JS || exit $?\nfi";
+               };
                5D29D8BE0E9860B400C3D2D0 /* Check For Weak VTables and Externals */ = {
                        isa = PBXShellScriptBuildPhase;
                        buildActionMask = 2147483647;
index 1ae95aef050604c27b87667ad90a885c26da6c1c..7438cad7386c2b791741c4d1badae8c8538b152b 100644 (file)
@@ -1,3 +1,13 @@
+2011-09-21  Dan Bernstein  <mitz@apple.com>
+
+        WebCore part of: Prevent the WebKit frameworks from defining inappropriately-named Objective-C classes
+        https://bugs.webkit.org/show_bug.cgi?id=68451
+
+        Reviewed by Darin Adler.
+
+        * WebCore.xcodeproj/project.pbxproj: Added a script build phase that invokes
+        check-for-inappropriate-objc-class-names, allowing only class names prefixed with "DOM" or "Web".
+
 2011-09-21  Dan Bernstein  <mitz@apple.com>
 
         <rdar://problem/9768483> REGRESSION: Crash in RenderBlock::removeFloatingObjectsBelow()
index c238b146aae403358e3ff9019d66d1aff8722d7f..70044daac92d45bc7335da066565b9df56a1d0c4 100644 (file)
                                939D050109D9FF6B00984996 /* Check For Global Initializers */,
                                933457E60EBFDF6B00B80894 /* Check For Exit Time Destructors */,
                                5D0D540D0E9862F60029E223 /* Check For Weak VTables and Externals */,
+                               37A1EAA3142699BC0087F425 /* Check For Inappropriate Objective-C Class Names */,
                                5DF50887116F3077005202AB /* Check For Inappropriate Files In Framework */,
                        );
                        buildRules = (
                        shellPath = /bin/sh;
                        shellScript = "# Copy all the Inspector front-end resources.\nditto \"${SRCROOT}/inspector/front-end\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/inspector\"\nditto \"${BUILT_PRODUCTS_DIR}/DerivedSources/WebCore/InspectorBackendStub.js\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/inspector\"\n\n# Remove the WebKit.qrc file since it is not used on the Mac (this file is for Qt).\nrm -f \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/inspector/WebKit.qrc\"\n\n# Remove *.re2js files, they are only used to generate some .js files.\nrm -f \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/inspector/\"*.re2js\n\n# Remove any .svn directories that may have been copied over.\nfind \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/inspector\" -name \".svn\" -type d | xargs rm -rf\n";
                };
+               37A1EAA3142699BC0087F425 /* Check For Inappropriate Objective-C Class Names */ = {
+                       isa = PBXShellScriptBuildPhase;
+                       buildActionMask = 2147483647;
+                       files = (
+                       );
+                       inputPaths = (
+                               "$(TARGET_BUILD_DIR)/$(EXECUTABLE_PATH)",
+                       );
+                       name = "Check For Inappropriate Objective-C Class Names";
+                       outputPaths = (
+                       );
+                       runOnlyForDeploymentPostprocessing = 0;
+                       shellPath = /bin/sh;
+                       shellScript = "if [ \"${ACTION}\" = \"installhdrs\" ]; then\n    exit 0;\nfi\n\nif [ -f ../../Tools/Scripts/check-for-inappropriate-objc-class-names ]; then\n    ../../Tools/Scripts/check-for-inappropriate-objc-class-names DOM Web || exit $?\nfi";
+               };
                5D0D540D0E9862F60029E223 /* Check For Weak VTables and Externals */ = {
                        isa = PBXShellScriptBuildPhase;
                        buildActionMask = 2147483647;
index 068c3ff2e8f053f881f8ae238d22d3563c63c6ed..2b60a8b9b6e7e58c169b690377d85d9455e7c8b0 100644 (file)
@@ -1,3 +1,13 @@
+2011-09-21  Dan Bernstein  <mitz@apple.com>
+
+        WebKit part of: Prevent the WebKit frameworks from defining inappropriately-named Objective-C classes
+        https://bugs.webkit.org/show_bug.cgi?id=68451
+
+        Reviewed by Darin Adler.
+
+        * WebKit.xcodeproj/project.pbxproj: Added a script build phase that invokes
+        check-for-inappropriate-objc-class-names, allowing only class names prefixed with "Web" or "_Web".
+
 2011-09-19  Anders Carlsson  <andersca@apple.com>
 
         Remove WebViewEventHandling.mm
index edcf7f3451a2e7cd64efe5f7d00c73d3c456badf..25be63afb243928ea3c65414c9bdaeb8dc3309ae 100644 (file)
                                939D054F09DA02D500984996 /* Check For Global Initializers */,
                                9337D6540EBFE54D00DA3CB5 /* Check For Exit Time Destructors */,
                                5D0D54210E98631D0029E223 /* Check For Weak VTables and Externals */,
+                               3713F018142905B70036387F /* Check For Inappropriate Objective-C Class Names */,
                                5D88EE6C11407DE800BC3ABC /* Check For Framework Include Consistency */,
                                5DE6D18C0FCF231B002DE28C /* Symlink WebKitPluginHost in to place */,
                        );
                        shellPath = /bin/sh;
                        shellScript = "mkdir -p \"${TARGET_BUILD_DIR}/${PRIVATE_HEADERS_FOLDER_PATH}\"\nmkdir -p \"${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}\"\nmkdir -p \"${BUILT_PRODUCTS_DIR}/DerivedSources/WebKit\"\n\nif [ \"${ACTION}\" = \"build\" -o \"${ACTION}\" = \"install\" -o \"${ACTION}\" = \"installhdrs\" ]; then\n    make -C mac -f \"MigrateHeaders.make\" -j `/usr/sbin/sysctl -n hw.availcpu`\nfi\n";
                };
+               3713F018142905B70036387F /* Check For Inappropriate Objective-C Class Names */ = {
+                       isa = PBXShellScriptBuildPhase;
+                       buildActionMask = 2147483647;
+                       files = (
+                       );
+                       inputPaths = (
+                               "$(TARGET_BUILD_DIR)/$(EXECUTABLE_PATH)",
+                       );
+                       name = "Check For Inappropriate Objective-C Class Names";
+                       outputPaths = (
+                       );
+                       runOnlyForDeploymentPostprocessing = 0;
+                       shellPath = /bin/sh;
+                       shellScript = "if [ \"${ACTION}\" = \"installhdrs\" ]; then\n    exit 0;\nfi\n\nif [ -f ../../Tools/Scripts/check-for-inappropriate-objc-class-names ]; then\n    ../../Tools/Scripts/check-for-inappropriate-objc-class-names Web _Web || exit $?\nfi";
+               };
                5D0D54210E98631D0029E223 /* Check For Weak VTables and Externals */ = {
                        isa = PBXShellScriptBuildPhase;
                        buildActionMask = 2147483647;
index 1d328292f4ca5aedac785add2ece52ff7a363e75..846e6cea31099c358692f80979293e499e053523 100644 (file)
@@ -1,3 +1,13 @@
+2011-09-21  Dan Bernstein  <mitz@apple.com>
+
+        WebKit2 part of: Prevent the WebKit frameworks from defining inappropriately-named Objective-C classes
+        https://bugs.webkit.org/show_bug.cgi?id=68451
+
+        Reviewed by Darin Adler.
+
+        * WebKit2.xcodeproj/project.pbxproj: Added a script build phase that invokes
+        check-for-inappropriate-objc-class-names, allowing only class names prefixed with "WK" or "Web".
+
 2011-09-21  Jesus Sanchez-Palencia  <jesus.palencia@openbossa.org>
 
         [Qt][WK2] Implement Download support in WebProcess
index 22158d14e9bfe2564ad7484b8c0fcad60d74a2a2..ec8742769b2046387ef2931787b18c99077dc217 100644 (file)
                                5DF408C0131DD37C00130071 /* Check For Global Initializers */,
                                5DF408C4131DD3DB00130071 /* Check For Exit Time Destructors */,
                                5DF408C5131DD46700130071 /* Check For Weak VTables and Externals */,
+                               3713F0231429063D0036387F /* Check For Inappropriate Objective-C Class Names */,
                                5DF408C6131DD49700130071 /* Check For Framework Include Consistency */,
                                5DF408D1131DDBEC00130071 /* Check For Inappropriate Files In Framework */,
                        );
 /* End PBXResourcesBuildPhase section */
 
 /* Begin PBXShellScriptBuildPhase section */
+               3713F0231429063D0036387F /* Check For Inappropriate Objective-C Class Names */ = {
+                       isa = PBXShellScriptBuildPhase;
+                       buildActionMask = 2147483647;
+                       files = (
+                       );
+                       inputPaths = (
+                               "$(TARGET_BUILD_DIR)/$(EXECUTABLE_PATH)",
+                       );
+                       name = "Check For Inappropriate Objective-C Class Names";
+                       outputPaths = (
+                       );
+                       runOnlyForDeploymentPostprocessing = 0;
+                       shellPath = /bin/sh;
+                       shellScript = "if [ \"${ACTION}\" = \"installhdrs\" ]; then\n    exit 0;\nfi\n\nif [ -f ../../Tools/Scripts/check-for-inappropriate-objc-class-names ]; then\n    ../../Tools/Scripts/check-for-inappropriate-objc-class-names WK Web || exit $?\nfi";
+               };
                5DF408C0131DD37C00130071 /* Check For Global Initializers */ = {
                        isa = PBXShellScriptBuildPhase;
                        buildActionMask = 2147483647;
index fdf70c002246a2b6a59d33bc65fd0acb1772a801..d33e6f11b6a3965adbfa42c829730253415c6402 100644 (file)
@@ -1,3 +1,14 @@
+2011-09-21  Dan Bernstein  <mitz@apple.com>
+
+        Tools part of: Prevent the WebKit frameworks from defining inappropriately-named Objective-C classes
+        https://bugs.webkit.org/show_bug.cgi?id=68451
+
+        Reviewed by Darin Adler.
+
+        * Scripts/check-for-inappropriate-objc-class-names: Added. Checks for
+        Objective-C classes with names not having one of a list of prefixes
+        passed on the command line.
+
 2011-09-21  Xianzhu Wang  <wangxianzhu@chromium.org>
 
         Ensure TestWebKitAPI works on mac, win, chromium-mac and chromium-linux
diff --git a/Tools/Scripts/check-for-inappropriate-objc-class-names b/Tools/Scripts/check-for-inappropriate-objc-class-names
new file mode 100755 (executable)
index 0000000..0240db9
--- /dev/null
@@ -0,0 +1,111 @@
+#!/usr/bin/perl
+
+# Copyright (C) 2006, 2007, 2008, 2010, 2011 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+# THE POSSIBILITY OF SUCH DAMAGE.
+
+# "check-for-inappropriate-objc-class-names" script for WebKit Open Source Project
+
+# Intended to be invoked from an Xcode build step to check if a framework
+# defines any Objective-C class whose name does not have one of the prefixes
+# the framework is allowed to use.
+
+use warnings;
+use strict;
+
+use File::Basename;
+
+sub touch($);
+
+my @allowedPrefixes = @ARGV;
+
+die "No allowed prefixes passed on the command line" if !@allowedPrefixes;
+
+my $arch = $ENV{'CURRENT_ARCH'};
+my $target = $ENV{'TARGET_NAME'};
+my $variant = $ENV{'CURRENT_VARIANT'};
+my $coverageBuild = $ENV{'WEBKIT_COVERAGE_BUILD'};
+
+my $executablePath = "$ENV{'TARGET_BUILD_DIR'}/$ENV{'EXECUTABLE_PATH'}";
+
+my $buildTimestampPath = $ENV{'TARGET_TEMP_DIR'} . "/" . basename($0) . join('-', @allowedPrefixes) . ".timestamp";
+my $buildTimestampAge = -M $buildTimestampPath;
+my $executablePathAge = -M $executablePath;
+my $scriptAge = -M $0;
+
+my $pattern = "^(" . join('|', @allowedPrefixes) . ")";
+
+my $sawError = 0;
+
+if (!defined $executablePathAge || !defined $buildTimestampAge || $executablePathAge < $buildTimestampAge || $scriptAge < $buildTimestampAge) {
+    if (!open NM, "(nm -Ugjp '$executablePath' | sed 's/^/STDOUT:/') 2>&1 |") {
+        print "ERROR: Could not open $executablePath\n";
+        $sawError = 1;
+        next;
+    }
+    my @badNames;
+    while (<NM>) {
+        if (/^STDOUT:/) {
+            next unless /^STDOUT:_OBJC_CLASS_\$_/;
+            chomp;
+            my $className = substr($_, 21);
+            push(@badNames, $className) unless $className =~ /$pattern/;
+        } else {
+            print STDERR if $_ ne "nm: no name list\n";
+        }
+    }
+    close NM;
+
+    if (@badNames) {
+
+        my $shortName = $executablePath;
+        $shortName =~ s/.*\///;
+
+        print "ERROR: $shortName defines one or more Objective-C classes with inappropriate names. ($executablePath)\n";
+        for my $className (@badNames) {
+            print "ERROR: Inapproriate Objective-C class name: $className.\n";
+        }
+
+        if (@allowedPrefixes > 1) {
+            print "ERROR: Objective-C class names in $target must have one of these prefixes: " . join(", ", map('"' . $_ . '"', @allowedPrefixes)) . ".\n";
+        } else {
+            print "ERROR: Objective-C class names in $target must have the prefix \"" . $allowedPrefixes[0] . "\".\n";
+        }
+
+        $sawError = 1;
+    }
+}
+
+if ($sawError and !$coverageBuild) {
+    unlink $executablePath;
+    exit 1;
+}
+
+touch($buildTimestampPath);
+exit 0;
+
+sub touch($)
+{
+    my ($path) = @_;
+    open(TOUCH, ">", $path) or die "$!";
+    close(TOUCH);
+}