| #!/bin/bash | |
| # | |
| # Copyright (C) 2019-2020 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. | |
| # | |
| if [[ -z "${SCRIPT_HEADER_VISIBILITY}" ]]; then | |
| exit 0 | |
| fi | |
| if [[ ${USE_INTERNAL_SDK} == "YES" ]]; then | |
| USE_APPLE_INTERNAL_SDK=1 | |
| else | |
| USE_APPLE_INTERNAL_SDK=0 | |
| fi | |
| UNIFDEF_OPTIONS=(-B) | |
| if [[ ${WK_PLATFORM_NAME} == macosx ]]; then | |
| UNIFDEF_OPTIONS+=(-DTARGET_OS_IPHONE=0 -DTARGET_OS_SIMULATOR=0) | |
| elif [[ ${WK_PLATFORM_NAME} == *simulator* ]]; then | |
| UNIFDEF_OPTIONS+=(-DTARGET_OS_IPHONE=1 -DTARGET_OS_SIMULATOR=1 "-DUSE_APPLE_INTERNAL_SDK=${USE_APPLE_INTERNAL_SDK}") | |
| else | |
| UNIFDEF_OPTIONS+=(-DTARGET_OS_IPHONE=1 -DTARGET_OS_SIMULATOR=0 "-DUSE_APPLE_INTERNAL_SDK=${USE_APPLE_INTERNAL_SDK}") | |
| fi | |
| # FIXME: We should consider making this logic general purpose so as to support keeping or removing | |
| # code guarded by an arbitrary feature define. For now it's sufficient to process touch- and gesture- | |
| # guarded code. | |
| for featureDefine in "ENABLE_TOUCH_EVENTS" "ENABLE_IOS_GESTURE_EVENTS" | |
| do | |
| # We assume a disabled feature is either undefined or has the empty string as its value. | |
| eval "isFeatureEnabled=\$$featureDefine" | |
| if [[ -z $isFeatureEnabled ]]; then | |
| UNIFDEF_OPTIONS+=("-D$featureDefine=0") | |
| else | |
| UNIFDEF_OPTIONS+=("-D$featureDefine=1") | |
| fi | |
| done | |
| SED_OPTIONS=() | |
| HEADER_NAME=$(basename "${SCRIPT_INPUT_FILE}") | |
| if [[ "${HEADER_NAME}" != "WebKitAvailability.h" ]]; then | |
| if [[ ${WK_PLATFORM_NAME} != macosx ]]; then | |
| SED_OPTIONS+=(-e "s/ *WEBKIT_((CLASS_|ENUM_)?(AVAILABLE|DEPRECATED))_MAC\([^)]+\)//g") | |
| fi | |
| fi | |
| if [[ ${#SED_OPTIONS[@]} -gt 0 ]]; then | |
| sed -E "${SED_OPTIONS[@]}" < "${SCRIPT_INPUT_FILE}" | | |
| unifdef ${UNIFDEF_OPTIONS[@]} > "${SCRIPT_OUTPUT_FILE_0}" | |
| exits=(${PIPESTATUS[@]}) | |
| [ ${exits[0]} -eq 0 -a ${exits[1]} -lt 2 ] | |
| else | |
| unifdef ${UNIFDEF_OPTIONS[@]} < "${SCRIPT_INPUT_FILE}" > "${SCRIPT_OUTPUT_FILE_0}" | |
| [ $? -lt 2 ] | |
| fi |