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

Commit 920f715

Browse files
author
Sauyon Lee
committed
autobuilder: Add dependency check
Sometimes build scripts succeed without installing dependencies, for example if they are unrelated to Go or if they simply always exit successfully. Therefore, added a check that dependencies at least resolve before skipping dependency installation.
1 parent 4a53bfd commit 920f715

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,15 @@ func main() {
455455
// try to build the project
456456
buildSucceeded := autobuilder.Autobuild()
457457

458+
// Build failed or there are still dependency errors; we'll try to install dependencies
459+
// ourselves
458460
if !buildSucceeded {
459-
// 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+
460467
shouldInstallDependencies = true
461468
}
462469
} 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)