...
1[compiler:gccgo] skip 'gccgo does not support -ldflags -X'
2env GO111MODULE=off
3go build run_go.go
4
5# Apply identity function to GOPATH
6exec ./run_go$GOEXE $GOPATH/src/my.pkg/main $GOPATH IDENTITY build -o $WORK/tmp/a.exe -ldflags -X=my.pkg.Text=linkXworked
7exec $WORK/tmp/a.exe
8stderr 'linkXworked'
9rm $WORK/tmp/a.exe
10
11[!GOOS:windows] stop 'rest of the tests only apply to Windows'
12
13# Replace '\' with '/' in GOPATH
14exec ./run_go$GOEXE $GOPATH/src/my.pkg/main $GOPATH REPLACE_SLASH build -o $WORK/tmp/a.exe -ldflags -X=my.pkg.Text=linkXworked
15exec $WORK/tmp/a.exe
16stderr 'linkXworked'
17rm $WORK/tmp/a.exe
18
19# Apply identity function to GOPATH
20exec ./run_go$GOEXE $GOPATH/src/my.pkg/main $GOPATH UPPER build -o $WORK/tmp/a.exe -ldflags -X=my.pkg.Text=linkXworked
21exec $WORK/tmp/a.exe
22stderr 'linkXworked'
23rm $WORK/tmp/a.exe
24
25# Apply identity function to GOPATH
26exec ./run_go$GOEXE $GOPATH/src/my.pkg/main $GOPATH LOWER build -o $WORK/tmp/a.exe -ldflags -X=my.pkg.Text=linkXworked
27exec $WORK/tmp/a.exe
28stderr 'linkXworked'
29rm $WORK/tmp/a.exe
30
31-- run_go.go --
32package main
33
34import (
35 "fmt"
36 "os"
37 "os/exec"
38 "strings"
39)
40
41func main() {
42 dir := os.Args[1]
43 gopath := os.Args[2]
44 switch os.Args[3] {
45 case "IDENTITY":
46 case "REPLACE_SLASH": gopath = strings.ReplaceAll(gopath, `\`, `/`)
47 case "UPPER": gopath = strings.ToUpper(gopath)
48 case "LOWER": gopath = strings.ToLower(gopath)
49 default: fmt.Fprintln(os.Stderr, "bad op"); os.Exit(1)
50 }
51 cmd := exec.Command("go", os.Args[4:]...)
52 cmd.Dir = dir
53 cmd.Env = append(os.Environ(), "GOPATH="+gopath)
54 cmd.Stdout = os.Stdout
55 cmd.Stderr = os.Stderr
56 if err := cmd.Run(); err != nil {
57 fmt.Fprintln(os.Stderr, err)
58 os.Exit(1)
59 }
60}
61
62-- my.pkg/main/main.go --
63package main
64
65import "my.pkg"
66
67func main() {
68 println(pkg.Text)
69}
70-- my.pkg/pkg.go --
71package pkg
72
73var Text = "unset"
View as plain text