From 8f6b25e0acf85baea153276ff2bb55aa6a11b2dd Mon Sep 17 00:00:00 2001 From: Sauyon Lee Date: Tue, 25 Aug 2020 03:51:13 -0700 Subject: [PATCH] autobuilder: Use -mod=mod for vendor directories wihtout modules.txt --- extractor/cli/go-autobuilder/go-autobuilder.go | 3 +++ extractor/util/util.go | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/extractor/cli/go-autobuilder/go-autobuilder.go b/extractor/cli/go-autobuilder/go-autobuilder.go index 75503aaeeec..99f9af145c9 100644 --- a/extractor/cli/go-autobuilder/go-autobuilder.go +++ b/extractor/cli/go-autobuilder/go-autobuilder.go @@ -244,7 +244,10 @@ func main() { // skip the dependency installation step and run the extractor with `-mod=vendor` if util.FileExists("vendor/modules.txt") { modMode = ModVendor + } else if util.DirExists("vendor") { + modMode = modModIfSupported() } + if modMode == ModVendor { // fix go vendor issues with go versions >= 1.14 when no go version is specified in the go.mod // if this is the case, and dependencies were vendored with an old go version (and therefore diff --git a/extractor/util/util.go b/extractor/util/util.go index c8eeb33f484..a592224672c 100644 --- a/extractor/util/util.go +++ b/extractor/util/util.go @@ -91,3 +91,12 @@ func FileExists(filename string) bool { } return err == nil && !info.IsDir() } + +// DirExists tests whether `filename` exists and is a directory. +func DirExists(filename string) bool { + info, err := os.Stat(filename) + if err != nil && !os.IsNotExist(err) { + log.Printf("Unable to stat %s: %s\n", filename, err.Error()) + } + return err == nil && info.IsDir() +}