You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
871 B

  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. // +build !plan9
  5. package main
  6. import (
  7. "bytes"
  8. "context"
  9. "os/exec"
  10. "runtime"
  11. "strings"
  12. )
  13. // arch contains either amd64 or 386.
  14. var arch = func() string {
  15. cmd := exec.Command("uname", "-m") // "x86_64"
  16. if runtime.GOOS == "windows" {
  17. cmd = exec.Command("powershell", "-command", "(Get-WmiObject -Class Win32_ComputerSystem).SystemType") // "x64-based PC"
  18. }
  19. out, err := cmd.Output()
  20. if err != nil {
  21. // a sensible default?
  22. return "amd64"
  23. }
  24. if bytes.Contains(out, []byte("64")) {
  25. return "amd64"
  26. }
  27. return "386"
  28. }()
  29. func findGo(ctx context.Context, cmd string) (string, error) {
  30. out, err := exec.CommandContext(ctx, cmd, "go").CombinedOutput()
  31. return strings.TrimSpace(string(out)), err
  32. }