1 // +build !nacl,!js,!wasip1
4 // Copyright 2014 The Go Authors. All rights reserved.
5 // Use of this source code is governed by a BSD-style
6 // license that can be found in the LICENSE file.
27 func run(cmdline ...string) {
28 args := strings.Fields(strings.Join(cmdline, " "))
29 cmd := exec.Command(args[0], args[1:]...)
30 out, err := cmd.CombinedOutput()
32 fmt.Printf("$ %s\n", cmdline)
33 fmt.Println(string(out))
40 func runFail(cmdline ...string) {
41 args := strings.Fields(strings.Join(cmdline, " "))
42 cmd := exec.Command(args[0], args[1:]...)
43 out, err := cmd.CombinedOutput()
45 fmt.Printf("$ %s\n", cmdline)
46 fmt.Println(string(out))
47 fmt.Println("SHOULD HAVE FAILED!")
55 tmpDir, err = ioutil.TempDir("", "")
60 tmp := func(name string) string {
61 return filepath.Join(tmpDir, name)
64 importcfg, err := exec.Command("go", "list", "-export", "-f", "{{if .Export}}packagefile {{.ImportPath}}={{.Export}}{{end}}", "std").Output()
69 os.WriteFile(tmp("importcfg"), importcfg, 0644)
71 // helloworld.go is package main
72 run("go tool compile -p=main -importcfg", tmp("importcfg"), "-o", tmp("linkmain.o"), "helloworld.go")
73 run("go tool compile -p=main -importcfg", tmp("importcfg"), " -pack -o", tmp("linkmain.a"), "helloworld.go")
74 run("go tool link -importcfg", tmp("importcfg"), "-o", tmp("linkmain.exe"), tmp("linkmain.o"))
75 run("go tool link -importcfg", tmp("importcfg"), "-o", tmp("linkmain.exe"), tmp("linkmain.a"))
78 run("go tool compile -importcfg", tmp("importcfg"), "-p=notmain -o", tmp("linkmain1.o"), "linkmain.go")
79 run("go tool compile -importcfg", tmp("importcfg"), "-p=notmain -pack -o", tmp("linkmain1.a"), "linkmain.go")
80 runFail("go tool link -importcfg", tmp("importcfg"), "-o", tmp("linkmain.exe"), tmp("linkmain1.o"))
81 runFail("go tool link -importcfg", tmp("importcfg"), "-o", tmp("linkmain.exe"), tmp("linkmain1.a"))