Fixed the build.
[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_SET\(([^\)]+)\)/NSSet<\1>/g'
63         -e s/WK_ASSUME_NONNULL_BEGIN/NS_ASSUME_NONNULL_BEGIN/
64         -e s/WK_ASSUME_NONNULL_END/NS_ASSUME_NONNULL_END/
65         -e s/WK_AVAILABLE/NS_AVAILABLE/
66         -e s/WK_DEPRECATED/NS_DEPRECATED/
67         -e s/WK_DESIGNATED_INITIALIZER/NS_DESIGNATED_INITIALIZER/
68         -e s/WK_ENUM_AVAILABLE/NS_ENUM_AVAILABLE/
69         -e s/WK_NULLABLE_PROPERTY/nullable,/
70         -e s/WK_NULLABLE_SPECIFIER/__nullable/g
71         -e s/WK_NULLABLE/nullable/g
72         -e s/WK_NULL_UNSPECIFIED/null_unspecified/
73         -e s/WK_UNAVAILABLE/NS_UNAVAILABLE/
74         -e s/^WK_CLASS_AVAILABLE/NS_CLASS_AVAILABLE/
75         -e s/^WK_CLASS_DEPRECATED/NS_CLASS_DEPRECATED/
76     )
77
78     if [[ -n "$OSX_VERSION" && -n "$IOS_VERSION" ]]; then
79         SED_OPTIONS+=(-e s/WK_MAC_TBA/${OSX_VERSION}/g -e s/WK_IOS_TBA/${IOS_VERSION}/g)
80     else
81         SED_OPTIONS+=(-e 's/WK_(CLASS_|ENUM_)?AVAILABLE(_IOS|_MAC)?\(.+\)//g' -e 's/WK_(CLASS_)?DEPRECATED\(.+\)//g')
82     fi
83
84     SED_OPTIONS+=(${OTHER_SED_OPTIONS[*]})
85
86     for HEADER_PATH in $1/*.h; do
87         if [[ $HEADER_PATH -nt $TIMESTAMP_PATH ]]; then
88             ditto ${HEADER_PATH} ${TARGET_TEMP_DIR}/${HEADER_PATH##*/}
89             sed -i .tmp -E ${SED_OPTIONS[*]} ${TARGET_TEMP_DIR}/${HEADER_PATH##*/} || exit $?
90             mv ${TARGET_TEMP_DIR}/${HEADER_PATH##*/} $HEADER_PATH
91         fi
92     done
93 }
94
95 DEFINITIONS_PATH=usr/local/include/WebKitAdditions/Scripts/postprocess-framework-headers-definitions
96
97 process_definitions "${BUILT_PRODUCTS_DIR}/${DEFINITIONS_PATH}" || process_definitions "${SDKROOT}/${DEFINITIONS_PATH}"
98
99 rewrite_headers ${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}
100 rewrite_headers ${TARGET_BUILD_DIR}/${PRIVATE_HEADERS_FOLDER_PATH}
101
102 touch ${TIMESTAMP_PATH}