1 [compiler:gccgo] skip 'gccgo does not support -ldflags -X'
2 env GO111MODULE=off
3 go build run_go.go
4
5 # Apply identity function to GOPATH
6 exec ./run_go$GOEXE $GOPATH/src/my.pkg/main $GOPATH IDENTITY build -o $WORK/tmp/a.exe -ldflags -X=my.pkg.Text=linkXworked
7 exec $WORK/tmp/a.exe
8 stderr 'linkXworked'
9 rm $WORK/tmp/a.exe
10
11 [!GOOS:windows] stop 'rest of the tests only apply to Windows'
12
13 # Replace '\' with '/' in GOPATH
14 exec ./run_go$GOEXE $GOPATH/src/my.pkg/main $GOPATH REPLACE_SLASH build -o $WORK/tmp/a.exe -ldflags -X=my.pkg.Text=linkXworked
15 exec $WORK/tmp/a.exe
16 stderr 'linkXworked'
17 rm $WORK/tmp/a.exe
18
19 # Apply identity function to GOPATH
20 exec ./run_go$GOEXE $GOPATH/src/my.pkg/main $GOPATH UPPER build -o $WORK/tmp/a.exe -ldflags -X=my.pkg.Text=linkXworked
21 exec $WORK/tmp/a.exe
22 stderr 'linkXworked'
23 rm $WORK/tmp/a.exe
24
25 # Apply identity function to GOPATH
26 exec ./run_go$GOEXE $GOPATH/src/my.pkg/main $GOPATH LOWER build -o $WORK/tmp/a.exe -ldflags -X=my.pkg.Text=linkXworked
27 exec $WORK/tmp/a.exe
28 stderr 'linkXworked'
29 rm $WORK/tmp/a.exe
30
31 -- run_go.go --
32 package main
33
34 import (
35 "fmt"
36 "os"
37 "os/exec"
38 "strings"
39 )
40
41 func 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 --
63 package main
64
65 import "my.pkg"
66
67 func main() {
68 println(pkg.Text)
69 }
70 -- my.pkg/pkg.go --
71 package pkg
72
73 var Text = "unset"
74
View as plain text