-
Notifications
You must be signed in to change notification settings - Fork 882
/
compile_check.sh
executable file
·60 lines (47 loc) · 1.59 KB
/
compile_check.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
set -e # exit when any command fails
set -x # show all commands being run
GC=go
COMPILE_CHECK_DIR="internal/test/compilecheck"
DEV_MIN_VERSION=1.19
# version will flatten a version string of upto 4 components for inequality
# comparison.
function version {
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }';
}
# compile_check will attempt to build the the internal/test/compilecheck project
# using the provided Go version. This is to simulate an end-to-end use case.
# This check will only run on environments where the Go version is greater than
# or equal to the given version.
function compile_check {
# Change the directory to the compilecheck test directory.
cd ${COMPILE_CHECK_DIR}
# If the Go version is 1.15 or greater, then run "go mod tidy".
MACHINE_VERSION=`${GC} version | { read _ _ v _; echo ${v#go}; }`
if [ $(version $MACHINE_VERSION) -ge $(version 1.15) ]; then
go mod tidy
fi
# Test vendoring
go mod vendor
${GC} build -mod=vendor
rm -rf vendor
# Check simple build.
${GC} build ./...
# Check build with dynamic linking.
${GC} build -buildmode=plugin
# Check build with tags.
${GC} build $BUILD_TAGS ./...
# Check build with various architectures.
GOOS=linux GOARCH=386 ${GC} build ./...
GOOS=linux GOARCH=arm ${GC} build ./...
GOOS=linux GOARCH=arm64 ${GC} build ./...
GOOS=linux GOARCH=amd64 ${GC} build ./...
GOOS=linux GOARCH=ppc64le ${GC} build ./...
GOOS=linux GOARCH=s390x ${GC} build ./...
# Remove the binaries.
rm compilecheck
rm compilecheck.so
# Change the directory back to the working directory.
cd -
}
compile_check