kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/examples/bazel/setup-bazel-repo.sh (about)

     1  #!/bin/bash -e
     2  #
     3  # Copyright 2015 The Kythe Authors. All rights reserved.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #    http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  #
    17  # Utility script to setup the Bazel repository to work with the kythe-index.sh script.
    18  
    19  EXAMPLE_ROOT="$(realpath -s "$(dirname "$0")")"
    20  
    21  usage() {
    22    cat <<EOF
    23  Usage: setup-bazel-repo.sh <bazel_root>
    24  
    25  Utility script to setup the Bazel repository to work with the kythe-index.sh script.
    26  EOF
    27  }
    28  
    29  BAZEL_ROOT=
    30  
    31  case $# in
    32    1)
    33      BAZEL_ROOT="$1" ;;
    34    *)
    35      usage
    36      exit 1 ;;
    37  esac
    38  
    39  cd "$BAZEL_ROOT"
    40  
    41  if grep -q 'Kythe extraction setup' WORKSPACE; then
    42    echo "ERROR: $BAZEL_ROOT looks setup already" >&2
    43    echo "Maybe run \`git checkout . && git clean -fd\` in $BAZEL_ROOT?" >&2
    44    exit 1
    45  fi
    46  
    47  # TODO(#3272): Kythe's protobuf dependency conflicts with Bazel's vendoring
    48  sed -i 's/"com_google_protobuf"/"com_google_protobuf_vendored"/' WORKSPACE
    49  
    50  cat "${EXAMPLE_ROOT}/bazel.WORKSPACE" >> WORKSPACE