...

Text file src/cmd/go/testdata/script/cgo_bad_directives.txt

Documentation: cmd/go/testdata/script

     1[!cgo] skip
     2[short] skip
     3
     4cp x.go.txt x.go
     5
     6# Only allow //go:cgo_ldflag .* in cgo-generated code
     7[compiler:gc] cp x_gc.go.txt x.go
     8[compiler:gc] ! go build x
     9[compiler:gc] stderr '//go:cgo_ldflag .* only allowed in cgo-generated code'
    10
    11# Ignore _* files
    12rm x.go
    13! go build .
    14stderr 'no Go files'
    15cp cgo_yy.go.txt _cgo_yy.go
    16! go build .
    17stderr 'no Go files' #_* files are ignored...
    18
    19[compiler:gc] ! go build _cgo_yy.go # ... but if forced, the comment is rejected
    20# Actually, today there is a separate issue that _ files named
    21# on the command line are ignored. Once that is fixed,
    22# we want to see the cgo_ldflag error.
    23[compiler:gc] stderr '//go:cgo_ldflag only allowed in cgo-generated code|no Go files'
    24
    25rm _cgo_yy.go
    26
    27# Reject #cgo CFLAGS: -fplugin=foo.so
    28cp x.go.txt x.go
    29cp y_fplugin.go.txt y.go
    30! go build x
    31stderr 'invalid flag in #cgo CFLAGS: -fplugin=foo.so'
    32
    33# Reject #cgo CFLAGS: -lbar -fplugin=foo.so
    34cp y_lbar_fplugin.go.txt y.go
    35! go build x
    36stderr 'invalid flag in #cgo CFLAGS: -fplugin=foo.so'
    37
    38# Reject #cgo pkg-config: -foo
    39cp y_pkgconfig_dash_foo.txt y.go
    40! go build x
    41stderr 'invalid pkg-config package name: -foo'
    42
    43# Reject #cgo pkg-config: @foo
    44cp y_pkgconfig_at_foo.txt y.go
    45! go build x
    46stderr 'invalid pkg-config package name: @foo'
    47
    48# Reject #cgo pkg-config: --log-file=/tmp/log
    49cp y_pkgconfig_log_file.txt y.go
    50! go build x
    51stderr 'invalid flag in pkg-config: --log-file=/tmp/log'
    52
    53# Reject #cgo CFLAGS: @foo
    54cp y_cflags_at_foo.txt y.go
    55! go build x
    56stderr 'invalid flag in #cgo CFLAGS: @foo'
    57
    58# Reject #cgo CFLAGS: -D
    59cp y_cflags_dash_d.txt y.go
    60! go build x
    61stderr 'invalid flag in #cgo CFLAGS: -D without argument'
    62
    63# Note that -I @foo is allowed because we rewrite it into -I /path/to/src/@foo
    64# before the check is applied. There's no such rewrite for -D.
    65
    66# Reject #cgo CFLAGS: -D @foo
    67cp y_cflags_dash_d_space_at_foo.txt y.go
    68! go build x
    69stderr 'invalid flag in #cgo CFLAGS: -D @foo'
    70
    71# Reject #cgo CFLAGS -D@foo
    72cp y_cflags_dash_d_at_foo.txt y.go
    73! go build x
    74stderr 'invalid flag in #cgo CFLAGS: -D@foo'
    75
    76# Check for CFLAGS in commands
    77env CGO_CFLAGS=-D@foo
    78cp y_no_cflags.txt y.go
    79go build -n x
    80stderr '-D@foo'
    81
    82-- go.mod --
    83module x
    84
    85go 1.16
    86-- x_gc.go.txt --
    87package x
    88
    89//go:cgo_ldflag "-fplugin=foo.so"
    90
    91import "C"
    92-- cgo_yy.go.txt --
    93package x
    94
    95//go:cgo_ldflag "-fplugin=foo.so"
    96
    97import "C"
    98-- x.go.txt --
    99package x
   100-- y_fplugin.go.txt --
   101package x
   102// #cgo CFLAGS: -fplugin=foo.so
   103import "C"
   104-- y_lbar_fplugin.go.txt --
   105package x
   106// #cgo CFLAGS: -Ibar -fplugin=foo.so
   107import "C"
   108-- y_pkgconfig_dash_foo.txt --
   109package x
   110// #cgo pkg-config: -foo
   111import "C"
   112-- y_pkgconfig_at_foo.txt --
   113package x
   114// #cgo pkg-config: @foo
   115import "C"
   116-- y_pkgconfig_log_file.txt --
   117package x
   118// #cgo pkg-config: --log-file=/tmp/log
   119import "C"
   120-- y_cflags_at_foo.txt --
   121package x
   122// #cgo CFLAGS: @foo
   123import "C"
   124-- y_cflags_dash_d.txt --
   125package x
   126// #cgo CFLAGS: -D
   127import "C"
   128-- y_cflags_dash_d_space_at_foo.txt --
   129package x
   130// #cgo CFLAGS: -D @foo
   131import "C"
   132-- y_cflags_dash_d_at_foo.txt --
   133package x
   134// #cgo CFLAGS: -D@foo
   135import "C"
   136-- y_no_cflags.txt --
   137package x
   138import "C"

View as plain text