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 for f
in $gofiles; do
103 tag1
=`echo $f | sed -e 's/^.*_\([^_]*\).go$/\1/'`
104 tag2
=`echo $f | sed -e 's/^.*_\([^_]*\)_[^_]*.go$/\1/'`
105 if test x
$tag1 = x
$f; then
108 if test x
$tag2 = x
$f; then
116 aix | android | darwin | dragonfly | freebsd | illumos | hurd | ios | js | linux | nacl | netbsd | openbsd | plan9 | solaris | windows | zos
)
119 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
)
123 # File name like x_amd64_random.go, where tag1=random.
124 # Don't match based on tag2.
133 aix | android | darwin | dragonfly | freebsd | hurd | ios | illumos | js | linux | nacl | netbsd | openbsd | plan9 | solaris | windows | zos
)
136 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
)
141 if test x
$tag1 != xnonmatchingtag
-a x
$tag2 != xnonmatchingtag
; then
142 # Pipe through cat so that `set -e` doesn't affect fgrep.
143 tags
=`sed '/^package /q' < $f | grep '^// *+build ' | cat`
151 "+build" |
"//+build")
152 if test "$first" = "true"; then
154 elif test "$match" = "false"; then
159 $goos |
$goarch |
$cgotag |
$cmdlinetag |
"gccgo" |
"goexperiment.fieldtrack" | go1.
[0-9] | go1.
[0-9][0-9])
162 "!"$goos |
"!"$goarch |
"!"$cgotag |
"!"$cmdlinetag |
"!gccgo" |
"!goexperiment.fieldtrack" |
"!"go1.
[0-9] |
"!"go1.1
[0-7])
166 for ctag
in `echo $tag | sed -e 's/,/ /g'`; do
168 $goos |
$goarch |
$cgotag |
$cmdlinetag |
"gccgo" |
"goexperiment.fieldtrack" | go1.
[0-9] | go1.
[0-9][0-9])
170 "!"$goos |
"!"$goarch |
"!"$cgotag |
"!"$cmdlinetag |
"!gccgo" |
"!goexperiment.fieldtrack" |
"!"go1.
[0-9] |
"!"go1.1
[0-7])
180 if test "$cmatch" = "true"; then
190 if test "$match" = "false" -a "$first" = "false"; then
194 if test "$omatch" = "true"; then
195 matched
="$matched $srcdir/$f"
200 echo $matched $extrafiles