...
1[short] skip
2
3# Test building in overlays.
4# TODO(#39958): add a test case where the destination file in the replace map
5# isn't a go file. Either completely exclude that case in fs.IsDirWithGoFiles
6# if the compiler doesn't allow it, or test that it works all the way.
7# TODO(#39958): add a test that both gc and gccgo assembly files can include .h
8# files.
9
10# The main package (m) is contained in an overlay. It imports m/dir2 which has one
11# file in an overlay and one file outside the overlay, which in turn imports m/dir,
12# which only has source files in the overlay.
13
14cd m
15
16! go build .
17go build -overlay overlay.json -o main$GOEXE .
18exec ./main$goexe
19stdout '^hello$'
20
21go build -overlay overlay.json -o print_abspath$GOEXE ./printpath
22exec ./print_abspath$GOEXE
23stdout $WORK[/\\]gopath[/\\]src[/\\]m[/\\]printpath[/\\]main.go
24
25go vet -overlay overlay.json ./printpath
26
27go build -overlay overlay.json -o print_trimpath$GOEXE -trimpath ./printpath
28exec ./print_trimpath$GOEXE
29stdout ^m[/\\]printpath[/\\]main.go
30
31go build -overlay overlay.json -o print_trimpath_two_files$GOEXE printpath/main.go printpath/other.go
32exec ./print_trimpath_two_files$GOEXE
33stdout $WORK[/\\]gopath[/\\]src[/\\]m[/\\]printpath[/\\]main.go
34stdout $WORK[/\\]gopath[/\\]src[/\\]m[/\\]printpath[/\\]other.go
35
36go build -overlay overlay.json -o main_call_asm$GOEXE ./call_asm
37exec ./main_call_asm$GOEXE
38! stdout .
39
40# Change the contents of a file in the overlay and ensure that makes the target stale
41env OLD_GOCACHE=$GOCACHE
42env GOCACHE=$WORK/cache # use a fresh cache so that multiple runs of the test don't interfere
43go build -x -overlay overlay.json ./test_cache
44stderr '(compile|gccgo)( |\.exe).*test_cache.go'
45go build -x -overlay overlay.json ./test_cache
46! stderr '(compile|gccgo)( |\.exe).*test_cache.go' # cached
47cp overlay/test_cache_different.go overlay/test_cache.go
48go build -x -overlay overlay.json ./test_cache
49stderr '(compile|gccgo)( |\.exe).*test_cache.go' # not cached
50env CACHE=$OLD_GOCACHE
51
52-- m/go.mod --
53// TODO(matloob): how do overlays work with go.mod (especially if mod=readonly)
54module m
55
56go 1.16
57
58-- m/dir2/h.go --
59package dir2
60
61func PrintMessage() {
62 printMessage()
63}
64-- m/dir/foo.txt --
65The build action code currently expects the package directory
66to exist, so it can run the compiler in that directory.
67TODO(matloob): Remove this requirement.
68-- m/printpath/about.txt --
69the actual code is in the overlay
70-- m/overlay.json --
71{
72 "Replace": {
73 "f.go": "overlay/f.go",
74 "dir/g.go": "overlay/dir_g.go",
75 "dir2/i.go": "overlay/dir2_i.go",
76 "printpath/main.go": "overlay/printpath.go",
77 "printpath/other.go": "overlay2/printpath2.go",
78 "call_asm/asm_gc.s": "overlay/asm_gc.s",
79 "call_asm/asm_gccgo.s": "overlay/asm_gccgo.s",
80 "test_cache/main.go": "overlay/test_cache.go"
81 }
82}
83-- m/overlay/f.go --
84package main
85
86import "m/dir2"
87
88func main() {
89 dir2.PrintMessage()
90}
91-- m/call_asm/main.go --
92package main
93
94func foo() // There will be a "missing function body" error if the assembly file isn't found.
95
96func main() {
97 foo()
98}
99-- m/overlay/dir_g.go --
100package dir
101
102import "fmt"
103
104func PrintMessage() {
105 fmt.Println("hello")
106}
107-- m/overlay/printpath.go --
108package main
109
110import (
111 "fmt"
112 "path/filepath"
113 "runtime"
114)
115
116func main() {
117 _, file, _, _ := runtime.Caller(0)
118
119 // Since https://golang.org/cl/214286, the runtime's debug paths are
120 // slash-separated regardless of platform, so normalize them to system file
121 // paths.
122 fmt.Println(filepath.FromSlash(file))
123}
124-- m/overlay2/printpath2.go --
125package main
126
127import (
128 "fmt"
129 "path/filepath"
130 "runtime"
131)
132
133func init() {
134 _, file, _, _ := runtime.Caller(0)
135 fmt.Println(filepath.FromSlash(file))
136}
137-- m/overlay/dir2_i.go --
138package dir2
139
140import "m/dir"
141
142func printMessage() {
143 dir.PrintMessage()
144}
145-- m/overlay/asm_gc.s --
146// +build gc
147
148TEXT ·foo(SB),0,$0
149 RET
150
151-- m/overlay/asm_gccgo.s --
152// +build gccgo
153
154.globl main.foo
155.text
156main.foo:
157 ret
158
159-- m/overlay/test_cache.go --
160package foo
161
162import "fmt"
163
164func bar() {
165 fmt.Println("something")
166}
167-- m/overlay/test_cache_different.go --
168package foo
169
170import "fmt"
171
172func bar() {
173 fmt.Println("different")
174}
View as plain text