compiler: only build thunk struct type when it is needed
[official-gcc.git] / libgo / match.sh
blobe5ed98de422fa8006a15fc58af73ea7b93a1cdc5
1 #!/bin/sh
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.
11 set -e
13 LANG=C
14 LC_ALL=C
15 LC_CTYPE=C
16 export LANG LC_ALL LC_CTYPE
18 srcdir=""
19 goarch=""
20 goos=""
21 extrafiles=""
22 cmdlinetag="nosuchtag"
23 cgotag="cgo"
25 for arg; do
26 case "x$arg" in
27 x--srcdir)
28 srcdir=$2
29 shift
30 shift
32 x--srcdir=*)
33 srcdir=`echo $1 | sed -e 's/^--srcdir=//'`
34 shift
36 x--goarch)
37 goarch=$2
38 shift
39 shift
41 x--goarch=*)
42 goarch=`echo $1 | sed -e 's/^--goarch=//'`
43 shift
45 x--goos)
46 goos=$2
47 shift
48 shift
50 x--goos=*)
51 goos=`echo $1 | sed -e 's/^--goos=//'`
52 shift
54 x--extrafiles)
55 extrafiles=$2
56 shift
57 shift
59 x--extrafiles=*)
60 extrafiles=`echo $1 | sed -e 's/^--extrafiles=//'`
61 shift
63 x--tag)
64 cmdlinetag=$2
65 shift
66 shift
68 x--tag=*)
69 cmdlinetag=`echo $1 | sed -e 's/^--tag=//'`
70 shift
72 x--nocgo)
73 cgotag="nosuchtag"
74 shift
77 echo 1>&2 "unknown argument $arg"
78 exit 1
80 esac
81 done
83 cd $srcdir
85 gofiles=
86 for f in *.go; do
87 case $f in
88 *_test.go)
90 *.go)
91 gofiles="$gofiles $f"
93 esac
94 done
96 if test "$gofiles" = ""; then
97 echo 1>&2 "no non-test .go files in $srcdir"
98 exit 1
101 gobuild() {
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/')
104 line=" $line "
105 wrap='[ ()!&|]'
106 for ones in $goarch $goos $cgotag $cmdlinetag gccgo goexperimentfieldtrack; do
107 line=$(echo "$line" | sed -e "s/\\(${wrap}\\)${ones}\\(${wrap}\\)/"'\11\2/g')
108 done
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")
114 return $((!($line)))
117 matched=
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
122 tag1=
124 if test x$tag2 = x$f; then
125 tag2=
128 case "$tag1" in
129 "") ;;
130 $goarch) ;;
131 $goos) ;;
132 aix | android | darwin | dragonfly | freebsd | illumos | hurd | ios | js | linux | nacl | netbsd | openbsd | plan9 | solaris | windows | zos)
133 tag1=nonmatchingtag
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)
136 tag1=nonmatchingtag
139 # File name like x_amd64_random.go, where tag1=random.
140 # Don't match based on tag2.
141 tag2=
143 esac
145 case "$tag2" in
146 "") ;;
147 $goarch) ;;
148 $goos) ;;
149 aix | android | darwin | dragonfly | freebsd | hurd | ios | illumos | js | linux | nacl | netbsd | openbsd | plan9 | solaris | windows | zos)
150 tag2=nonmatchingtag
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)
153 tag2=nonmatchingtag
155 esac
157 if test x$tag1 = xnonmatchingtag -o x$tag2 = xnonmatchingtag; then
158 continue
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"
167 continue
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`
173 omatch=true
174 first=true
175 match=false
176 for tag in $tags; do
177 case $tag in
178 "//")
180 "+build" | "//+build")
181 if test "$first" = "true"; then
182 first=false
183 elif test "$match" = "false"; then
184 omatch=false
186 match=false
188 $goos | $goarch | $cgotag | $cmdlinetag | "gccgo" | "goexperiment.fieldtrack" | go1.[0-9] | go1.[0-9][0-9])
189 match=true
191 "!"$goos | "!"$goarch | "!"$cgotag | "!"$cmdlinetag | "!gccgo" | "!goexperiment.fieldtrack" | "!"go1.[0-9] | "!"go1.1[0-7])
193 *,*)
194 cmatch=true
195 for ctag in `echo $tag | sed -e 's/,/ /g'`; do
196 case $ctag in
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])
200 cmatch=false
202 "!"*)
205 cmatch=false
207 esac
208 done
209 if test "$cmatch" = "true"; then
210 match=true
213 "!"*)
214 match=true
216 esac
217 done
219 if test "$match" = "false" -a "$first" = "false"; then
220 omatch=false
223 if test "$omatch" = "true"; then
224 matched="$matched $srcdir/$f"
226 done
228 echo $matched $extrafiles
230 exit 0