3 # Copyright 2016 The Go Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style
5 # license that can be found in the LICENSE file.
7 # Given a source directory, returns the non-test Go files that should
8 # be built for this target. This implements Go's build constraints in
9 # a shell script. There is similar code in testsuite/gotest.
16 export LANG LC_ALL LC_CTYPE
22 cmdlinetag
="nosuchtag"
33 srcdir
=`echo $1 | sed -e 's/^--srcdir=//'`
42 goarch
=`echo $1 | sed -e 's/^--goarch=//'`
51 goos
=`echo $1 | sed -e 's/^--goos=//'`
60 extrafiles
=`echo $1 | sed -e 's/^--extrafiles=//'`
69 cmdlinetag
=`echo $1 | sed -e 's/^--tag=//'`
77 echo 1>&2 "unknown argument $arg"
96 if test "$gofiles" = ""; then
97 echo 1>&2 "no non-test .go files in $srcdir"
102 line
=$
(echo "$1" |
sed -e 's|//go:build ||')
103 line
=$
(echo "$line" |
sed -e 's/go1\.[0-9][0-9]*/1/g' -e 's/goexperiment\./goexperiment/')
106 for ones
in $goarch $goos $cgotag $cmdlinetag gccgo goexperimentfieldtrack
; do
107 line
=$
(echo "$line" |
sed -e "s/\\(${wrap}\\)${ones}\\(${wrap}\\)/"'\11\2/g')
109 # 386 is a special case since it looks like a number to the shell.
110 # We need it to be 0 if it's not $goarch.
111 if test "$goarch" != "386"; then
112 line
=$
(echo "$line" |
sed -e "s/\\(${wrap}\\)386\\(${wrap}\\)/\10\2/g")
118 for f
in $gofiles; do
119 tag1
=`echo $f | sed -e 's/^.*_\([^_]*\).go$/\1/'`
120 tag2
=`echo $f | sed -e 's/^.*_\([^_]*\)_[^_]*.go$/\1/'`
121 if test x
$tag1 = x
$f; then
124 if test x
$tag2 = x
$f; then
132 aix | android | darwin | dragonfly | freebsd | illumos | hurd | ios | js | linux | nacl | netbsd | openbsd | plan9 | solaris | windows | zos
)
135 386 | amd64 | amd64p32 | arm | armbe | arm64 | arm64be | alpha | ia64 | m68k | mips | mipsle | mips64 | mips64le | mips64p32 | mips64p32le | nios2 | ppc | ppc64 | ppc64le | riscv | riscv64 | s390 | s390x | sh | shbe | sparc | sparc64 | wasm
)
139 # File name like x_amd64_random.go, where tag1=random.
140 # Don't match based on tag2.
149 aix | android | darwin | dragonfly | freebsd | hurd | ios | illumos | js | linux | nacl | netbsd | openbsd | plan9 | solaris | windows | zos
)
152 386 | amd64 | amd64p32 | arm | armbe | arm64 | arm64be | alpha | ia64 | m68k | mips | mipsle | mips64 | mips64le | mips64p32 | mips64p32le | nios2 | ppc | ppc64 | ppc64le | riscv | riscv64 | s390 | s390x | sh | shbe | sparc | sparc64 | wasm
)
157 if test x
$tag1 = xnonmatchingtag
-o x
$tag2 = xnonmatchingtag
; then
161 # Check for go:build line
162 build
=$
(sed '/^package /q' < $f |
grep '^//go:build ' |
cat)
163 if test -n "$build"; then
164 if $
(gobuild
"$build"); then
165 matched
="$matched $srcdir/$f"
170 # No go:build line, check for +build lines.
171 # Pipe through cat so that `set -e` doesn't affect fgrep.
172 tags
=`sed '/^package /q' < $f | grep '^// *+build ' | cat`
180 "+build" |
"//+build")
181 if test "$first" = "true"; then
183 elif test "$match" = "false"; then
188 $goos |
$goarch |
$cgotag |
$cmdlinetag |
"gccgo" |
"goexperiment.fieldtrack" | go1.
[0-9] | go1.
[0-9][0-9])
191 "!"$goos |
"!"$goarch |
"!"$cgotag |
"!"$cmdlinetag |
"!gccgo" |
"!goexperiment.fieldtrack" |
"!"go1.
[0-9] |
"!"go1.1
[0-7])
195 for ctag
in `echo $tag | sed -e 's/,/ /g'`; do
197 $goos |
$goarch |
$cgotag |
$cmdlinetag |
"gccgo" |
"goexperiment.fieldtrack" | go1.
[0-9] | go1.
[0-9][0-9])
199 "!"$goos |
"!"$goarch |
"!"$cgotag |
"!"$cmdlinetag |
"!gccgo" |
"!goexperiment.fieldtrack" |
"!"go1.
[0-9] |
"!"go1.1
[0-7])
209 if test "$cmatch" = "true"; then
219 if test "$match" = "false" -a "$first" = "false"; then
223 if test "$omatch" = "true"; then
224 matched
="$matched $srcdir/$f"
228 echo $matched $extrafiles