...

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 CFLAGS: @foo
    49cp y_cflags_at_foo.txt y.go
    50! go build x
    51stderr 'invalid flag in #cgo CFLAGS: @foo'
    52
    53# Reject #cgo CFLAGS: -D
    54cp y_cflags_dash_d.txt y.go
    55! go build x
    56stderr 'invalid flag in #cgo CFLAGS: -D without argument'
    57
    58# Note that -I @foo is allowed because we rewrite it into -I /path/to/src/@foo
    59# before the check is applied. There's no such rewrite for -D.
    60
    61# Reject #cgo CFLAGS: -D @foo
    62cp y_cflags_dash_d_space_at_foo.txt y.go
    63! go build x
    64stderr 'invalid flag in #cgo CFLAGS: -D @foo'
    65
    66# Reject #cgo CFLAGS -D@foo
    67cp y_cflags_dash_d_at_foo.txt y.go
    68! go build x
    69stderr 'invalid flag in #cgo CFLAGS: -D@foo'
    70
    71# Check for CFLAGS in commands
    72env CGO_CFLAGS=-D@foo
    73cp y_no_cflags.txt y.go
    74go build -n x
    75stderr '-D@foo'
    76
    77-- go.mod --
    78module x
    79
    80go 1.16
    81-- x_gc.go.txt --
    82package x
    83
    84//go:cgo_ldflag "-fplugin=foo.so"
    85
    86import "C"
    87-- cgo_yy.go.txt --
    88package x
    89
    90//go:cgo_ldflag "-fplugin=foo.so"
    91
    92import "C"
    93-- x.go.txt --
    94package x
    95-- y_fplugin.go.txt --
    96package x
    97// #cgo CFLAGS: -fplugin=foo.so
    98import "C"
    99-- y_lbar_fplugin.go.txt --
   100package x
   101// #cgo CFLAGS: -Ibar -fplugin=foo.so
   102import "C"
   103-- y_pkgconfig_dash_foo.txt --
   104package x
   105// #cgo pkg-config: -foo
   106import "C"
   107-- y_pkgconfig_at_foo.txt --
   108package x
   109// #cgo pkg-config: @foo
   110import "C"
   111-- y_cflags_at_foo.txt --
   112package x
   113// #cgo CFLAGS: @foo
   114import "C"
   115-- y_cflags_dash_d.txt --
   116package x
   117// #cgo CFLAGS: -D
   118import "C"
   119-- y_cflags_dash_d_space_at_foo.txt --
   120package x
   121// #cgo CFLAGS: -D @foo
   122import "C"
   123-- y_cflags_dash_d_at_foo.txt --
   124package x
   125// #cgo CFLAGS: -D@foo
   126import "C"
   127-- y_no_cflags.txt --
   128package x
   129import "C"

View as plain text