...
1[short] skip
2[!cgo] skip
3
4# Test building cgo packages in overlays.
5
6cd m
7
8go build -overlay overlay.json -o main_cgo_replace$GOEXE ./cgo_hello_replace
9exec ./main_cgo_replace$GOEXE
10stdout '^hello cgo\r?\n'
11
12go build -overlay overlay.json -o main_cgo_quote$GOEXE ./cgo_hello_quote
13exec ./main_cgo_quote$GOEXE
14stdout '^hello cgo\r?\n'
15
16go build -overlay overlay.json -o main_cgo_angle$GOEXE ./cgo_hello_angle
17exec ./main_cgo_angle$GOEXE
18stdout '^hello cgo\r?\n'
19
20go list -compiled -overlay overlay.json -f '{{range .CompiledGoFiles}}{{. | printf "%s\n"}}{{end}}' ./cgo_hello_replace
21cp stdout compiled_cgo_sources.txt
22go run ../print_line_comments.go compiled_cgo_sources.txt
23stdout $GOPATH[/\\]src[/\\]m[/\\]cgo_hello_replace[/\\]cgo_hello_replace.go
24! stdout $GOPATH[/\\]src[/\\]m[/\\]overlay[/\\]hello.c
25
26-- m/go.mod --
27// TODO(matloob): how do overlays work with go.mod (especially if mod=readonly)
28module m
29
30go 1.16
31
32-- m/overlay.json --
33{
34 "Replace": {
35 "printpath/main.go": "overlay/printpath.go",
36 "printpath/other.go": "overlay2/printpath2.go",
37 "call_asm/asm_gc.s": "overlay/asm_gc.s",
38 "call_asm/asm_gccgo.s": "overlay/asm_gccgo.s",
39 "test_cache/main.go": "overlay/test_cache.go",
40 "cgo_hello_replace/cgo_header.h": "overlay/cgo_head.h",
41 "cgo_hello_replace/hello.c": "overlay/hello.c",
42 "cgo_hello_quote/cgo_hello.go": "overlay/cgo_hello_quote.go",
43 "cgo_hello_quote/cgo_header.h": "overlay/cgo_head.h",
44 "cgo_hello_angle/cgo_hello.go": "overlay/cgo_hello_angle.go",
45 "cgo_hello_angle/cgo_header.h": "overlay/cgo_head.h"
46 }
47}
48-- m/cgo_hello_replace/cgo_hello_replace.go --
49package main
50
51// #include "cgo_header.h"
52import "C"
53
54func main() {
55 C.say_hello()
56}
57-- m/cgo_hello_replace/cgo_header.h --
58 // Test that this header is replaced with one that has the proper declaration.
59void say_goodbye();
60
61-- m/cgo_hello_replace/hello.c --
62#include <stdio.h>
63
64void say_goodbye() { puts("goodbye cgo\n"); fflush(stdout); }
65
66-- m/overlay/cgo_hello_quote.go --
67package main
68
69// #include "cgo_header.h"
70import "C"
71
72func main() {
73 C.say_hello()
74}
75-- m/overlay/cgo_hello_angle.go --
76package main
77
78// #include <cgo_header.h>
79import "C"
80
81func main() {
82 C.say_hello()
83}
84-- m/overlay/cgo_head.h --
85void say_hello();
86-- m/overlay/hello.c --
87#include <stdio.h>
88
89void say_hello() { puts("hello cgo\n"); fflush(stdout); }
90-- m/cgo_hello_quote/hello.c --
91#include <stdio.h>
92
93void say_hello() { puts("hello cgo\n"); fflush(stdout); }
94-- m/cgo_hello_angle/hello.c --
95#include <stdio.h>
96
97void say_hello() { puts("hello cgo\n"); fflush(stdout); }
98
99-- print_line_comments.go --
100package main
101
102import (
103 "fmt"
104 "io/ioutil"
105 "log"
106 "os"
107 "strings"
108)
109
110func main() {
111 compiledGoFilesArg := os.Args[1]
112 b, err := ioutil.ReadFile(compiledGoFilesArg)
113 if err != nil {
114 log.Fatal(err)
115 }
116 compiledGoFiles := strings.Split(strings.TrimSpace(string(b)), "\n")
117 for _, f := range compiledGoFiles {
118 b, err := ioutil.ReadFile(f)
119 if err != nil {
120 log.Fatal(err)
121 }
122 for _, line := range strings.Split(string(b), "\n") {
123 if strings.HasPrefix(line, "#line") || strings.HasPrefix(line, "//line") {
124 fmt.Println(line)
125 }
126 }
127 }
128}
View as plain text