Chris Broadfoot | ac1e4b1 | 2017-07-25 14:46:40 -0700 | [diff] [blame] | 1 | // Copyright 2017 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
Brad Fitzpatrick | 36c7af3 | 2017-11-29 19:51:57 +0000 | [diff] [blame] | 5 | // +build !plan9 |
| 6 | |
Chris Broadfoot | ac1e4b1 | 2017-07-25 14:46:40 -0700 | [diff] [blame] | 7 | package main |
| 8 | |
| 9 | import ( |
| 10 | "bytes" |
Jaana Burcu Dogan | 9badcbe | 2017-07-29 12:51:58 -0700 | [diff] [blame] | 11 | "context" |
Roland Shoemaker | fe37c9e | 2021-01-11 10:19:11 -0800 | [diff] [blame] | 12 | exec "golang.org/x/sys/execabs" |
Chris Broadfoot | ac1e4b1 | 2017-07-25 14:46:40 -0700 | [diff] [blame] | 13 | "runtime" |
Jaana Burcu Dogan | 9badcbe | 2017-07-29 12:51:58 -0700 | [diff] [blame] | 14 | "strings" |
Chris Broadfoot | ac1e4b1 | 2017-07-25 14:46:40 -0700 | [diff] [blame] | 15 | ) |
| 16 | |
| 17 | // arch contains either amd64 or 386. |
| 18 | var arch = func() string { |
| 19 | cmd := exec.Command("uname", "-m") // "x86_64" |
| 20 | if runtime.GOOS == "windows" { |
| 21 | cmd = exec.Command("powershell", "-command", "(Get-WmiObject -Class Win32_ComputerSystem).SystemType") // "x64-based PC" |
| 22 | } |
| 23 | |
| 24 | out, err := cmd.Output() |
| 25 | if err != nil { |
| 26 | // a sensible default? |
| 27 | return "amd64" |
| 28 | } |
| 29 | if bytes.Contains(out, []byte("64")) { |
| 30 | return "amd64" |
| 31 | } |
| 32 | return "386" |
| 33 | }() |
Jaana Burcu Dogan | 9badcbe | 2017-07-29 12:51:58 -0700 | [diff] [blame] | 34 | |
| 35 | func findGo(ctx context.Context, cmd string) (string, error) { |
| 36 | out, err := exec.CommandContext(ctx, cmd, "go").CombinedOutput() |
| 37 | return strings.TrimSpace(string(out)), err |
| 38 | } |