Skip to content

all: format all shell scripts in Go repo with shfmt #45125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions misc/cgo/fortran/test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ goos=$(go env GOOS)

libext="so"
if [ "$goos" = "darwin" ]; then
libext="dylib"
libext="dylib"
elif [ "$goos" = "aix" ]; then
libtext="a"
libtext="a"
fi

case "$FC" in
*gfortran*)
libpath=$(dirname $($FC -print-file-name=libgfortran.$libext))
if [ "$goos" != "aix" ]; then
RPATH_FLAG="-Wl,-rpath,$libpath"
RPATH_FLAG="-Wl,-rpath,$libpath"
fi
export CGO_LDFLAGS="$CGO_LDFLAGS $RPATH_FLAG -L $libpath"
;;
esac

if ! $FC helloworld/helloworld.f90 -o /dev/null >& /dev/null; then
if ! $FC helloworld/helloworld.f90 -o /dev/null >&/dev/null; then
echo "skipping Fortran test: could not build helloworld.f90 with $FC"
exit 0
fi
Expand Down
4 changes: 2 additions & 2 deletions misc/ios/clangwrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ else
CLANGARCH="x86_64"
fi

SDK_PATH=`xcrun --sdk $SDK --show-sdk-path`
SDK_PATH=$(xcrun --sdk $SDK --show-sdk-path)
export IPHONEOS_DEPLOYMENT_TARGET=5.1
# cmd/cgo doesn't support llvm-gcc-4.2, so we have to use clang.
CLANG=`xcrun --sdk $SDK --find clang`
CLANG=$(xcrun --sdk $SDK --find clang)

exec "$CLANG" -arch $CLANGARCH -isysroot "$SDK_PATH" -m${PLATFORM}-version-min=10.0 "$@"
2 changes: 1 addition & 1 deletion src/all.bash
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ OLDPATH="$PATH"
. ./make.bash "$@" --no-banner
bash run.bash --no-rebuild
PATH="$OLDPATH"
$GOTOOLDIR/dist banner # print build info
$GOTOOLDIR/dist banner # print build info
2 changes: 1 addition & 1 deletion src/bootstrap.bash
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ if [ "$BOOTSTRAP_FORMAT" = "mintgz" ]; then
find . -type l -exec rm {} \;

echo "Writing ${OUTGZ} ..."
tar cf - . | gzip -9 > ../$OUTGZ
tar cf - . | gzip -9 >../$OUTGZ
cd ..
ls -l "$(pwd)/$OUTGZ"
exit 0
Expand Down
3 changes: 1 addition & 2 deletions src/buildall.bash
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ non_linux_targets() {
targets="$(linux_targets) $(non_linux_targets)"

failed=false
for target in $targets
do
for target in $targets; do
echo ""
echo "### Building $target"
export GOOS=$(echo $target | sed 's/-.*//')
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/ssa/gen/cover.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env bash
# Copyright 2020 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
Expand Down
27 changes: 17 additions & 10 deletions src/cmp.bash
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,46 @@ FLAGS2="-newexport=1"
echo
echo
echo "1a) clean build using $FLAGS1"
(export GO_GCFLAGS="$FLAGS1"; sh make.bash)
(
export GO_GCFLAGS="$FLAGS1"
sh make.bash
)

echo
echo
echo "1b) save go build output for all packages"
for pkg in `go list std`; do
for pkg in $(go list std); do
echo $pkg
DIR=$GOROOT/src/$pkg
go build -gcflags "$FLAGS1 -S" -o /dev/null $pkg &> $DIR/old.txt
go build -gcflags "$FLAGS1 -S" -o /dev/null $pkg &>$DIR/old.txt
done

echo
echo
echo "2a) clean build using $FLAGS2"
(export GO_GCFLAGS="$FLAGS2"; sh make.bash)
(
export GO_GCFLAGS="$FLAGS2"
sh make.bash
)

echo
echo
echo "2b) save go build output for all packages"
for pkg in `go list std`; do
for pkg in $(go list std); do
echo $pkg
DIR=$GOROOT/src/$pkg
go build -gcflags "$FLAGS2 -S" -o /dev/null $pkg &> $DIR/new.txt
go build -gcflags "$FLAGS2 -S" -o /dev/null $pkg &>$DIR/new.txt
done

echo
echo
echo "3) compare assembly files"
for pkg in `go list std`; do
for pkg in $(go list std); do
DIR=$GOROOT/src/$pkg

if cmp $DIR/old.txt $DIR/new.txt &> /dev/null
then rm $DIR/old.txt $DIR/new.txt
else echo "==> $DIR"
if cmp $DIR/old.txt $DIR/new.txt &>/dev/null; then
rm $DIR/old.txt $DIR/new.txt
else
echo "==> $DIR"
fi
done
11 changes: 6 additions & 5 deletions src/make.bash
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,9 @@ fi
# Test for bad SELinux.
# On Fedora 16 the selinux filesystem is mounted at /sys/fs/selinux,
# so loop through the possible selinux mount points.
for se_mount in /selinux /sys/fs/selinux
do
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 ! cat $se_mount/booleans/allow_execstack | grep -c '^1 1$' >> /dev/null ; 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 "
echo "command (as root):"
Expand Down Expand Up @@ -154,14 +153,16 @@ fi

export GOROOT_BOOTSTRAP=${GOROOT_BOOTSTRAP:-$HOME/go1.4}
export GOROOT="$(cd .. && pwd)"
IFS=$'\n'; for go_exe in $(type -ap go); do
IFS=$'\n'
for go_exe in $(type -ap go); do
if [ ! -x "$GOROOT_BOOTSTRAP/bin/go" ]; then
goroot=$(GOROOT='' GOOS='' GOARCH='' "$go_exe" env GOROOT)
if [ "$goroot" != "$GOROOT" ]; then
GOROOT_BOOTSTRAP=$goroot
fi
fi
done; unset IFS
done
unset IFS
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 1.4." >&2
Expand Down
2 changes: 1 addition & 1 deletion src/race.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

set -e

function usage {
function usage() {
echo 'race detector is only supported on linux/amd64, linux/ppc64le, linux/arm64, freebsd/amd64, netbsd/amd64, openbsd/amd64, darwin/amd64, and darwin/arm64' 1>&2
exit 1
}
Expand Down
8 changes: 4 additions & 4 deletions src/run.bash
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ if [ ! -f ../bin/go ]; then
fi

eval $(../bin/go env)
export GOROOT # The api test requires GOROOT to be set, so set it to match ../bin/go.
export GOROOT # The api test requires GOROOT to be set, so set it to match ../bin/go.
export GOPATH=/nonexist-gopath

unset CDPATH # in case user has it set
export GOBIN=$GOROOT/bin # Issue 14340
unset CDPATH # in case user has it set
export GOBIN=$GOROOT/bin # Issue 14340
unset GOFLAGS
unset GO111MODULE

Expand All @@ -49,7 +49,7 @@ ulimit -c 0
[ "$(ulimit -H -d)" = "unlimited" ] || ulimit -S -d $(ulimit -H -d)

# Thread count limit on NetBSD 7.
if ulimit -T &> /dev/null; then
if ulimit -T &>/dev/null; then
[ "$(ulimit -H -T)" = "unlimited" ] || ulimit -S -T $(ulimit -H -T)
fi

Expand Down
19 changes: 10 additions & 9 deletions src/syscall/mkall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,27 @@ run="sh"

case "$1" in
-syscalls)
for i in zsyscall*go
do
for i in zsyscall*go; do
# Run the command line that appears in the first line
# of the generated file to regenerate it.
sed 1q $i | sed 's;^// ;;' | sh > _$i && gofmt < _$i > $i
sed 1q $i | sed 's;^// ;;' | sh >_$i && gofmt <_$i >$i
rm _$i
done
exit 0
;;
-n)
run="cat"
shift
;;
esac

