Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 3 | # Copyright 2015 The Bazel Authors. All rights reserved. |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 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 | # Set-up the base workspace, currently used as package_path to provide |
| 18 | # the tools directory. |
| 19 | |
| 20 | # Create symlinks so we can use tools and examples from the base_workspace. |
| 21 | base_workspace=${WORKSPACE_DIR}/base_workspace |
| 22 | mkdir -p "$base_workspace" |
| 23 | rm -f "${base_workspace}/tools" && ln -s "$(pwd)/tools" "${base_workspace}/tools" |
| 24 | rm -f "${base_workspace}/third_party" && ln -s "$(pwd)/third_party" "${base_workspace}/third_party" |
| 25 | rm -f "${base_workspace}/examples" && ln -s "$(pwd)/examples" "${base_workspace}/examples" |
David Chen | f54fc60 | 2015-07-02 09:14:32 +0000 | [diff] [blame] | 26 | rm -rf "${base_workspace}/src" |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 27 | |
| 28 | # Create a bazelrc file with the base_workspace directory in the package path. |
| 29 | bazelrc='build --package_path %workspace%:'${base_workspace} |
| 30 | bazelrc="${bazelrc}"$'\nfetch --package_path %workspace%:'${base_workspace} |
| 31 | bazelrc="${bazelrc}"$'\nquery --package_path %workspace%:'${base_workspace} |
| 32 | if [ -z "${HOME-}" ]; then |
| 33 | warning="$INFO No \$HOME variable set, cannot write .bazelrc file." |
| 34 | warning="$warning Consider adding $base_workspace to your package path" |
| 35 | display $warning |
| 36 | elif [ ! -f $HOME/.bazelrc ]; then |
| 37 | display "$INFO Creating a .bazelrc pointing to $base_workspace" |
| 38 | echo -e "$bazelrc" > $HOME/.bazelrc |
| 39 | else |
| 40 | while read rcline; do |
| 41 | if ! grep -q "$rcline" $HOME/.bazelrc; then |
| 42 | warning="$INFO You already have a .bazelrc. Make sure it contains the " |
| 43 | warning="$warning following package paths:\n\n$bazelrc\n\n" |
| 44 | display "$warning" |
| 45 | break |
| 46 | fi |
| 47 | done <<< "$bazelrc" |
| 48 | fi |