Title: [243569] trunk/Source/WebKit
Revision
243569
Author
[email protected]
Date
2019-03-27 16:34:04 -0700 (Wed, 27 Mar 2019)

Log Message

Need a way to include WebKitAdditions code in WebKit API headers
https://bugs.webkit.org/show_bug.cgi?id=196173

Reviewed by Tim Horton.

Introduce a mechanism that allows us to insert code from WebKitAdditions into public or private SDK headers
using `#import`s of the form:

```
#if USE(APPLE_INTERNAL_SDK)
#import <WebKitAdditions/WKWebViewConfigurationAdditions.h>
#endif
```

The resulting header in the built products directory will contain the contents of the imported file inserted in
place of the `#if USE(APPLE_INTERNAL_SDK) … #endif` block; however, when building with the Apple internal SDK,
the additions header content will be imported by the usual means.

* mac/postprocess-framework-headers.sh:
* mac/replace-webkit-additions-includes.py: Added.

Add a step when post-processing framework headers to replace instances of `#if USE(APPLE_INTERNAL_SDK) … #endif`
with the text content of the additions files. The replacement script first searches in the built products
directory for the matching additions file, and falls back to the SDK if no matching file is found. If neither
are present (e.g. a build using the public SDK), then the block is simply replaced by the empty string.

(read_content_from_webkit_additions):
(main):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (243568 => 243569)


--- trunk/Source/WebKit/ChangeLog	2019-03-27 23:32:34 UTC (rev 243568)
+++ trunk/Source/WebKit/ChangeLog	2019-03-27 23:34:04 UTC (rev 243569)
@@ -1,3 +1,34 @@
+2019-03-27  Wenson Hsieh  <[email protected]>
+
+        Need a way to include WebKitAdditions code in WebKit API headers
+        https://bugs.webkit.org/show_bug.cgi?id=196173
+
+        Reviewed by Tim Horton.
+
+        Introduce a mechanism that allows us to insert code from WebKitAdditions into public or private SDK headers
+        using `#import`s of the form:
+
+        ```
+        #if USE(APPLE_INTERNAL_SDK)
+        #import <WebKitAdditions/WKWebViewConfigurationAdditions.h>
+        #endif
+        ```
+
+        The resulting header in the built products directory will contain the contents of the imported file inserted in
+        place of the `#if USE(APPLE_INTERNAL_SDK) … #endif` block; however, when building with the Apple internal SDK,
+        the additions header content will be imported by the usual means.
+
+        * mac/postprocess-framework-headers.sh:
+        * mac/replace-webkit-additions-includes.py: Added.
+
+        Add a step when post-processing framework headers to replace instances of `#if USE(APPLE_INTERNAL_SDK) … #endif`
+        with the text content of the additions files. The replacement script first searches in the built products
+        directory for the matching additions file, and falls back to the SDK if no matching file is found. If neither
+        are present (e.g. a build using the public SDK), then the block is simply replaced by the empty string.
+
+        (read_content_from_webkit_additions):
+        (main):
+
 2019-03-27  Andy Estes  <[email protected]>
 
         REGRESSION (r242686): package-root creates roots with broken symlinks in WebKit.framework/XPCServices/

Modified: trunk/Source/WebKit/mac/postprocess-framework-headers.sh (243568 => 243569)


--- trunk/Source/WebKit/mac/postprocess-framework-headers.sh	2019-03-27 23:32:34 UTC (rev 243568)
+++ trunk/Source/WebKit/mac/postprocess-framework-headers.sh	2019-03-27 23:34:04 UTC (rev 243569)
@@ -48,6 +48,14 @@
     source "${DEFINITIONS_FILE}"
 }
 
