setup_go_workspace_for_soong.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. set -e
  3. # Copyright 2017 Google Inc. 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. #mounts the components of soong into a directory structure that Go tools and editors expect
  17. #move to the script's directory
  18. cd "$(dirname $0)"
  19. SCRIPT_PATH="$PWD"
  20. #find the root of the Repo checkout
  21. cd "${SCRIPT_PATH}"/../../..
  22. ANDROID_PATH="${PWD}"
  23. OUTPUT_PATH="$(echo ${GOPATH} | sed 's/\:.*//')" #if GOPATH contains multiple paths, use the first one
  24. if [ -z "${OUTPUT_PATH}" ]; then
  25. 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"
  26. exit 1
  27. fi
  28. function confirm() {
  29. while true; do
  30. echo "Will create GOPATH-compatible directory structure at ${OUTPUT_PATH}"
  31. echo -n "Ok [Y/n]?"
  32. read decision
  33. if [ "${decision}" == "y" -o "${decision}" == "Y" -o "${decision}" == "" ]; then
  34. return 0
  35. else
  36. if [ "${decision}" == "n" ]; then
  37. return 1
  38. else
  39. echo "Invalid choice ${decision}; choose either 'y' or 'n'"
  40. fi
  41. fi
  42. done
  43. }
  44. function bindAll() {
  45. bindOne "${ANDROID_PATH}/build/blueprint" "${OUTPUT_PATH}/src/github.com/google/blueprint"
  46. bindOne "${ANDROID_PATH}/build/soong" "${OUTPUT_PATH}/src/android/soong"
  47. bindOne "${ANDROID_PATH}/art/build" "${OUTPUT_PATH}/src/android/soong/art"
  48. bindOne "${ANDROID_PATH}/external/llvm/soong" "${OUTPUT_PATH}/src/android/soong/llvm"
  49. bindOne "${ANDROID_PATH}/external/clang/soong" "${OUTPUT_PATH}/src/android/soong/clang"
  50. echo
  51. echo "Created GOPATH-compatible directory structure at ${OUTPUT_PATH}"
  52. }
  53. function bindOne() {
  54. #causes $newPath to mirror $existingPath
  55. existingPath="$1"
  56. newPath="$2"
  57. mkdir -p "$newPath"
  58. echoAndDo bindfs "${existingPath}" "${newPath}"
  59. }
  60. function echoAndDo() {
  61. echo "$@"
  62. eval "$@"
  63. }
  64. if confirm; then
  65. echo
  66. bindAll
  67. else
  68. echo "skipping due to user request"
  69. exit 1
  70. fi