blob: 2ca8baf98cae20807549925708c9bbb2c19312a1 [file] [log] [blame]
Chris Parsonsf3c96ef2020-09-29 02:23:17 -04001#!/bin/bash
2
3# Copyright 2020 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
17# Helper script for setting environment variables required for Bazel/Soong
18# mixed builds prototype. For development use only.
19#
20# Usage:
21# export BAZEL_PATH=[some_bazel_path] && source bazelenv.sh
22#
23# If BAZEL_PATH is not set, `which bazel` will be used
24# to locate the appropriate bazel to use.
25
26
27# Function to find top of the source tree (if $TOP isn't set) by walking up the
28# tree.
29function gettop
30{
31 local TOPFILE=build/soong/root.bp
32 if [ -n "${TOP-}" -a -f "${TOP-}/${TOPFILE}" ] ; then
33 # The following circumlocution ensures we remove symlinks from TOP.
34 (cd $TOP; PWD= /bin/pwd)
35 else
36 if [ -f $TOPFILE ] ; then
37 # The following circumlocution (repeated below as well) ensures
38 # that we record the true directory name and not one that is
39 # faked up with symlink names.
40 PWD= /bin/pwd
41 else
42 local HERE=$PWD
43 T=
44 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
45 \cd ..
46 T=`PWD= /bin/pwd -P`
47 done
48 \cd $HERE
49 if [ -f "$T/$TOPFILE" ]; then
50 echo $T
51 fi
52 fi
53 fi
54}
55
56BASE_DIR="$(mktemp -d)"
57
58if [ -z "$BAZEL_PATH" ] ; then
59 export BAZEL_PATH="$(which bazel)"
60fi
61
62export USE_BAZEL=1
63export BAZEL_HOME="$BASE_DIR/bazelhome"
64export BAZEL_OUTPUT_BASE="$BASE_DIR/output"
65export BAZEL_WORKSPACE="$(gettop)"
66
67echo "USE_BAZEL=${USE_BAZEL}"
68echo "BAZEL_PATH=${BAZEL_PATH}"
69echo "BAZEL_HOME=${BAZEL_HOME}"
70echo "BAZEL_OUTPUT_BASE=${BAZEL_OUTPUT_BASE}"
71echo "BAZEL_WORKSPACE=${BAZEL_WORKSPACE}"
72
73mkdir -p $BAZEL_HOME
74mkdir -p $BAZEL_OUTPUT_BASE