]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgo/match.sh
print-rtl: Change return type of two print functions from int to void
[thirdparty/gcc.git] / libgo / match.sh
CommitLineData
e0f69f36
ILT
1#!/bin/sh
2
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.
6
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.
10
11set -e
12
82b709f9 13LANG=C
e0f69f36
ILT
14LC_ALL=C
15LC_CTYPE=C
82b709f9 16export LANG LC_ALL LC_CTYPE
e0f69f36
ILT
17
18srcdir=""
19goarch=""
20goos=""
21extrafiles=""
22cmdlinetag="nosuchtag"
23cgotag="cgo"
24
25for arg; do
26 case "x$arg" in
27 x--srcdir)
28 srcdir=$2
29 shift
30 shift
31 ;;
32 x--srcdir=*)
33 srcdir=`echo $1 | sed -e 's/^--srcdir=//'`
34 shift
35 ;;
36 x--goarch)
37 goarch=$2
38 shift
39 shift
40 ;;
41 x--goarch=*)
42 goarch=`echo $1 | sed -e 's/^--goarch=//'`
43 shift
44 ;;
45 x--goos)
46 goos=$2
47 shift
48 shift
49 ;;
50 x--goos=*)
51 goos=`echo $1 | sed -e 's/^--goos=//'`
52 shift
53 ;;
54 x--extrafiles)
55 extrafiles=$2
56 shift
57 shift
58 ;;
59 x--extrafiles=*)
60 extrafiles=`echo $1 | sed -e 's/^--extrafiles=//'`
61 shift
62 ;;
63 x--tag)
64 cmdlinetag=$2
65 shift
66 shift
67 ;;
68 x--tag=*)
69 cmdlinetag=`echo $1 | sed -e 's/^--tag=//'`
70 shift
71 ;;
72 x--nocgo)
73 cgotag="nosuchtag"
74 shift
75 ;;
76 *)
77 echo 1>&2 "unknown argument $arg"
78 exit 1
79 ;;
80 esac
81done
82
83cd $srcdir
84
85gofiles=
86for f in *.go; do
87 case $f in
88 *_test.go)
89 ;;
90 *.go)
91 gofiles="$gofiles $f"
92 ;;
93 esac
94done
95
96if test "$gofiles" = ""; then
97 echo 1>&2 "no non-test .go files in $srcdir"
98 exit 1
99fi
100
8dc2499a
ILT
101gobuild() {
102 line=$(echo "$1" | sed -e 's|//go:build ||')
4a1a72a8 103 line=$(echo "$line" | sed -e 's/go1\.[0-9][0-9]*/1/g' -e 's/goexperiment\./goexperiment/')
8dc2499a
ILT
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")
113 fi
cf172561 114 return $((!($line)))
8dc2499a
ILT
115}
116
e0f69f36
ILT
117matched=
118for 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=
123 fi
124 if test x$tag2 = x$f; then
125 tag2=
126 fi
127
128 case "$tag1" in
129 "") ;;
130 $goarch) ;;
131 $goos) ;;
cfcbb422 132 aix | android | darwin | dragonfly | freebsd | illumos | hurd | ios | js | linux | nacl | netbsd | openbsd | plan9 | solaris | windows | zos)
e0f69f36
ILT
133 tag1=nonmatchingtag
134 ;;
2c5499b5 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)
e0f69f36
ILT
136 tag1=nonmatchingtag
137 ;;
c5b21c3f
ILT
138 *)
139 # File name like x_amd64_random.go, where tag1=random.
140 # Don't match based on tag2.
141 tag2=
142 ;;
e0f69f36
ILT
143 esac
144
145 case "$tag2" in
146 "") ;;
147 $goarch) ;;
148 $goos) ;;
cfcbb422 149 aix | android | darwin | dragonfly | freebsd | hurd | ios | illumos | js | linux | nacl | netbsd | openbsd | plan9 | solaris | windows | zos)
e0f69f36
ILT
150 tag2=nonmatchingtag
151 ;;
2c5499b5 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)
e0f69f36
ILT
153 tag2=nonmatchingtag
154 ;;
155 esac
156
8dc2499a
ILT
157 if test x$tag1 = xnonmatchingtag -o x$tag2 = xnonmatchingtag; then
158 continue
159 fi
e0f69f36 160
8dc2499a
ILT
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
e0f69f36
ILT
165 matched="$matched $srcdir/$f"
166 fi
8dc2499a
ILT
167 continue
168 fi
169
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 "//")
179 ;;
180 "+build" | "//+build")
181 if test "$first" = "true"; then
182 first=false
183 elif test "$match" = "false"; then
184 omatch=false
185 fi
186 match=false
187 ;;
188 $goos | $goarch | $cgotag | $cmdlinetag | "gccgo" | "goexperiment.fieldtrack" | go1.[0-9] | go1.[0-9][0-9])
189 match=true
190 ;;
191 "!"$goos | "!"$goarch | "!"$cgotag | "!"$cmdlinetag | "!gccgo" | "!goexperiment.fieldtrack" | "!"go1.[0-9] | "!"go1.1[0-7])
192 ;;
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])
198 ;;
199 "!"$goos | "!"$goarch | "!"$cgotag | "!"$cmdlinetag | "!gccgo" | "!goexperiment.fieldtrack" | "!"go1.[0-9] | "!"go1.1[0-7])
200 cmatch=false
201 ;;
202 "!"*)
203 ;;
204 *)
205 cmatch=false
206 ;;
207 esac
208 done
209 if test "$cmatch" = "true"; then
210 match=true
211 fi
212 ;;
213 "!"*)
214 match=true
215 ;;
216 esac
217 done
218
219 if test "$match" = "false" -a "$first" = "false"; then
220 omatch=false
221 fi
222
223 if test "$omatch" = "true"; then
224 matched="$matched $srcdir/$f"
e0f69f36
ILT
225 fi
226done
227
228echo $matched $extrafiles
229
230exit 0