aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/cgo_bad_directives.txt
blob: 358284ffec0dee40d2b23c902ef163203480c418 (plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
[!cgo] skip
[short] skip

mkdir x
cp x.go.txt x/x.go

# Only allow //go:cgo_ldflag .* in cgo-generated code
[gc] cp x_gc.go.txt x/x.go
[gc] ! go build x
[gc] stderr '//go:cgo_ldflag .* only allowed in cgo-generated code'

# Ignore _* files
rm x/x.go
! go build x
stderr 'no Go files'
cp cgo_yy.go.txt x/_cgo_yy.go
! go build x
stderr 'no Go files' #_* files are ignored...

[gc] ! go build x/_cgo_yy.go # ... but if forced, the comment is rejected
# Actually, today there is a separate issue that _ files named
# on the command line are ignored. Once that is fixed,
# we want to see the cgo_ldflag error.
[gc] stderr '//go:cgo_ldflag only allowed in cgo-generated code|no Go files'

rm x/_cgo_yy.go

# Reject #cgo CFLAGS: -fplugin=foo.so
cp x.go.txt x/x.go
cp y_fplugin.go.txt x/y.go
! go build x
stderr 'invalid flag in #cgo CFLAGS: -fplugin=foo.so'

# Reject #cgo CFLAGS: -lbar -fplugin=foo.so
cp y_lbar_fplugin.go.txt x/y.go
! go build x
stderr 'invalid flag in #cgo CFLAGS: -fplugin=foo.so'

# Reject #cgo pkg-config: -foo
cp y_pkgconfig_dash_foo.txt x/y.go
! go build x
stderr 'invalid pkg-config package name: -foo'

# Reject #cgo pkg-config: @foo
cp y_pkgconfig_at_foo.txt x/y.go
! go build x
stderr 'invalid pkg-config package name: @foo'

# Reject #cgo CFLAGS: @foo
cp y_cflags_at_foo.txt x/y.go
! go build x
stderr 'invalid flag in #cgo CFLAGS: @foo'

# Reject #cgo CFLAGS: -D
cp y_cflags_dash_d.txt x/y.go
! go build x
stderr 'invalid flag in #cgo CFLAGS: -D without argument'

# Note that -I @foo is allowed because we rewrite it into -I /path/to/src/@foo
# before the check is applied. There's no such rewrite for -D.

# Reject #cgo CFLAGS: -D @foo
cp y_cflags_dash_d_space_at_foo.txt x/y.go
! go build x
stderr 'invalid flag in #cgo CFLAGS: -D @foo'

# Reject #cgo CFLAGS -D@foo
cp y_cflags_dash_d_at_foo.txt x/y.go
! go build x
stderr 'invalid flag in #cgo CFLAGS: -D@foo'

# Check for CFLAGS in commands
env CGO_CFLAGS=-D@foo
cp y_no_cflags.txt x/y.go
go build -n x
stderr '-D@foo'

-- x_gc.go.txt --
package x

//go:cgo_ldflag "-fplugin=foo.so"

import "C"
-- cgo_yy.go.txt --
package x

//go:cgo_ldflag "-fplugin=foo.so"

import "C"
-- x.go.txt --
package x
-- y_fplugin.go.txt --
package x
// #cgo CFLAGS: -fplugin=foo.so
import "C"
-- y_lbar_fplugin.go.txt --
package x
// #cgo CFLAGS: -Ibar -fplugin=foo.so
import "C"
-- y_pkgconfig_dash_foo.txt --
package x
// #cgo pkg-config: -foo
import "C"
-- y_pkgconfig_at_foo.txt --
package x
// #cgo pkg-config: @foo
import "C"
-- y_cflags_at_foo.txt --
package x
// #cgo CFLAGS: @foo
import "C"
-- y_cflags_dash_d.txt --
package x
// #cgo CFLAGS: -D
import "C"
-- y_cflags_dash_d_space_at_foo.txt --
package x
// #cgo CFLAGS: -D @foo
import "C"
-- y_cflags_dash_d_at_foo.txt --
package x
// #cgo CFLAGS: -D@foo
import "C"
-- y_no_cflags.txt --
package x
import "C"