github.com/westcoastroms/westcoastroms-build@v0.0.0-20190928114312-2350e5a73030/build/soong/scripts/setup_go_workspace_for_soong.sh (about)

     1  #!/bin/bash
     2  set -e
     3  
     4  # Copyright 2017 Google Inc. All rights reserved.
     5  #
     6  # Licensed under the Apache License, Version 2.0 (the "License");
     7  # you may not use this file except in compliance with the License.
     8  # You may obtain a copy of the License at
     9  #
    10  #     http://www.apache.org/licenses/LICENSE-2.0
    11  #
    12  # Unless required by applicable law or agreed to in writing, software
    13  # distributed under the License is distributed on an "AS IS" BASIS,
    14  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  # See the License for the specific language governing permissions and
    16  # limitations under the License.
    17  
    18  #mounts the components of soong into a directory structure that Go tools and editors expect
    19  
    20  #move to the script's directory
    21  cd "$(dirname $0)"
    22  SCRIPT_PATH="$PWD"
    23  
    24  #find the root of the Repo checkout
    25  cd "${SCRIPT_PATH}"/../../..
    26  ANDROID_PATH="${PWD}"
    27  OUTPUT_PATH="$(echo ${GOPATH} | sed 's/\:.*//')" #if GOPATH contains multiple paths, use the first one
    28  
    29  if [ -z "${OUTPUT_PATH}" ]; then
    30    echo "Error; could not determine the desired location at which to create a Go-compatible workspace. Please update GOPATH to specify the desired destination directory"
    31    exit 1
    32  fi
    33  
    34  function confirm() {
    35    while true; do
    36      echo "Will create GOPATH-compatible directory structure at ${OUTPUT_PATH}"
    37      echo -n "Ok [Y/n]?"
    38      read decision
    39      if [ "${decision}" == "y" -o "${decision}" == "Y" -o "${decision}" == "" ]; then
    40        return 0
    41      else
    42        if [ "${decision}" == "n" ]; then
    43          return 1
    44        else
    45          echo "Invalid choice ${decision}; choose either 'y' or 'n'"
    46        fi
    47      fi
    48    done
    49  }
    50  
    51  function bindAll() {
    52    bindOne "${ANDROID_PATH}/build/blueprint" "${OUTPUT_PATH}/src/github.com/google/blueprint"
    53    bindOne "${ANDROID_PATH}/build/soong" "${OUTPUT_PATH}/src/android/soong"
    54  
    55    bindOne "${ANDROID_PATH}/art/build" "${OUTPUT_PATH}/src/android/soong/art"
    56    bindOne "${ANDROID_PATH}/external/golang-protobuf" "${OUTPUT_PATH}/src/github.com/golang/protobuf"
    57    bindOne "${ANDROID_PATH}/external/llvm/soong" "${OUTPUT_PATH}/src/android/soong/llvm"
    58    bindOne "${ANDROID_PATH}/external/clang/soong" "${OUTPUT_PATH}/src/android/soong/clang"
    59    echo
    60    echo "Created GOPATH-compatible directory structure at ${OUTPUT_PATH}"
    61  }
    62  
    63  function bindOne() {
    64    #causes $newPath to mirror $existingPath
    65    existingPath="$1"
    66    newPath="$2"
    67    mkdir -p "$newPath"
    68    case $(uname -s) in
    69      Darwin)
    70        echoAndDo bindfs -o allow_recursion -n "${existingPath}" "${newPath}"
    71        ;;
    72      Linux)
    73        echoAndDo bindfs "${existingPath}" "${newPath}"
    74        ;;
    75    esac
    76  }
    77  
    78  function echoAndDo() {
    79    echo "$@"
    80    eval "$@"
    81  }
    82  
    83  if confirm; then
    84    echo
    85    bindAll
    86  else
    87    echo "skipping due to user request"
    88    exit 1
    89  fi