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.
51 lines
1009 B
51 lines
1009 B
3 years ago
|
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()
|
||
|
}
|