blob: 232ca366ca265b984c4b8e052f6b19ca738ff844 [file] [log] [blame]
Chris Broadfootac1e4b12017-07-25 14:46:40 -07001// 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 Fitzpatrick36c7af32017-11-29 19:51:57 +00005// +build !plan9
6
Chris Broadfootac1e4b12017-07-25 14:46:40 -07007package main
8
9import (
10 "bytes"
Jaana Burcu Dogan9badcbe2017-07-29 12:51:58 -070011 "context"
Roland Shoemakerfe37c9e2021-01-11 10:19:11 -080012 exec "golang.org/x/sys/execabs"
Chris Broadfootac1e4b12017-07-25 14:46:40 -070013 "runtime"
Jaana Burcu Dogan9badcbe2017-07-29 12:51:58 -070014 "strings"
Chris Broadfootac1e4b12017-07-25 14:46:40 -070015)
16
17// arch contains either amd64 or 386.
18var 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 Dogan9badcbe2017-07-29 12:51:58 -070034
35func 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}