From 45c349a8ffbe124eb8800be963d1476b155ab8f4 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Wed, 24 Jan 2024 13:09:18 +0000 Subject: [PATCH] Go: Emit relative path import diagnostic if prompted by `go mod tidy` The corresponding integration test now successfully extracts the project --- go/extractor/cli/go-autobuilder/go-autobuilder.go | 9 ++++++++- .../go/diagnostics/unsupported-relative-path/test.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/go/extractor/cli/go-autobuilder/go-autobuilder.go b/go/extractor/cli/go-autobuilder/go-autobuilder.go index 953ab1775d07b..72f7b8780a59e 100644 --- a/go/extractor/cli/go-autobuilder/go-autobuilder.go +++ b/go/extractor/cli/go-autobuilder/go-autobuilder.go @@ -463,8 +463,15 @@ func initGoModForLegacyProject(buildInfo project.BuildInfo) { modTidy := exec.Command("go", "mod", "tidy") modTidy.Dir = buildInfo.BaseDir - if !util.RunCmd(modTidy) { + out, err := modTidy.CombinedOutput() + log.Println(out) + + if err != nil { log.Printf("Failed to determine module requirements for this project.") + + if strings.Contains(string(out), "is relative, but relative import paths are not supported in module mode") { + diagnostics.EmitRelativeImportPaths() + } } } diff --git a/go/ql/integration-tests/all-platforms/go/diagnostics/unsupported-relative-path/test.py b/go/ql/integration-tests/all-platforms/go/diagnostics/unsupported-relative-path/test.py index 21a6cd40ef7dc..841351c4f670e 100644 --- a/go/ql/integration-tests/all-platforms/go/diagnostics/unsupported-relative-path/test.py +++ b/go/ql/integration-tests/all-platforms/go/diagnostics/unsupported-relative-path/test.py @@ -10,7 +10,7 @@ goPath = os.path.join(os.path.abspath(os.getcwd()), ".go") os.environ['GOPATH'] = goPath os.environ['GITHUB_REPOSITORY'] = "a/b" -run_codeql_database_create([], lang="go", source="work", db=None, runFunction=runUnsuccessfully) +run_codeql_database_create([], lang="go", source="work", db=None) check_diagnostics()