...

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

Documentation: cmd/go/testdata/script

     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
    13env GO111MODULE=off
    14
    15cd m
    16
    17! go build -compiler=gccgo .
    18go build -compiler=gccgo -overlay overlay.json -o main_gccgo$GOEXE .
    19exec ./main_gccgo$goexe
    20stdout '^hello$'
    21
    22go build -compiler=gccgo -overlay overlay.json -o print_abspath_gccgo$GOEXE ./printpath
    23exec ./print_abspath_gccgo$GOEXE
    24stdout $WORK[/\\]gopath[/\\]src[/\\]m[/\\]printpath[/\\]main.go
    25
    26go build -compiler=gccgo -overlay overlay.json -o print_trimpath_gccgo$GOEXE -trimpath ./printpath
    27exec ./print_trimpath_gccgo$GOEXE
    28stdout ^\.[/\\]printpath[/\\]main.go
    29
    30
    31go build -compiler=gccgo  -overlay overlay.json -o main_cgo_replace_gccgo$GOEXE ./cgo_hello_replace
    32exec ./main_cgo_replace_gccgo$GOEXE
    33stdout '^hello cgo\r?\n'
    34
    35go build -compiler=gccgo  -overlay overlay.json -o main_cgo_quote_gccgo$GOEXE ./cgo_hello_quote
    36exec ./main_cgo_quote_gccgo$GOEXE
    37stdout '^hello cgo\r?\n'
    38
    39go build -compiler=gccgo  -overlay overlay.json -o main_cgo_angle_gccgo$GOEXE ./cgo_hello_angle
    40exec ./main_cgo_angle_gccgo$GOEXE
    41stdout '^hello cgo\r?\n'
    42
    43go build -compiler=gccgo -overlay overlay.json -o main_call_asm_gccgo$GOEXE ./call_asm
    44exec ./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)
    49module m
    50
    51go 1.16
    52
    53-- m/dir2/h.go --
    54package dir2
    55
    56func PrintMessage() {
    57	printMessage()
    58}
    59-- m/dir/foo.txt --
    60The build action code currently expects the package directory
    61to exist, so it can run the compiler in that directory.
    62TODO(matloob): Remove this requirement.
    63-- m/printpath/about.txt --
    64the 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 --
    85package main
    86
    87// #include "cgo_header.h"
    88import "C"
    89
    90func 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.
    95void say_goodbye();
    96
    97-- m/cgo_hello_replace/hello.c --
    98#include <stdio.h>
    99
   100void say_goodbye() { puts("goodbye cgo\n"); fflush(stdout); }
   101
   102-- m/overlay/f.go --
   103package main
   104
   105import "m/dir2"
   106
   107func main() {
   108	dir2.PrintMessage()
   109}
   110-- m/call_asm/main.go --
   111package main
   112
   113func foo() // There will be a "missing function body" error if the assembly file isn't found.
   114
   115func main() {
   116	foo()
   117}
   118-- m/overlay/dir_g.go --
   119package dir
   120
   121import "fmt"
   122
   123func PrintMessage() {
   124	fmt.Println("hello")
   125}
   126-- m/overlay/printpath.go --
   127package main
   128
   129import (
   130	"fmt"
   131	"path/filepath"
   132	"runtime"
   133)
   134
   135func 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 --
   144package main
   145
   146import (
   147	"fmt"
   148	"path/filepath"
   149	"runtime"
   150)
   151
   152func init() {
   153	_, file, _, _ := runtime.Caller(0)
   154	fmt.Println(filepath.FromSlash(file))
   155}
   156-- m/overlay/dir2_i.go --
   157package dir2
   158
   159import "m/dir"
   160
   161func printMessage() {
   162	dir.PrintMessage()
   163}
   164-- m/overlay/cgo_hello_quote.go --
   165package main
   166
   167// #include "cgo_header.h"
   168import "C"
   169
   170func main() {
   171	C.say_hello()
   172}
   173-- m/overlay/cgo_hello_angle.go --
   174package main
   175
   176// #include <cgo_header.h>
   177import "C"
   178
   179func main() {
   180	C.say_hello()
   181}
   182-- m/overlay/cgo_head.h --
   183void say_hello();
   184-- m/overlay/hello.c --
   185#include <stdio.h>
   186
   187void say_hello() { puts("hello cgo\n"); fflush(stdout); }
   188-- m/overlay/asm_gc.s --
   189// +build gc
   190
   191TEXT ·foo(SB),0,$0
   192	RET
   193
   194-- m/overlay/asm_gccgo.s --
   195// +build gccgo
   196
   197.globl main.foo
   198.text
   199main.foo:
   200	ret
   201
   202-- m/cgo_hello_quote/hello.c --
   203#include <stdio.h>
   204
   205void say_hello() { puts("hello cgo\n"); fflush(stdout); }
   206-- m/cgo_hello_angle/hello.c --
   207#include <stdio.h>
   208
   209void say_hello() { puts("hello cgo\n"); fflush(stdout); }

View as plain text