Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 82a5b5f

Browse files
authored
Merge pull request #369 from sauyon/checkdeps
Check dependencies before skipping dependency installation
2 parents 04cec8b + 920f715 commit 82a5b5f

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

extractor/cli/go-autobuilder/go-autobuilder.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,14 @@ func main() {
293293
log.Println("Found glide.yaml, enabling go modules")
294294
}
295295

296-
// if a vendor/modules.txt file exists, we assume that there are vendored Go dependencies, and
297-
// skip the dependency installation step and run the extractor with `-mod=vendor`
298-
if util.FileExists("vendor/modules.txt") {
299-
modMode = ModVendor
300-
} else if util.DirExists("vendor") {
301-
modMode = ModMod
296+
if depMode == GoGetWithModules {
297+
// if a vendor/modules.txt file exists, we assume that there are vendored Go dependencies, and
298+
// skip the dependency installation step and run the extractor with `-mod=vendor`
299+
if util.FileExists("vendor/modules.txt") {
300+
modMode = ModVendor
301+
} else if util.DirExists("vendor") {
302+
modMode = ModMod
303+
}
302304
}
303305

304306
if modMode == ModVendor {
@@ -453,8 +455,15 @@ func main() {
453455
// try to build the project
454456
buildSucceeded := autobuilder.Autobuild()
455457

458+
// Build failed or there are still dependency errors; we'll try to install dependencies
459+
// ourselves
456460
if !buildSucceeded {
457-
// Build failed; we'll try to install dependencies ourselves
461+
log.Println("Build failed, continuing to install dependencies.")
462+
463+
shouldInstallDependencies = true
464+
} else if util.DepErrors("./...", modMode.argsForGoVersion(getEnvGoSemVer())...) {
465+
log.Println("Dependencies are still not resolving after the build, continuing to install dependencies.")
466+
458467
shouldInstallDependencies = true
459468
}
460469
} else {

extractor/util/util.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ func GetPkgDir(pkgpath string, flags ...string) string {
9090
return abs
9191
}
9292

93+
// DepErrors checks there are any errors resolving dependencies for `pkgpath`. It passes the `go
94+
// list` command the flags specified by `flags`.
95+
func DepErrors(pkgpath string, flags ...string) bool {
96+
out, err := runGoList("{{if .DepsErrors}}{{else}}error{{end}}", pkgpath, flags...)
97+
if err != nil {
98+
// if go list failed, assume dependencies are broken
99+
return false
100+
}
101+
102+
return out != ""
103+
}
104+
93105
// FileExists tests whether the file at `filename` exists and is not a directory.
94106
func FileExists(filename string) bool {
95107
info, err := os.Stat(filename)

0 commit comments

Comments
 (0)