Skip to content

Commit

Permalink
Reintroduce .bazelrc and set --action_env defaults
Browse files Browse the repository at this point in the history
Shipping a .bazelrc was removed in 009b48b.
However, as per our "Specifying environment variables for actions" design
document, we want to ship a global rc file specifying the common environment
variables to be inherited. So revert that change and add the desired entries
to the global bazelrc file we're shipping.

--
Change-Id: Ib763677a951e1264ae92954df9b831374594d8b7
Reviewed-on: https://bazel-review.googlesource.com/#/c/6113
MOS_MIGRATED_REVID=133704608
  • Loading branch information
aehlig authored and laszlocsomor committed Sep 21, 2016
1 parent 6e2142a commit 96d4628
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
9 changes: 9 additions & 0 deletions scripts/packages/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ pkg_tar(
strip_prefix = ".",
)

pkg_tar(
name = "bazel-rc",
files = ["debian/bazel.bazelrc"],
mode = "0644",
package_dir = "/etc",
strip_prefix = "debian",
)

genrule(
name = "rename-bazel-completion",
srcs = ["//scripts:bash_completion"],
Expand All @@ -112,6 +120,7 @@ pkg_tar(
deps = [
":bazel-bin",
":bazel-completion",
":bazel-rc",
],
)

Expand Down
3 changes: 3 additions & 0 deletions scripts/packages/debian/bazel.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
common --action_env=PATH
common --action_env=LD_LIBRARY_PATH
common --action_env=TMPDIR
22 changes: 18 additions & 4 deletions scripts/packages/template_bin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,24 @@ usage() {
echo " --prefix=/some/path set the prefix path (default=/usr/local)." >&2
echo " --bin= set the binary folder path (default=%prefix%/bin)." >&2
echo " --base= set the base install path (default=%prefix%/lib/bazel)." >&2
echo " --bazelrc= set the path to bazelrc (default=/etc/bazel.bazelrc)." >&2
echo " --user configure for user install, expands to:" >&2
echo ' --bin=$HOME/bin --base=$HOME/.bazel' >&2
echo ' --bin=$HOME/bin --base=$HOME/.bazel --bazelrc=$HOME/.bazelrc' >&2
exit 1
}

prefix="/usr/local"
bin="%prefix%/bin"
base="%prefix%/lib/bazel"
bazelrc="/etc/bazel.bazelrc"

for opt in "${@}"; do
case $opt in
--prefix=*)
prefix="$(echo "$opt" | cut -d '=' -f 2-)"
;;
--bazelrc=*)
# TODO(kchodorow): remove once everything we're testing on CI contains
# this comment.
bazelrc="$(echo "$opt" | cut -d '=' -f 2-)"
;;
--bin=*)
bin="$(echo "$opt" | cut -d '=' -f 2-)"
Expand All @@ -68,6 +69,7 @@ for opt in "${@}"; do
--user)
bin="$HOME/bin"
base="$HOME/.bazel"
bazelrc="$HOME/.bazelrc"
;;
*)
usage
Expand All @@ -77,6 +79,7 @@ done

bin="${bin//%prefix%/${prefix}}"
base="${base//%prefix%/${prefix}}"
bazelrc="${bazelrc//%prefix%/${prefix}}"

test_write() {
local file="$1"
Expand Down Expand Up @@ -130,6 +133,7 @@ fi
# Test for write access
test_write "${bin}"
test_write "${base}"
test_write "${bazelrc}"

# Do the actual installation
echo -n "Uncompressing."
Expand All @@ -155,7 +159,17 @@ echo -n .
ln -s "${base}/bin/bazel" "${bin}/bazel"
echo -n .

if [ "${UID}" -ne 0 ]; then
if [ -f "${bazelrc}" ]; then
echo
echo "${bazelrc} already exists, moving it to ${bazelrc}.bak."
mv "${bazelrc}" "${bazelrc}.bak"
fi

# Not necessary, but this way it matches the Debian package.
touch "${bazelrc}"
if [ "${UID}" -eq 0 ]; then
chmod 0644 "${bazelrc}"
else
# Uncompress the bazel base install for faster startup time
"${bin}/bazel" help >/dev/null
fi
Expand Down

0 comments on commit 96d4628

Please sign in to comment.