case "$#" in
0)
;;
0) ;;

*)
echo 'usage: mkall.sh [-n]' 1>&2
exit 2
;;
esac

GOOSARCH_in=syscall_$GOOSARCH.go
Expand Down Expand Up @@ -360,18 +361,18 @@ esac
(
if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi
syscall_goos="syscall_$GOOS.go"
case "$GOOS" in
case "$GOOS" in
darwin | dragonfly | freebsd | netbsd | openbsd)
syscall_goos="syscall_bsd.go $syscall_goos"
;;
esac
;;
esac
if [ -n "$mksyscall" ]; then echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go"; fi
if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
if [ -n "$mktypes" ]; then
# ztypes_$GOOSARCH.go could be erased before "go run mkpost.go" is called.
# Therefore, "go run" tries to recompile syscall package but ztypes is empty and it fails.
echo "$mktypes types_$GOOS.go |go run mkpost.go >ztypes_$GOOSARCH.go.NEW && mv ztypes_$GOOSARCH.go.NEW ztypes_$GOOSARCH.go";
echo "$mktypes types_$GOOS.go |go run mkpost.go >ztypes_$GOOSARCH.go.NEW && mv ztypes_$GOOSARCH.go.NEW ztypes_$GOOSARCH.go"
fi
if [ -n "$mkasm" ]; then echo "$mkasm $GOOS $GOARCH"; fi
) | $run
20 changes: 9 additions & 11 deletions src/syscall/mkerrors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ ccflags="$@"
# The gcc command line prints all the #defines
# it encounters while processing the input
echo "${!indirect} $includes" | $CC -x c - -E -dM $ccflags |
awk '
awk '
$1 != "#define" || $2 ~ /\(/ || $3 == "" {next}

$2 ~ /^E([ABCD]X|[BIS]P|[SD]I|S|FL)$/ {next} # 386 registers
Expand Down Expand Up @@ -333,16 +333,16 @@ ccflags="$@"
# Pull out the error names for later.
errors=$(
echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags |
awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print $2 }' |
sort
awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print $2 }' |
sort
)

# Pull out the signal names for later.
signals=$(
echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags |
awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print $2 }' |
egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT)' |
sort
awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print $2 }' |
egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT)' |
sort
)

# Again, writing regexps to a file.
Expand Down Expand Up @@ -387,8 +387,7 @@ enum { A = 'A', Z = 'Z', a = 'a', z = 'z' }; // avoid need for single quotes bel

int errors[] = {
"
for i in $errors
do
for i in $errors; do
echo -E ' '$i,
done

Expand All @@ -397,8 +396,7 @@ int errors[] = {

int signals[] = {
"
for i in $signals
do
for i in $signals; do
echo -E ' '$i,
done

Expand Down Expand Up @@ -432,7 +430,7 @@ main(void)
printf("\t%d: \"%s\",\n", e, buf);
}
printf("}\n\n");

printf("\n\n// Signal table\n");
printf("var signals = [...]string {\n");
qsort(signals, nelem(signals), sizeof signals[0], intcmp);
Expand Down