make.bash: use [[ rather than [

[[ is a compound command part of the language with structure,
whereas [ is simply a standard program with string arguments.
The former has a few significant advantages over the latter:

* Better syntax, e.g. && and || rather than -a and -o,
  as well as == rather than = for comparisons
* No need for fork+exec to evaluate each conditional
* Forgetting the closing token is an early parse error

The only advantage of [ over [[ is that [[ is Bash syntax,
whereas [ and "test" are portable POSIX Shell utilities.
However, this is a Bash script, so that is not a concern.

Change-Id: I8a4bdd16845bd67bf67a348d7d96d45d5b131d85
Reviewed-on: https://go-review.googlesource.com/c/go/+/531875
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Daniel Martí 2023-09-30 09:57:36 +01:00
parent 122b35e838
commit 352c8835e7

View File

@ -78,12 +78,12 @@ bootgo=1.20.6
set -e
if [ ! -f run.bash ]; then
if [[ ! -f run.bash ]]; then
echo 'make.bash must be run from $GOROOT/src' 1>&2
exit 1
fi
if [ "$GOBUILDTIMELOGFILE" != "" ]; then
if [[ "$GOBUILDTIMELOGFILE" != "" ]]; then
echo $(LC_TIME=C date) start make.bash >"$GOBUILDTIMELOGFILE"
fi
@ -114,7 +114,7 @@ fi
# so loop through the possible selinux mount points.
for se_mount in /selinux /sys/fs/selinux
do
if [ -d $se_mount -a -f $se_mount/booleans/allow_execstack -a -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
if [[ -d $se_mount && -f $se_mount/booleans/allow_execstack && -x /usr/sbin/selinuxenabled ]] && /usr/sbin/selinuxenabled; then
if ! cat $se_mount/booleans/allow_execstack | grep -c '^1 1$' >> /dev/null ; then
echo "WARNING: the default SELinux policy on, at least, Fedora 12 breaks "
echo "Go. You can enable the features that Go needs via the following "
@ -134,7 +134,7 @@ done
# Test for debian/kFreeBSD.
# cmd/dist will detect kFreeBSD as freebsd/$GOARCH, but we need to
# disable cgo manually.
if [ "$(uname -s)" = "GNU/kFreeBSD" ]; then
if [[ "$(uname -s)" == "GNU/kFreeBSD" ]]; then
export CGO_ENABLED=0
fi
@ -145,17 +145,17 @@ rm -f ./runtime/runtime_defs.go
verbose=false
vflag=""
if [ "$1" = "-v" ]; then
if [[ "$1" == "-v" ]]; then
verbose=true
vflag=-v
shift
fi
goroot_bootstrap_set=${GOROOT_BOOTSTRAP+"true"}
if [ -z "$GOROOT_BOOTSTRAP" ]; then
if [[ -z "$GOROOT_BOOTSTRAP" ]]; then
GOROOT_BOOTSTRAP="$HOME/go1.4"
for d in sdk/go$bootgo go$bootgo; do
if [ -d "$HOME/$d" ]; then
if [[ -d "$HOME/$d" ]]; then
GOROOT_BOOTSTRAP="$HOME/$d"
fi
done
@ -168,10 +168,10 @@ nogoenv() {
export GOROOT="$(cd .. && pwd)"
IFS=$'\n'; for go_exe in $(type -ap go); do
if [ ! -x "$GOROOT_BOOTSTRAP/bin/go" ]; then
if [[ ! -x "$GOROOT_BOOTSTRAP/bin/go" ]]; then
goroot=$(GOROOT= nogoenv "$go_exe" env GOROOT)
if [ "$goroot" != "$GOROOT" ]; then
if [ "$goroot_bootstrap_set" = "true" ]; then
if [[ "$goroot" != "$GOROOT" ]]; then
if [[ "$goroot_bootstrap_set" == "true" ]]; then
printf 'WARNING: %s does not exist, found %s from env\n' "$GOROOT_BOOTSTRAP/bin/go" "$go_exe" >&2
printf 'WARNING: set %s as GOROOT_BOOTSTRAP\n' "$goroot" >&2
fi
@ -179,7 +179,7 @@ IFS=$'\n'; for go_exe in $(type -ap go); do
fi
fi
done; unset IFS
if [ ! -x "$GOROOT_BOOTSTRAP/bin/go" ]; then
if [[ ! -x "$GOROOT_BOOTSTRAP/bin/go" ]]; then
echo "ERROR: Cannot find $GOROOT_BOOTSTRAP/bin/go." >&2
echo "Set \$GOROOT_BOOTSTRAP to a working Go tree >= Go $bootgo." >&2
exit 1
@ -192,7 +192,7 @@ echo "Building Go cmd/dist using $GOROOT_BOOTSTRAP. ($GOROOT_BOOTSTRAP_VERSION)"
if $verbose; then
echo cmd/dist
fi
if [ "$GOROOT_BOOTSTRAP" = "$GOROOT" ]; then
if [[ "$GOROOT_BOOTSTRAP" == "$GOROOT" ]]; then
echo "ERROR: \$GOROOT_BOOTSTRAP must not be set to \$GOROOT" >&2
echo "Set \$GOROOT_BOOTSTRAP to a working Go tree >= Go $bootgo." >&2
exit 1
@ -202,7 +202,7 @@ GOROOT="$GOROOT_BOOTSTRAP" nogoenv "$GOROOT_BOOTSTRAP/bin/go" build -o cmd/dist/
# -e doesn't propagate out of eval, so check success by hand.
eval $(./cmd/dist/dist env -p || echo FAIL=true)
if [ "$FAIL" = true ]; then
if [[ "$FAIL" == true ]]; then
exit 1
fi
@ -210,10 +210,10 @@ if $verbose; then
echo
fi
if [ "$1" = "--dist-tool" ]; then
if [[ "$1" == "--dist-tool" ]]; then
# Stop after building dist tool.
mkdir -p "$GOTOOLDIR"
if [ "$2" != "" ]; then
if [[ "$2" != "" ]]; then
cp cmd/dist/dist "$2"
fi
mv cmd/dist/dist "$GOTOOLDIR"/dist