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

     1  # This is a test that -trimpath trims the paths of every directory
     2  # of Cgo dependencies in the module, and trims file paths included
     3  # through the __FILE__ macro using --file-prefix-map.
     4  
     5  [!cgo] skip
     6  [short] skip 'links and runs binaries'
     7  
     8  # Test in main module.
     9  go run -trimpath -mod=vendor ./main
    10  stdout '(\\_\\_|/_)[\\/]m[\\/]c[\\/]bar.h'
    11  
    12  # Test in vendored module.
    13  go run -trimpath -mod=vendor v.com/main
    14  stdout '(\\_\\_|/_)[\\/]vendor[\\/]v.com[\\/]c[\\/]bar.h'
    15  
    16  # Test in GOPATH mode.
    17  env GO111MODULE=off
    18  go run -trimpath ./main
    19  stdout '(\\_\\_|/_)[\\/]GOPATH[\\/]src[\\/]c[\\/]bar.h'
    20  
    21  -- go.mod --
    22  module m
    23  
    24  require v.com v1.0.0
    25  -- go.sum --
    26  v.com v1.0.0 h1:xxx
    27  v.com v1.0.0/go.mod h1:xxx
    28  -- vendor/modules.txt --
    29  # v.com v1.0.0
    30  ## explicit; go 1.20
    31  v.com/main
    32  -- vendor/v.com/main/main.go --
    33  package main
    34  
    35  // #cgo CFLAGS: -I../c
    36  // #include "stdio.h"
    37  // void printfile();
    38  import "C"
    39  
    40  func main() {
    41      C.printfile()
    42      C.fflush(C.stdout)
    43  }
    44  -- vendor/v.com/main/foo.c --
    45  #include "bar.h"
    46  -- vendor/v.com/c/bar.h --
    47  #include "stdio.h"
    48  
    49  void printfile() {
    50      printf("%s\n", __FILE__);
    51  }
    52  -- main/main.go --
    53  package main
    54  
    55  // #cgo CFLAGS: -I../c
    56  // #include "stdio.h"
    57  // void printfile();
    58  import "C"
    59  
    60  func main() {
    61      C.printfile()
    62      C.fflush(C.stdout)
    63  }
    64  -- main/foo.c --
    65  #include "bar.h"
    66  -- c/bar.h --
    67  #include "stdio.h"
    68  
    69  void printfile() {
    70      printf("%s\n", __FILE__);
    71  }

View as plain text