+function replace_webkit_additions_includes () {
+    if [[ -z `grep '#import <WebKitAdditions/.*\.h>' "${1}"` ]]; then
+        return 0
+    fi
+    python "$(dirname $0)/replace-webkit-additions-includes.py" "${1}" "${BUILT_PRODUCTS_DIR}" "${SDKROOT}"
+    return $?
+}
+
 function rewrite_headers () {
     if [[ "${WK_PLATFORM_NAME}" == "macosx" ]]; then
         [[ -n ${OSX_VERSION} ]] || OSX_VERSION=${MACOSX_DEPLOYMENT_TARGET}
@@ -81,6 +89,7 @@
     for HEADER_PATH in "${1}/"*.h; do
         if [[ "$HEADER_PATH" -nt $TIMESTAMP_PATH ]]; then
             ditto "${HEADER_PATH}" "${TARGET_TEMP_DIR}/${HEADER_PATH##*/}"
+            replace_webkit_additions_includes "${TARGET_TEMP_DIR}/${HEADER_PATH##*/}"
             sed -i .tmp -E "${SED_OPTIONS[@]}" "${TARGET_TEMP_DIR}/${HEADER_PATH##*/}" || exit $?
             mv "${TARGET_TEMP_DIR}/${HEADER_PATH##*/}" "$HEADER_PATH"
         fi

Added: trunk/Source/WebKit/mac/replace-webkit-additions-includes.py (0 => 243569)


--- trunk/Source/WebKit/mac/replace-webkit-additions-includes.py	                        (rev 0)
+++ trunk/Source/WebKit/mac/replace-webkit-additions-includes.py	2019-03-27 23:34:04 UTC (rev 243569)
@@ -0,0 +1,88 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2019 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.
+#
+
+import os
+import re
+import sys
+
+
+def read_content_from_webkit_additions(built_products_directory, sdk_root_directory, filename):
+    additions_path = os.path.join("usr/local/include/WebKitAdditions", filename)
+    try:
+        file_in_build_directory = open(os.path.join(built_products_directory, additions_path), "r")
+        return file_in_build_directory.read()
+    except:
+        try:
+            file_in_sdk_root = open(os.path.join(sdk_root_directory, additions_path), "r")
+            return file_in_sdk_root.read()
+        except:
+            return ""
+
+
+def main(argv=None):
+    if not argv:
+        argv = sys.argv
+
+    if len(argv) != 4:
+        print("Usage: replace-webkit-additions-includes.py <header_path> <built_products_directory> <sdk_root_directory>")
+        return 1
+
+    header_path = argv[1]
+    built_products_directory = argv[2]
+    sdk_root_directory = argv[3]
+    if not len(header_path):
+        print("(%s): header path unspecified" % argv[0])
+        return 1
+
+    if not len(built_products_directory):
+        print("(%s): built products directory unspecified" % argv[0])
+        return 1
+
+    if not len(sdk_root_directory):
+        print("(%s): SDK root directory unspecified" % argv[0])
+        return 1
+
+    additions_import_pattern = re.compile(r"\#if USE\(APPLE_INTERNAL_SDK\)\n#import <WebKitAdditions/(.*\.h)>\n#endif")
+    try:
+        with open(header_path, "r") as header:
+            header_contents = header.read()
+            match = additions_import_pattern.search(header_contents)
+            while match:
+                header_contents = header_contents[:match.start()] + read_content_from_webkit_additions(built_products_directory, sdk_root_directory, match.groups()[0]) + header_contents[match.end():]
+                match = additions_import_pattern.search(header_contents)
+            try:
+                with open(header_path, "w") as header:
+                    header.write(header_contents)
+            except:
+                print("(%s): failed to write to file: %s" % (argv[0], header_path))
+                return 1
+        return 0
+    except:
+        print("(%s): failed to read file: %s" % (argv[0], header_path))
+        return 1
+
+if __name__ == "__main__":
+    sys.exit(main(sys.argv))
Property changes on: trunk/Source/WebKit/mac/replace-webkit-additions-includes.py
___________________________________________________________________

Added: svn:executable

+* \ No newline at end of property
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to