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
14 cd m
15
16 ! go build .
17 go build -overlay overlay.json -o main$GOEXE .
18 exec ./main$goexe
19 stdout '^hello$'
20
21 go build -overlay overlay.json -o print_abspath$GOEXE ./printpath
22 exec ./print_abspath$GOEXE
23 stdout $WORK[/\\]gopath[/\\]src[/\\]m[/\\]printpath[/\\]main.go
24
25 go vet -overlay overlay.json ./printpath
26
27 go build -overlay overlay.json -o print_trimpath$GOEXE -trimpath ./printpath
28 exec ./print_trimpath$GOEXE
29 stdout ^m[/\\]printpath[/\\]main.go
30
31 go build -overlay overlay.json -o print_trimpath_two_files$GOEXE printpath/main.go printpath/other.go
32 exec ./print_trimpath_two_files$GOEXE
33 stdout $WORK[/\\]gopath[/\\]src[/\\]m[/\\]printpath[/\\]main.go
34 stdout $WORK[/\\]gopath[/\\]src[/\\]m[/\\]printpath[/\\]other.go
35
36 go build -overlay overlay.json -o main_call_asm$GOEXE ./call_asm
37 exec ./main_call_asm$GOEXE
38 ! stdout .
39
40 # Change the contents of a file in the overlay and ensure that makes the target stale
41 env OLD_GOCACHE=$GOCACHE
42 env GOCACHE=$WORK/cache # use a fresh cache so that multiple runs of the test don't interfere
43 go build -x -overlay overlay.json ./test_cache
44 stderr '(compile|gccgo)( |\.exe).*test_cache.go'
45 go build -x -overlay overlay.json ./test_cache
46 ! stderr '(compile|gccgo)( |\.exe).*test_cache.go' # cached
47 cp overlay/test_cache_different.go overlay/test_cache.go
48 go build -x -overlay overlay.json ./test_cache
49 stderr '(compile|gccgo)( |\.exe).*test_cache.go' # not cached
50 env CACHE=$OLD_GOCACHE
51
52 -- m/go.mod --
53 // TODO(matloob): how do overlays work with go.mod (especially if mod=readonly)
54 module m
55
56 go 1.16
57
58 -- m/dir2/h.go --
59 package dir2
60
61 func PrintMessage() {
62 printMessage()
63 }
64 -- m/dir/foo.txt --
65 The build action code currently expects the package directory
66 to exist, so it can run the compiler in that directory.
67 TODO(matloob): Remove this requirement.
68 -- m/printpath/about.txt --
69 the 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 --
84 package main
85
86 import "m/dir2"
87
88 func main() {
89 dir2.PrintMessage()
90 }
91 -- m/call_asm/main.go --
92 package main
93
94 func foo() // There will be a "missing function body" error if the assembly file isn't found.
95
96 func main() {
97 foo()
98 }
99 -- m/overlay/dir_g.go --
100 package dir
101
102 import "fmt"
103
104 func PrintMessage() {
105 fmt.Println("hello")
106 }
107 -- m/overlay/printpath.go --
108 package main
109
110 import (
111 "fmt"
112 "path/filepath"
113 "runtime"
114 )
115
116 func 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 --
125 package main
126
127 import (
128 "fmt"
129 "path/filepath"
130 "runtime"
131 )
132
133 func init() {
134 _, file, _, _ := runtime.Caller(0)
135 fmt.Println(filepath.FromSlash(file))
136 }
137 -- m/overlay/dir2_i.go --
138 package dir2
139
140 import "m/dir"
141
142 func printMessage() {
143 dir.PrintMessage()
144 }
145 -- m/overlay/asm_gc.s --
146 // +build gc
147
148 TEXT ·foo(SB),0,$0
149 RET
150
151 -- m/overlay/asm_gccgo.s --
152 // +build gccgo
153
154 .globl main.foo
155 .text
156 main.foo:
157 ret
158
159 -- m/overlay/test_cache.go --
160 package foo
161
162 import "fmt"
163
164 func bar() {
165 fmt.Println("something")
166 }
167 -- m/overlay/test_cache_different.go --
168 package foo
169
170 import "fmt"
171
172 func bar() {
173 fmt.Println("different")
174 }
175
View as plain text