[Cocoa] Get rid of WK_ macros for nullability
[WebKit-https.git] / Source / WebKit2 / mac / postprocess-framework-headers.sh
1 #!/bin/sh
2 #
3 # Copyright (C) 2014 Apple Inc. All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
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.
13 #
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.
25 #
26
27 if [[ "${WK_FRAMEWORK_HEADER_POSTPROCESSING_DISABLED}" == "YES" ]]; then
28     exit 0;
29 fi
30
31 TIMESTAMP_PATH=${TARGET_TEMP_DIR}/${0##*/}
32
33 if [[ -e $TIMESTAMP_PATH && $0 -nt $TIMESTAMP_PATH ]]; then
34     rm "${TIMESTAMP_PATH}";
35 fi
36
37 function process_definitions () {
38     local DEFINITIONS_FILE=$1
39
40     if [[ ! -f "${DEFINITIONS_FILE}" ]]; then
41         return 1
42     fi
43
44     if [[ -e $TIMESTAMP_PATH && "${DEFINITIONS_FILE}" -nt $TIMESTAMP_PATH ]]; then
45         rm "${TIMESTAMP_PATH}";
46     fi
47
48     source "${DEFINITIONS_FILE}"
49 }
50
51 function rewrite_headers () {
52     if [[ "${PLATFORM_NAME}" == "macosx" ]]; then
53         [[ -n ${OSX_VERSION} ]] || OSX_VERSION=${MACOSX_DEPLOYMENT_TARGET/\./_}
54         [[ -n ${IOS_VERSION} ]] || IOS_VERSION="NA"
55     elif [[ "${PLATFORM_NAME}" =~ "iphone" ]]; then
56         [[ -n ${IOS_VERSION} ]] || IOS_VERSION=${IPHONEOS_DEPLOYMENT_TARGET/\./_}
57         [[ -n ${OSX_VERSION} ]] || OSX_VERSION="NA"
58     fi
59
60     SED_OPTIONS=(
61         -e 's/WK_ARRAY\(([^\)]+)\)/NSArray<\1>/g'
62         -e 's/WK_DICTIONARY\(([^\)]+)\)/NSDictionary<\1>/g'
63         -e 's/WK_SET\(([^\)]+)\)/NSSet<\1>/g'
64         -e s/WK_DESIGNATED_INITIALIZER/NS_DESIGNATED_INITIALIZER/
65         -e s/WK_UNAVAILABLE/NS_UNAVAILABLE/
66     )
67
68     if [[ -n "$OSX_VERSION" && -n "$IOS_VERSION" ]]; then
69         SED_OPTIONS+=(
70             -e s/WK_MAC_TBA/${OSX_VERSION}/g
71             -e s/WK_IOS_TBA/${IOS_VERSION}/g
72             -e s/WK_AVAILABLE/NS_AVAILABLE/
73             -e s/WK_DEPRECATED/NS_DEPRECATED/
74             -e s/WK_ENUM_AVAILABLE/NS_ENUM_AVAILABLE/
75             -e s/^WK_CLASS_AVAILABLE/NS_CLASS_AVAILABLE/
76             -e s/^WK_CLASS_DEPRECATED/NS_CLASS_DEPRECATED/
77         )
78     else
79         SED_OPTIONS+=(-e 's/WK_(CLASS_|ENUM_)?AVAILABLE(_IOS|_MAC)?\([^\)]+\)//g' -e 's/WK_(CLASS_)?DEPRECATED\([^\)]+\)//g')
80     fi
81
82     SED_OPTIONS+=(${OTHER_SED_OPTIONS[*]})
83
84     for HEADER_PATH in "${1}/"*.h; do
85         if [[ "$HEADER_PATH" -nt $TIMESTAMP_PATH ]]; then
86             ditto "${HEADER_PATH}" "${TARGET_TEMP_DIR}/${HEADER_PATH##*/}"
87             sed -i .tmp -E ${SED_OPTIONS[*]} "${TARGET_TEMP_DIR}/${HEADER_PATH##*/}" || exit $?
88             mv "${TARGET_TEMP_DIR}/${HEADER_PATH##*/}" "$HEADER_PATH"
89         fi
90     done
91 }
92
93 DEFINITIONS_PATH=usr/local/include/WebKitAdditions/Scripts/postprocess-framework-headers-definitions
94
95 process_definitions "${BUILT_PRODUCTS_DIR}/${DEFINITIONS_PATH}" || process_definitions "${SDKROOT}/${DEFINITIONS_PATH}"
96
97 rewrite_headers "${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}"
98 rewrite_headers "${TARGET_BUILD_DIR}/${PRIVATE_HEADERS_FOLDER_PATH}"
99
100 touch ${TIMESTAMP_PATH}