Created
August 15, 2022 18:04
-
-
Save EricCousineau-TRI/ca97ccc404ece082885d71c559d83936 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Generates initial `~/.bazelrc` (for use in any Bazel project (e.g. Drake, | |
# Anzu, etc.) | |
set -euo pipefail | |
dotfile=~/.bazelrc | |
dotfile_user= | |
echo "Check if ${dotfile} exists." | |
if [[ -f ${dotfile} ]]; then | |
echo "${dotfile}: already exists! Will not overwrite." | |
dotfile_user=${dotfile} | |
dotfile=$(mktemp) | |
echo "Instead, writing to: ${dotfile}" | |
fi | |
echo "Write ${dotfile}" | |
cat > ${dotfile} <<EOF | |
# .bazelrc options. For more information, please see: | |
# https://docs.bazel.build/versions/master/guide.html#bazelrc | |
# https://docs.bazel.build/versions/master/user-manual.html | |
build -j HOST_CPUS*0.5 | |
# N.B. Do not use 'common' for these flags since it will break commands like | |
# 'bazel version'. | |
fetch --repository_cache ${HOME}/.cache/bazel-externals | |
fetch --disk_cache ${HOME}/.cache/bazel_local_disk | |
build --repository_cache ${HOME}/.cache/bazel-externals | |
build --disk_cache ${HOME}/.cache/bazel_local_disk | |
# Uncomment these if you wish. | |
# build --progress_report_interval=5 | |
# Have GCC show color output. May invalidate prior builds. | |
# build --cxxopt -fdiagnostics-color | |
EOF | |
if [[ -n ${dotfile_user} ]]; then | |
echo "Show diff" | |
echo | |
# N.B. Use readlink so that text comparison is performed. | |
# N.B. Ignore exit code. | |
git --no-pager diff --no-index \ | |
$(readlink -f ${dotfile_user}) ${dotfile} || : | |
echo | |
echo "Merge changes using:" | |
echo " $(git config diff.tool) ${dotfile} ${dotfile_user}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment