aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/build_overlay.txt
blob: 0602e706e9ef9207725de7291829be4275a34882 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
[short] skip

# Test building in overlays.
# TODO(matloob): add a test case where the destination file in the replace map
#   isn't a go file. Either completely exclude that case in fs.IsDirWithGoFiles
#   if the compiler doesn't allow it, or test that it works all the way.

# The main package (m) is contained in an overlay. It imports m/dir2 which has one
# file in an overlay and one file outside the overlay, which in turn imports m/dir,
# which only has source files in the overlay.

cd m

! go build .
go build -overlay overlay.json -o main$GOEXE .
exec ./main$goexe
stdout '^hello$'

go build -overlay overlay.json -o print_abspath$GOEXE ./printpath
exec ./print_abspath$GOEXE
stdout $WORK[/\\]gopath[/\\]src[/\\]m[/\\]printpath[/\\]main.go

go build -overlay overlay.json -o print_trimpath$GOEXE -trimpath ./printpath
exec ./print_trimpath$GOEXE
stdout ^m[/\\]printpath[/\\]main.go

go build -overlay overlay.json -o print_trimpath_two_files$GOEXE printpath/main.go printpath/other.go
exec ./print_trimpath_two_files$GOEXE
stdout $WORK[/\\]gopath[/\\]src[/\\]m[/\\]printpath[/\\]main.go
stdout $WORK[/\\]gopath[/\\]src[/\\]m[/\\]printpath[/\\]other.go

# Run same tests but with gccgo.
env GO111MODULE=off
[!exec:gccgo] stop

! go build -compiler=gccgo .
go build -compiler=gccgo -overlay overlay.json -o main_gccgo$GOEXE .
exec ./main_gccgo$goexe
stdout '^hello$'

go build -compiler=gccgo -overlay overlay.json -o print_abspath_gccgo$GOEXE ./printpath
exec ./print_abspath_gccgo$GOEXE
stdout $WORK[/\\]gopath[/\\]src[/\\]m[/\\]printpath[/\\]main.go

go build -compiler=gccgo -overlay overlay.json -o print_trimpath_gccgo$GOEXE -trimpath ./printpath
exec ./print_trimpath_gccgo$GOEXE
stdout ^\.[/\\]printpath[/\\]main.go

-- m/go.mod --
// TODO(matloob): how do overlays work with go.mod (especially if mod=readonly)
module m

go 1.16

-- m/dir2/h.go --
package dir2

func PrintMessage() {
	printMessage()
}
-- m/dir/foo.txt --
The build action code currently expects the package directory
to exist, so it can run the compiler in that directory.
TODO(matloob): Remove this requirement.
-- m/printpath/about.txt --
the actual code is in the overlay
-- m/overlay.json --
{
	"Replace": {
		"f.go": "overlay/f.go",
		"dir/g.go": "overlay/dir_g.go",
		"dir2/i.go": "overlay/dir2_i.go",
		"printpath/main.go": "overlay/printpath.go",
		"printpath/other.go": "overlay2/printpath2.go"
	}
}
-- m/overlay/f.go --
package main

import "m/dir2"

func main() {
	dir2.PrintMessage()
}
-- m/overlay/dir_g.go --
package dir

import "fmt"

func PrintMessage() {
	fmt.Println("hello")
}
-- m/overlay/printpath.go --
package main

import (
	"fmt"
	"path/filepath"
	"runtime"
)

func main() {
	_, file, _, _ := runtime.Caller(0)

	// Since https://golang.org/cl/214286, the runtime's debug paths are
	// slash-separated regardless of platform, so normalize them to system file
	// paths.
	fmt.Println(filepath.FromSlash(file))
}
-- m/overlay2/printpath2.go --
package main

import (
	"fmt"
	"path/filepath"
	"runtime"
)

func init() {
	_, file, _, _ := runtime.Caller(0)
	fmt.Println(filepath.FromSlash(file))
}
-- m/overlay/dir2_i.go --
package dir2

import "m/dir"

func printMessage() {
	dir.PrintMessage()
}