blob: fcf71f118f2646c822582124b2656d3798a16520 [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
Chris Parsons8b77a002020-10-27 18:59:25 -040062# TODO(cparsons): Use USE_BAZEL=1 instead once "mixed Soong/Bazel builds" are
63# production ready.
64export USE_BAZEL_ANALYSIS=1
65# TODO(cparsons): Retrieve this information in either envsetup.sh or
66# bazel.sh.
Chris Parsonsf3c96ef2020-09-29 02:23:17 -040067export BAZEL_HOME="$BASE_DIR/bazelhome"
68export BAZEL_OUTPUT_BASE="$BASE_DIR/output"
69export BAZEL_WORKSPACE="$(gettop)"
70
Chris Parsons8b77a002020-10-27 18:59:25 -040071echo "USE_BAZEL_ANALYSIS=${USE_BAZEL_ANALYSIS}"
Chris Parsonsf3c96ef2020-09-29 02:23:17 -040072echo "BAZEL_PATH=${BAZEL_PATH}"
73echo "BAZEL_HOME=${BAZEL_HOME}"
74echo "BAZEL_OUTPUT_BASE=${BAZEL_OUTPUT_BASE}"
75echo "BAZEL_WORKSPACE=${BAZEL_WORKSPACE}"
76
77mkdir -p $BAZEL_HOME
78mkdir -p $BAZEL_OUTPUT_BASE