[JSC] JSC should have "parseFunction" to optimize Function constructor
[WebKit-https.git] / Source / JavaScriptCore / postprocess-headers.sh
1 #!/bin/sh
2 #
3 # Copyright (C) 2014-2018 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 [[ "${JSC_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         [[ -n ${OSX_VERSION_NUMBER} ]] || OSX_VERSION_NUMBER=${TARGET_MAC_OS_X_VERSION_MAJOR}
56         [[ -n ${IOS_VERSION_NUMBER} ]] || IOS_VERSION_NUMBER="0"
57     elif [[ "${PLATFORM_NAME}" =~ "iphone" ]]; then
58         [[ -n ${IOS_VERSION} ]] || IOS_VERSION=${IPHONEOS_DEPLOYMENT_TARGET}
59         [[ -n ${OSX_VERSION} ]] || OSX_VERSION="NA"
60         [[ -n ${OSX_VERSION_NUMBER} ]] || OSX_VERSION_NUMBER="0"
61         [[ -n ${IOS_VERSION_NUMBER} ]] || IOS_VERSION_NUMBER=${SDK_VERSION_MAJOR}
62     fi
63
64     SED_OPTIONS=(
65     )
66
67     if [[ -n "$OSX_VERSION" && -n "$IOS_VERSION" ]]; then
68         SED_OPTIONS+=(
69             -e s/JSC_MAC_TBA/${OSX_VERSION}/g
70             -e s/JSC_IOS_TBA/${IOS_VERSION}/g
71             -e s/JSC_MAC_VERSION_TBA/${OSX_VERSION_NUMBER}/g
72             -e s/JSC_IOS_VERSION_TBA/${IOS_VERSION_NUMBER}/g
73             -e s/JSC_API_AVAILABLE/API_AVAILABLE/
74             -e s/JSC_API_DEPRECATED/API_DEPRECATED/
75             -e "s/^JSC_CLASS_AVAILABLE/JSC_EXTERN API_AVAILABLE/"
76             -e "s/^JSC_CLASS_DEPRECATED/JSC_EXTERN API_DEPRECATED/"
77         )
78     else
79         SED_OPTIONS+=(
80             -e 's/JSC_(API_|CLASS_)AVAILABLE\(.*\)\s*\)//g'
81             -e 's/JSC_(API_|CLASS_)DEPRECATED(_WITH_REPLACEMENT)?\(.*\)\s*\)//g'
82             -e 's/JSC_(MAC|IOS)_VERSION_TBA/0/g'
83         )
84     fi
85
86     SED_OPTIONS+=(${OTHER_SED_OPTIONS[*]})
87
88     for HEADER_PATH in "${1}/"*.h; do
89         if [[ "$HEADER_PATH" -nt $TIMESTAMP_PATH ]]; then
90             ditto "${HEADER_PATH}" "${TARGET_TEMP_DIR}/${HEADER_PATH##*/}"
91             sed -i .tmp -E "${SED_OPTIONS[@]}" "${TARGET_TEMP_DIR}/${HEADER_PATH##*/}" || exit $?
92             mv "${TARGET_TEMP_DIR}/${HEADER_PATH##*/}" "$HEADER_PATH"
93         fi
94     done
95 }
96
97 DEFINITIONS_PATH=usr/local/include/WebKitAdditions/Scripts/postprocess-framework-headers-definitions
98
99 process_definitions "${BUILT_PRODUCTS_DIR}/${DEFINITIONS_PATH}" || process_definitions "${SDKROOT}/${DEFINITIONS_PATH}"
100
101 rewrite_headers "${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}"
102 rewrite_headers "${TARGET_BUILD_DIR}/${PRIVATE_HEADERS_FOLDER_PATH}"
103
104 touch ${TIMESTAMP_PATH}