Skip to content

Commit

Permalink
Avoid -mod=vendor when there's no vendor folder
Browse files Browse the repository at this point in the history
This accounts for the fact that Terraform no longer vendors dependencies
  • Loading branch information
radeksimko authored and paultyng committed Sep 25, 2020
1 parent 48ef9fa commit d5e1b68
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tfinstall/git_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"

"github.com/go-git/go-git/v5"
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit d5e1b68

Please sign in to comment.