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.
|
|
|
package build
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"github.com/magefile/mage/mg"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
|
|
|
const ToolsDir = "buildtools"
|
|
|
|
|
|
|
|
func HasExecutableInTools(name string) (bool, error) {
|
|
|
|
info, err := os.Stat(filepath.Join(ToolsDir, 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 := filepath.Abs(ToolsDir)
|
|
|
|
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()
|
|
|
|
}
|