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

     1  [!cgo] skip
     2  [short] skip
     3  
     4  cp 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
    12  rm x.go
    13  ! go build .
    14  stderr 'no Go files'
    15  cp cgo_yy.go.txt _cgo_yy.go
    16  ! go build .
    17  stderr '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  
    25  rm _cgo_yy.go
    26  
    27  # Reject #cgo CFLAGS: -fplugin=foo.so
    28  cp x.go.txt x.go
    29  cp y_fplugin.go.txt y.go
    30  ! go build x
    31  stderr 'invalid flag in #cgo CFLAGS: -fplugin=foo.so'
    32  
    33  # Reject #cgo CFLAGS: -lbar -fplugin=foo.so
    34  cp y_lbar_fplugin.go.txt y.go
    35  ! go build x
    36  stderr 'invalid flag in #cgo CFLAGS: -fplugin=foo.so'
    37  
    38  # Reject #cgo pkg-config: -foo
    39  cp y_pkgconfig_dash_foo.txt y.go
    40  ! go build x
    41  stderr 'invalid pkg-config package name: -foo'
    42  
    43  # Reject #cgo pkg-config: @foo
    44  cp y_pkgconfig_at_foo.txt y.go
    45  ! go build x
    46  stderr 'invalid pkg-config package name: @foo'
    47  
    48  # Reject #cgo CFLAGS: @foo
    49  cp y_cflags_at_foo.txt y.go
    50  ! go build x
    51  stderr 'invalid flag in #cgo CFLAGS: @foo'
    52  
    53  # Reject #cgo CFLAGS: -D
    54  cp y_cflags_dash_d.txt y.go
    55  ! go build x
    56  stderr '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
    62  cp y_cflags_dash_d_space_at_foo.txt y.go
    63  ! go build x
    64  stderr 'invalid flag in #cgo CFLAGS: -D @foo'
    65  
    66  # Reject #cgo CFLAGS -D@foo
    67  cp y_cflags_dash_d_at_foo.txt y.go
    68  ! go build x
    69  stderr 'invalid flag in #cgo CFLAGS: -D@foo'
    70  
    71  # Check for CFLAGS in commands
    72  env CGO_CFLAGS=-D@foo
    73  cp y_no_cflags.txt y.go
    74  go build -n x
    75  stderr '-D@foo'
    76  
    77  -- go.mod --
    78  module x
    79  
    80  go 1.16
    81  -- x_gc.go.txt --
    82  package x
    83  
    84  //go:cgo_ldflag "-fplugin=foo.so"
    85  
    86  import "C"
    87  -- cgo_yy.go.txt --
    88  package x
    89  
    90  //go:cgo_ldflag "-fplugin=foo.so"
    91  
    92  import "C"
    93  -- x.go.txt --
    94  package x
    95  -- y_fplugin.go.txt --
    96  package x
    97  // #cgo CFLAGS: -fplugin=foo.so
    98  import "C"
    99  -- y_lbar_fplugin.go.txt --
   100  package x
   101  // #cgo CFLAGS: -Ibar -fplugin=foo.so
   102  import "C"
   103  -- y_pkgconfig_dash_foo.txt --
   104  package x
   105  // #cgo pkg-config: -foo
   106  import "C"
   107  -- y_pkgconfig_at_foo.txt --
   108  package x
   109  // #cgo pkg-config: @foo
   110  import "C"
   111  -- y_cflags_at_foo.txt --
   112  package x
   113  // #cgo CFLAGS: @foo
   114  import "C"
   115  -- y_cflags_dash_d.txt --
   116  package x
   117  // #cgo CFLAGS: -D
   118  import "C"
   119  -- y_cflags_dash_d_space_at_foo.txt --
   120  package x
   121  // #cgo CFLAGS: -D @foo
   122  import "C"
   123  -- y_cflags_dash_d_at_foo.txt --
   124  package x
   125  // #cgo CFLAGS: -D@foo
   126  import "C"
   127  -- y_no_cflags.txt --
   128  package x
   129  import "C"
   130  

View as plain text