blob: 7e1544ee850ba3608589b0319c201bdb0f286098 [file] [log] [blame]
Damien Martin-Guillerezd47a8ef2015-06-10 11:54:50 +00001#!/bin/bash
2
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00003# Copyright 2015 The Bazel Authors. All rights reserved.
Damien Martin-Guillerezd47a8ef2015-06-10 11:54:50 +00004#
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.
21base_workspace=${WORKSPACE_DIR}/base_workspace
22mkdir -p "$base_workspace"
23rm -f "${base_workspace}/tools" && ln -s "$(pwd)/tools" "${base_workspace}/tools"
24rm -f "${base_workspace}/third_party" && ln -s "$(pwd)/third_party" "${base_workspace}/third_party"
25rm -f "${base_workspace}/examples" && ln -s "$(pwd)/examples" "${base_workspace}/examples"
David Chenf54fc602015-07-02 09:14:32 +000026rm -rf "${base_workspace}/src"
Damien Martin-Guillerezd47a8ef2015-06-10 11:54:50 +000027
28# Create a bazelrc file with the base_workspace directory in the package path.
29bazelrc='build --package_path %workspace%:'${base_workspace}
30bazelrc="${bazelrc}"$'\nfetch --package_path %workspace%:'${base_workspace}
31bazelrc="${bazelrc}"$'\nquery --package_path %workspace%:'${base_workspace}
32if [ -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
36elif [ ! -f $HOME/.bazelrc ]; then
37 display "$INFO Creating a .bazelrc pointing to $base_workspace"
38 echo -e "$bazelrc" > $HOME/.bazelrc
39else
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"
48fi