From d5e1b687e5980d76c2488415cf0eb75b48f9e52b Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Fri, 25 Sep 2020 10:06:25 +0100 Subject: [PATCH] Avoid -mod=vendor when there's no vendor folder This accounts for the fact that Terraform no longer vendors dependencies --- tfinstall/git_ref.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tfinstall/git_ref.go b/tfinstall/git_ref.go index 60c01783..71149bd4 100644 --- a/tfinstall/git_ref.go +++ b/tfinstall/git_ref.go @@ -5,7 +5,9 @@ import ( "fmt" "io/ioutil" "log" + "os" "os/exec" + "path/filepath" "runtime" "github.com/go-git/go-git/v5" @@ -72,7 +74,14 @@ func (opt *GitRefOption) ExecPath(ctx context.Context) (string, error) { binFile.Close() } - cmd := exec.CommandContext(ctx, "go", "build", "-mod", "vendor", "-o", binName) + goArgs := []string{"build", "-o", binName} + + vendorDir := filepath.Join(installDir, "vendor") + if fi, err := os.Stat(vendorDir); err == nil && fi.IsDir() { + goArgs = append(goArgs, "-mod", "vendor") + } + + cmd := exec.CommandContext(ctx, "go", goArgs...) cmd.Dir = installDir out, err := cmd.CombinedOutput() log.Print(string(out))