kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/cxx/extractor/xcode_wrapper.sh (about)

     1  #!/bin/bash
     2  # Copyright 2019 The Kythe Authors. All rights reserved.
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #   http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  #
    16  # Translate Bazel's special XCode parameters into paths based on the
    17  # environment variables `SDKROOT` and `DEVELOPER_DIR` before invoking
    18  # the C++ extractor.
    19  
    20  set -euo pipefail
    21  # --- begin runfiles.bash initialization ---
    22  if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
    23      if [[ -f "$0.runfiles_manifest" ]]; then
    24        export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest"
    25      elif [[ -f "$0.runfiles/MANIFEST" ]]; then
    26        export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST"
    27      elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
    28        export RUNFILES_DIR="$0.runfiles"
    29      fi
    30  fi
    31  if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
    32    # shellcheck disable=SC1090
    33    source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash"
    34  elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
    35    # shellcheck disable=SC1090
    36    source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \
    37              "$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)"
    38  else
    39    echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash"
    40    exit 1
    41  fi
    42  # --- end runfiles.bash initialization ---
    43  
    44  EXTRACTOR="$(rlocation io_kythe/kythe/cxx/extractor/cxx_extractor)"
    45  
    46  # Pick values for DEVELOPER_DIR and SDKROOT as appropriate (if they weren't set)
    47  WRAPPER_DEVDIR="${DEVELOPER_DIR:-}"
    48  if [[ -z "${WRAPPER_DEVDIR}" ]] ; then
    49    WRAPPER_DEVDIR="$(xcode-select -p)"
    50  fi
    51  
    52  CLANG_PATH=$(xcrun -f clang)
    53  
    54  # Subsitute toolkit path placeholders.
    55  UPDATEDARGS=()
    56  for ARG in "$@" ; do
    57    ARG="${ARG//__BAZEL_XCODE_DEVELOPER_DIR__/${WRAPPER_DEVDIR}}"
    58    ARG="${ARG//__BAZEL_XCODE_SDKROOT__/${SDKROOT}}"
    59    ARG="${ARG//__KYTHE_XCODE_CLANG_PATH__/${CLANG_PATH}}"
    60    UPDATEDARGS+=("${ARG}")
    61  done
    62  
    63  exec "$EXTRACTOR" "${UPDATEDARGS[@]}"