22set -e # exit when any command fails
33set -x # show all commands being run
44
5- # Default to Go 1.18 if GO_VERSION is not set.
6- #
7- # Use the "=" operator (instead of the more common ":-" operator) so that it
8- # allows setting GO_VERSION="" to use the Go installation in the PATH, and it
9- # sets the GO_VERSION variable if the default is used.
10- GC=go${GO_VERSION=" 1.18" }
5+ : ${GC:= go${GO_VERSION=" 1.18" } }
6+
117COMPILE_CHECK_DIR=" internal/cmd/compilecheck"
8+ ARCHITECTURES=(" 386" " arm" " arm64" " ppc64le" " s390x" )
9+ BUILD_CMD=" ${GC} build -buildvcs=false"
1210
1311# compile_check will attempt to build the internal/test/compilecheck project
1412# using the provided Go version. This is to simulate an end-to-end use case.
1513function compile_check {
1614 # Change the directory to the compilecheck test directory.
17- pushd ${COMPILE_CHECK_DIR}
15+ pushd " ${COMPILE_CHECK_DIR} " > /dev/null
1816
1917 # If a custom Go version is set using the GO_VERSION env var (e.g. "1.18"),
2018 # add the GOPATH bin directory to PATH and then install that Go version.
@@ -29,29 +27,22 @@ function compile_check {
2927 ${GC} version
3028 ${GC} mod tidy
3129
32- # Check simple build.
33- ${GC} build ./...
30+ # Standard build
31+ $BUILD_CMD ./...
3432
35- # Check build with dynamic linking.
36- ${GC} build -buildmode=plugin
33+ # Dynamic linking
34+ $BUILD_CMD -buildmode=plugin
3735
3836 # Check build with tags.
39- ${GC} build $BUILD_TAGS ./...
37+ [[ -n " $BUILD_TAGS " ]] && $BUILD_CMD $BUILD_TAGS ./...
4038
4139 # Check build with various architectures.
42- GOOS=linux GOARCH=386 ${GC} build ./...
43- GOOS=linux GOARCH=arm ${GC} build ./...
44- GOOS=linux GOARCH=arm64 ${GC} build ./...
45- GOOS=linux GOARCH=amd64 ${GC} build ./...
46- GOOS=linux GOARCH=ppc64le ${GC} build ./...
47- GOOS=linux GOARCH=s390x ${GC} build ./...
48-
49- # Remove the binaries.
50- rm compilecheck
51- rm compilecheck.so
40+ for ARCH in " ${ARCHITECTURES[@]} " ; do
41+ GOOS=linux GOARCH=$ARCH $BUILD_CMD ./...
42+ done
5243
5344 # Change the directory back to the working directory.
54- popd
45+ popd > /dev/null
5546}
5647
5748compile_check
0 commit comments