package build import ( "context" "github.com/magefile/mage/mg" "os" "os/exec" "path/filepath" ) func GetBuildToolsDir() (string, error) { basedir, err := os.Getwd() if err != nil { return "", err } return filepath.Join(basedir, "buildtools"), nil } func HasExecutableInBuildtools(name string) (bool, error) { tooldir, err := GetBuildToolsDir() if err != nil { return false, err } info, err := os.Stat(filepath.Join(tooldir, name)) if err != nil { if os.IsNotExist(err) { return false, nil } else { return false, err } } if info.Mode() & 0100 != 0 { return true, nil } else { return false, nil } } func InstallGoExecutable(ctx context.Context, packageNameWithVersion string) error { tooldir, err := GetBuildToolsDir() if err != nil { return err } cmd := exec.CommandContext(ctx, "go", "install", packageNameWithVersion) cmd.Env = append(os.Environ(), "GOBIN=" + tooldir) cmd.Stderr = os.Stderr if mg.Verbose() { cmd.Stdout = os.Stdout } return cmd.Run() }