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

     1  [short] skip
     2  [!exec:gccgo] skip
     3  [cross] skip  # gccgo can't necessarily cross-compile
     4  
     5  # Test building in overlays with gccgo.
     6  # TODO(#39958): add a test that both gc and gccgo assembly files can include .h
     7  #   files.
     8  
     9  # The main package (m) is contained in an overlay. It imports m/dir2 which has one
    10  # file in an overlay and one file outside the overlay, which in turn imports m/dir,
    11  # which only has source files in the overlay.
    12  
    13  env GO111MODULE=off
    14  
    15  cd m
    16  
    17  ! go build -compiler=gccgo .
    18  go build -compiler=gccgo -overlay overlay.json -o main_gccgo$GOEXE .
    19  exec ./main_gccgo$goexe
    20  stdout '^hello$'
    21  
    22  go build -compiler=gccgo -overlay overlay.json -o print_abspath_gccgo$GOEXE ./printpath
    23  exec ./print_abspath_gccgo$GOEXE
    24  stdout $WORK[/\\]gopath[/\\]src[/\\]m[/\\]printpath[/\\]main.go
    25  
    26  go build -compiler=gccgo -overlay overlay.json -o print_trimpath_gccgo$GOEXE -trimpath ./printpath
    27  exec ./print_trimpath_gccgo$GOEXE
    28  stdout ^\.[/\\]printpath[/\\]main.go
    29  
    30  
    31  go build -compiler=gccgo  -overlay overlay.json -o main_cgo_replace_gccgo$GOEXE ./cgo_hello_replace
    32  exec ./main_cgo_replace_gccgo$GOEXE
    33  stdout '^hello cgo\r?\n'
    34  
    35  go build -compiler=gccgo  -overlay overlay.json -o main_cgo_quote_gccgo$GOEXE ./cgo_hello_quote
    36  exec ./main_cgo_quote_gccgo$GOEXE
    37  stdout '^hello cgo\r?\n'
    38  
    39  go build -compiler=gccgo  -overlay overlay.json -o main_cgo_angle_gccgo$GOEXE ./cgo_hello_angle
    40  exec ./main_cgo_angle_gccgo$GOEXE
    41  stdout '^hello cgo\r?\n'
    42  
    43  go build -compiler=gccgo -overlay overlay.json -o main_call_asm_gccgo$GOEXE ./call_asm
    44  exec ./main_call_asm_gccgo$GOEXE
    45  ! stdout .
    46  
    47  -- m/go.mod --
    48  // TODO(matloob): how do overlays work with go.mod (especially if mod=readonly)
    49  module m
    50  
    51  go 1.16
    52  
    53  -- m/dir2/h.go --
    54  package dir2
    55  
    56  func PrintMessage() {
    57  	printMessage()
    58  }
    59  -- m/dir/foo.txt --
    60  The build action code currently expects the package directory
    61  to exist, so it can run the compiler in that directory.
    62  TODO(matloob): Remove this requirement.
    63  -- m/printpath/about.txt --
    64  the actual code is in the overlay
    65  -- m/overlay.json --
    66  {
    67  	"Replace": {
    68  		"f.go": "overlay/f.go",
    69  		"dir/g.go": "overlay/dir_g.go",
    70  		"dir2/i.go": "overlay/dir2_i.go",
    71  		"printpath/main.go": "overlay/printpath.go",
    72  		"printpath/other.go": "overlay2/printpath2.go",
    73  		"call_asm/asm_gc.s": "overlay/asm_gc.s",
    74  		"call_asm/asm_gccgo.s": "overlay/asm_gccgo.s",
    75  		"test_cache/main.go": "overlay/test_cache.go",
    76  		"cgo_hello_replace/cgo_header.h": "overlay/cgo_head.h",
    77  		"cgo_hello_replace/hello.c": "overlay/hello.c",
    78  		"cgo_hello_quote/cgo_hello.go": "overlay/cgo_hello_quote.go",
    79  		"cgo_hello_quote/cgo_header.h": "overlay/cgo_head.h",
    80  		"cgo_hello_angle/cgo_hello.go": "overlay/cgo_hello_angle.go",
    81  		"cgo_hello_angle/cgo_header.h": "overlay/cgo_head.h"
    82  	}
    83  }
    84  -- m/cgo_hello_replace/cgo_hello_replace.go --
    85  package main
    86  
    87  // #include "cgo_header.h"
    88  import "C"
    89  
    90  func main() {
    91  	C.say_hello()
    92  }
    93  -- m/cgo_hello_replace/cgo_header.h --
    94   // Test that this header is replaced with one that has the proper declaration.
    95  void say_goodbye();
    96  
    97  -- m/cgo_hello_replace/hello.c --
    98  #include <stdio.h>
    99  
   100  void say_goodbye() { puts("goodbye cgo\n"); fflush(stdout); }
   101  
   102  -- m/overlay/f.go --
   103  package main
   104  
   105  import "m/dir2"
   106  
   107  func main() {
   108  	dir2.PrintMessage()
   109  }
   110  -- m/call_asm/main.go --
   111  package main
   112  
   113  func foo() // There will be a "missing function body" error if the assembly file isn't found.
   114  
   115  func main() {
   116  	foo()
   117  }
   118  -- m/overlay/dir_g.go --
   119  package dir
   120  
   121  import "fmt"
   122  
   123  func PrintMessage() {
   124  	fmt.Println("hello")
   125  }
   126  -- m/overlay/printpath.go --
   127  package main
   128  
   129  import (
   130  	"fmt"
   131  	"path/filepath"
   132  	"runtime"
   133  )
   134  
   135  func main() {
   136  	_, file, _, _ := runtime.Caller(0)
   137  
   138  	// Since https://golang.org/cl/214286, the runtime's debug paths are
   139  	// slash-separated regardless of platform, so normalize them to system file
   140  	// paths.
   141  	fmt.Println(filepath.FromSlash(file))
   142  }
   143  -- m/overlay2/printpath2.go --
   144  package main
   145  
   146  import (
   147  	"fmt"
   148  	"path/filepath"
   149  	"runtime"
   150  )
   151  
   152  func init() {
   153  	_, file, _, _ := runtime.Caller(0)
   154  	fmt.Println(filepath.FromSlash(file))
   155  }
   156  -- m/overlay/dir2_i.go --
   157  package dir2
   158  
   159  import "m/dir"
   160  
   161  func printMessage() {
   162  	dir.PrintMessage()
   163  }
   164  -- m/overlay/cgo_hello_quote.go --
   165  package main
   166  
   167  // #include "cgo_header.h"
   168  import "C"
   169  
   170  func main() {
   171  	C.say_hello()
   172  }
   173  -- m/overlay/cgo_hello_angle.go --
   174  package main
   175  
   176  // #include <cgo_header.h>
   177  import "C"
   178  
   179  func main() {
   180  	C.say_hello()
   181  }
   182  -- m/overlay/cgo_head.h --
   183  void say_hello();
   184  -- m/overlay/hello.c --
   185  #include <stdio.h>
   186  
   187  void say_hello() { puts("hello cgo\n"); fflush(stdout); }
   188  -- m/overlay/asm_gc.s --
   189  // +build gc
   190  
   191  TEXT ·foo(SB),0,$0
   192  	RET
   193  
   194  -- m/overlay/asm_gccgo.s --
   195  // +build gccgo
   196  
   197  .globl main.foo
   198  .text
   199  main.foo:
   200  	ret
   201  
   202  -- m/cgo_hello_quote/hello.c --
   203  #include <stdio.h>
   204  
   205  void say_hello() { puts("hello cgo\n"); fflush(stdout); }
   206  -- m/cgo_hello_angle/hello.c --
   207  #include <stdio.h>
   208  
   209  void say_hello() { puts("hello cgo\n"); fflush(stdout); }
   210  

View as plain text