|
1 | 1 | // +build ignore |
2 | 2 |
|
3 | 3 | // This is run during go generate and embeds ssh-agent-pipe into the ssh-agent-inject binary. |
4 | | -// * Compiles the ssh-agent-pipe binary for all platforms. |
| 4 | +// * Compiles the ssh-agent-pipe binary for all target platforms (GOOS=linux, different GOARCHs). |
5 | 5 | // * Creates a .tar.gz with that binary having executable permissions set. |
6 | | -// * Stores that .tar.gz files in the assets/ folder as Go source files targeting the respective host platform. |
| 6 | +// * Stores that .tar.gz files in the assets/ folder as Go source files targeting the respective GOARCH. |
7 | 7 |
|
8 | 8 | package main |
9 | 9 |
|
@@ -31,19 +31,17 @@ const AgentArchive = {{.agent|quote}} |
31 | 31 | func main() { |
32 | 32 | os.RemoveAll("assets") |
33 | 33 | os.MkdirAll("assets", 0700) |
34 | | - platforms := map[string][]string{ |
35 | | - "amd64": {"darwin", "linux", "windows"}, |
36 | | - "arm": {"linux"}, |
37 | | - "arm64": {"linux"}, |
| 34 | + archs := []string{ |
| 35 | + "amd64", |
| 36 | + "arm", |
| 37 | + "arm64", |
38 | 38 | } |
39 | | - for arch, hosts := range platforms { |
| 39 | + for _, arch := range archs { |
40 | 40 | archive, err := buildAgentArchive(arch) |
41 | 41 | if err != nil { |
42 | 42 | log.Fatalln("Failed compiling ssh-agent-pipe", err) |
43 | 43 | } |
44 | | - for _, host := range hosts { |
45 | | - genPlatformAssets(arch, host, archive) |
46 | | - } |
| 44 | + genPlatformAssets(arch, archive) |
47 | 45 | } |
48 | 46 | } |
49 | 47 |
|
@@ -81,13 +79,14 @@ func buildAgentArchive(arch string) ([]byte, error) { |
81 | 79 | return buffer.Bytes(), nil |
82 | 80 | } |
83 | 81 |
|
84 | | -func genPlatformAssets(arch string, hostOS string, archive []byte) { |
85 | | - config := map[string]string{ |
86 | | - "agent": string(archive), |
87 | | - } |
88 | | - file, err := os.Create(fmt.Sprintf("assets/assets_%s_%s.go", hostOS, arch)) |
| 82 | +func genPlatformAssets(arch string, archive []byte) { |
| 83 | + file, err := os.Create(fmt.Sprintf("assets/assets_%s.go", arch)) |
| 84 | + defer file.Close() |
89 | 85 | if err != nil { |
90 | 86 | log.Fatalln("Failed writing assets", err) |
91 | 87 | } |
| 88 | + config := map[string]string{ |
| 89 | + "agent": string(archive), |
| 90 | + } |
92 | 91 | assetsTemplate.Execute(file, config) |
93 | 92 | } |
0 commit comments