From 21366dd5023b588215a9820f541b4c3a3e38700f Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Wed, 14 Aug 2024 17:57:24 +0100 Subject: [PATCH 01/13] Go / configure-baseline: account for multiple vendor directories and the `CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS` setting Our existing configure-baseline scripts would give the wrong result if a `vendor` directory wasn't at the root of the repository, or if the `CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS` variable was set to `true` indicating the user wants their vendored code scanned. Here I replace the shell scripts that implemented the very simplest behaviour with a small Go program. --- go/BUILD.bazel | 1 + go/codeql-tools/baseline-config-empty.json | 3 -- go/codeql-tools/baseline-config-vendor.json | 5 -- go/codeql-tools/configure-baseline.cmd | 11 +++-- go/codeql-tools/configure-baseline.sh | 6 +-- .../cli/go-configure-baseline/BUILD.bazel | 18 +++++++ .../go-configure-baseline.go | 14 ++++++ go/extractor/configurebaseline/BUILD.bazel | 10 ++++ .../configurebaseline/configurebaseline.go | 48 +++++++++++++++++++ 9 files changed, 98 insertions(+), 18 deletions(-) delete mode 100644 go/codeql-tools/baseline-config-empty.json delete mode 100644 go/codeql-tools/baseline-config-vendor.json create mode 100644 go/extractor/cli/go-configure-baseline/BUILD.bazel create mode 100644 go/extractor/cli/go-configure-baseline/go-configure-baseline.go create mode 100644 go/extractor/configurebaseline/BUILD.bazel create mode 100644 go/extractor/configurebaseline/configurebaseline.go diff --git a/go/BUILD.bazel b/go/BUILD.bazel index 936c86e0ed13..931f061da9ef 100644 --- a/go/BUILD.bazel +++ b/go/BUILD.bazel @@ -47,6 +47,7 @@ codeql_pkg_files( "//go/extractor/cli/go-autobuilder", "//go/extractor/cli/go-bootstrap", "//go/extractor/cli/go-build-runner", + "//go/extractor/cli/go-configure-baseline", "//go/extractor/cli/go-extractor", "//go/extractor/cli/go-gen-dbscheme", "//go/extractor/cli/go-tokenizer", diff --git a/go/codeql-tools/baseline-config-empty.json b/go/codeql-tools/baseline-config-empty.json deleted file mode 100644 index 568d688fc3fe..000000000000 --- a/go/codeql-tools/baseline-config-empty.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "paths-ignore": [] -} \ No newline at end of file diff --git a/go/codeql-tools/baseline-config-vendor.json b/go/codeql-tools/baseline-config-vendor.json deleted file mode 100644 index d2f654073b03..000000000000 --- a/go/codeql-tools/baseline-config-vendor.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "paths-ignore": [ - "vendor/**" - ] -} \ No newline at end of file diff --git a/go/codeql-tools/configure-baseline.cmd b/go/codeql-tools/configure-baseline.cmd index 285c3d66829a..03edd525f3e6 100644 --- a/go/codeql-tools/configure-baseline.cmd +++ b/go/codeql-tools/configure-baseline.cmd @@ -1,6 +1,7 @@ @echo off -if exist vendor\modules.txt ( - type "%CODEQL_EXTRACTOR_GO_ROOT%\tools\baseline-config-vendor.json" -) else ( - type "%CODEQL_EXTRACTOR_GO_ROOT%\tools\baseline-config-empty.json" -) +SETLOCAL EnableDelayedExpansion + +type NUL && "%CODEQL_EXTRACTOR_GO_ROOT%/tools/%CODEQL_PLATFORM%/go-configure-baseline.exe" +exit /b %ERRORLEVEL% + +ENDLOCAL diff --git a/go/codeql-tools/configure-baseline.sh b/go/codeql-tools/configure-baseline.sh index f426773c3ba0..20edf8b4c93f 100755 --- a/go/codeql-tools/configure-baseline.sh +++ b/go/codeql-tools/configure-baseline.sh @@ -1,7 +1,3 @@ #!/bin/sh -if [ -f vendor/modules.txt ]; then - cat "$CODEQL_EXTRACTOR_GO_ROOT/tools/baseline-config-vendor.json" -else - cat "$CODEQL_EXTRACTOR_GO_ROOT/tools/baseline-config-empty.json" -fi +"$CODEQL_EXTRACTOR_GO_ROOT/tools/$CODEQL_PLATFORM/go-configure-baseline" diff --git a/go/extractor/cli/go-configure-baseline/BUILD.bazel b/go/extractor/cli/go-configure-baseline/BUILD.bazel new file mode 100644 index 000000000000..df1af64d6a33 --- /dev/null +++ b/go/extractor/cli/go-configure-baseline/BUILD.bazel @@ -0,0 +1,18 @@ +# generated running `bazel run //go/gazelle`, do not edit + +load("@rules_go//go:def.bzl", "go_library") +load("//go:rules.bzl", "codeql_go_binary") + +go_library( + name = "go-configure-baseline_lib", + srcs = ["go-configure-baseline.go"], + importpath = "github.com/github/codeql-go/extractor/cli/go-configure-baseline", + visibility = ["//visibility:private"], + deps = ["//go/extractor/configurebaseline"], +) + +codeql_go_binary( + name = "go-configure-baseline", + embed = [":go-configure-baseline_lib"], + visibility = ["//visibility:public"], +) diff --git a/go/extractor/cli/go-configure-baseline/go-configure-baseline.go b/go/extractor/cli/go-configure-baseline/go-configure-baseline.go new file mode 100644 index 000000000000..b7f88230267e --- /dev/null +++ b/go/extractor/cli/go-configure-baseline/go-configure-baseline.go @@ -0,0 +1,14 @@ +package main + +import ( + "github.com/github/codeql-go/extractor/configurebaseline" +) + +func main() { + jsonResult, err := configurebaseline.GetConfigBaselineAsJSON(".") + if err != nil { + panic(err) + } else { + println(string(jsonResult)) + } +} diff --git a/go/extractor/configurebaseline/BUILD.bazel b/go/extractor/configurebaseline/BUILD.bazel new file mode 100644 index 000000000000..7c5161683f5b --- /dev/null +++ b/go/extractor/configurebaseline/BUILD.bazel @@ -0,0 +1,10 @@ +# generated running `bazel run //go/gazelle`, do not edit + +load("@rules_go//go:def.bzl", "go_library") + +go_library( + name = "configurebaseline", + srcs = ["configurebaseline.go"], + importpath = "github.com/github/codeql-go/extractor/configurebaseline", + visibility = ["//visibility:public"], +) diff --git a/go/extractor/configurebaseline/configurebaseline.go b/go/extractor/configurebaseline/configurebaseline.go new file mode 100644 index 000000000000..b8bab4eeb958 --- /dev/null +++ b/go/extractor/configurebaseline/configurebaseline.go @@ -0,0 +1,48 @@ +package configurebaseline + +import ( + "encoding/json" + "io/fs" + "os" + "path" + "path/filepath" +) + +func fileExists(path string) bool { + stat, err := os.Stat(path) + return err == nil && stat.Mode().IsRegular() +} + +func isGolangVendorDirectory(dirPath string) bool { + // Call a directory a Golang vendor directory if it contains a modules.txt file. + return path.Base(dirPath) == "vendor" && fileExists(path.Join(dirPath, "modules.txt")) +} + +type PathsIgnoreStruct struct { + PathsIgnore []string `json:"paths-ignore"` +} + +func GetConfigBaselineAsJSON(rootDir string) ([]byte, error) { + vendorDirs := make([]string, 0) + + // If CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS is "true": + if os.Getenv("CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS") == "true" { + // The user wants vendor directories scanned; emit an empty report. + } else { + filepath.WalkDir(rootDir, func(dirPath string, d fs.DirEntry, err error) error { + if err != nil { + // Mask any unreadable paths. + return nil + } + if isGolangVendorDirectory(dirPath) { + vendorDirs = append(vendorDirs, path.Join(dirPath, "**")) + return filepath.SkipDir + } else { + return nil + } + }) + } + + outputStruct := PathsIgnoreStruct{PathsIgnore: vendorDirs} + return json.Marshal(outputStruct) +} From 624d2b83c04928f32e27f585cac8712aaa8f13db Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Mon, 19 Aug 2024 17:40:27 +0100 Subject: [PATCH 02/13] Tidy comments --- go/extractor/configurebaseline/configurebaseline.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go/extractor/configurebaseline/configurebaseline.go b/go/extractor/configurebaseline/configurebaseline.go index b8bab4eeb958..5ed112c624bb 100644 --- a/go/extractor/configurebaseline/configurebaseline.go +++ b/go/extractor/configurebaseline/configurebaseline.go @@ -13,8 +13,9 @@ func fileExists(path string) bool { return err == nil && stat.Mode().IsRegular() } +// Decides if `dirPath` is a vendor directory by testing whether it is called `vendor` +// and contains a `modules.txt` file. func isGolangVendorDirectory(dirPath string) bool { - // Call a directory a Golang vendor directory if it contains a modules.txt file. return path.Base(dirPath) == "vendor" && fileExists(path.Join(dirPath, "modules.txt")) } @@ -25,7 +26,6 @@ type PathsIgnoreStruct struct { func GetConfigBaselineAsJSON(rootDir string) ([]byte, error) { vendorDirs := make([]string, 0) - // If CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS is "true": if os.Getenv("CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS") == "true" { // The user wants vendor directories scanned; emit an empty report. } else { From 5d34dbf2c296db396a7ab84161c5edb21111b00d Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Mon, 19 Aug 2024 17:49:48 +0100 Subject: [PATCH 03/13] Remove unnecessary batch script flag --- go/codeql-tools/configure-baseline.cmd | 3 --- 1 file changed, 3 deletions(-) diff --git a/go/codeql-tools/configure-baseline.cmd b/go/codeql-tools/configure-baseline.cmd index 03edd525f3e6..47789cfbd3ab 100644 --- a/go/codeql-tools/configure-baseline.cmd +++ b/go/codeql-tools/configure-baseline.cmd @@ -1,7 +1,4 @@ @echo off -SETLOCAL EnableDelayedExpansion type NUL && "%CODEQL_EXTRACTOR_GO_ROOT%/tools/%CODEQL_PLATFORM%/go-configure-baseline.exe" exit /b %ERRORLEVEL% - -ENDLOCAL From 22802fd41fea6b854ab54f9afe30e36abd6c9018 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Mon, 19 Aug 2024 17:50:53 +0100 Subject: [PATCH 04/13] Improve struct naming --- go/extractor/configurebaseline/configurebaseline.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go/extractor/configurebaseline/configurebaseline.go b/go/extractor/configurebaseline/configurebaseline.go index 5ed112c624bb..59075b07239c 100644 --- a/go/extractor/configurebaseline/configurebaseline.go +++ b/go/extractor/configurebaseline/configurebaseline.go @@ -19,7 +19,7 @@ func isGolangVendorDirectory(dirPath string) bool { return path.Base(dirPath) == "vendor" && fileExists(path.Join(dirPath, "modules.txt")) } -type PathsIgnoreStruct struct { +type BaselineConfig struct { PathsIgnore []string `json:"paths-ignore"` } @@ -43,6 +43,6 @@ func GetConfigBaselineAsJSON(rootDir string) ([]byte, error) { }) } - outputStruct := PathsIgnoreStruct{PathsIgnore: vendorDirs} + outputStruct := BaselineConfig{PathsIgnore: vendorDirs} return json.Marshal(outputStruct) } From f1f6f9b580a11977fa31a3da1992b7fb6f70fd15 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Mon, 19 Aug 2024 17:55:42 +0100 Subject: [PATCH 05/13] Share vendor-dir extraction logic between extractor and configure-baseline script --- go/extractor/configurebaseline/configurebaseline.go | 4 +++- go/extractor/extractor.go | 2 +- go/extractor/util/extractvendordirs.go | 9 +++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 go/extractor/util/extractvendordirs.go diff --git a/go/extractor/configurebaseline/configurebaseline.go b/go/extractor/configurebaseline/configurebaseline.go index 59075b07239c..e318111fef91 100644 --- a/go/extractor/configurebaseline/configurebaseline.go +++ b/go/extractor/configurebaseline/configurebaseline.go @@ -6,6 +6,8 @@ import ( "os" "path" "path/filepath" + + "github.com/github/codeql-go/extractor/util" ) func fileExists(path string) bool { @@ -26,7 +28,7 @@ type BaselineConfig struct { func GetConfigBaselineAsJSON(rootDir string) ([]byte, error) { vendorDirs := make([]string, 0) - if os.Getenv("CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS") == "true" { + if util.IsVendorDirExtractionEnabled() { // The user wants vendor directories scanned; emit an empty report. } else { filepath.WalkDir(rootDir, func(dirPath string, d fs.DirEntry, err error) error { diff --git a/go/extractor/extractor.go b/go/extractor/extractor.go index df3a43f80cfa..4926d8e3e13a 100644 --- a/go/extractor/extractor.go +++ b/go/extractor/extractor.go @@ -199,7 +199,7 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error { // If CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS is "true", we extract `vendor` directories; // otherwise (the default) is to exclude them from extraction - includeVendor := os.Getenv("CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS") == "true" + includeVendor := util.IsVendorDirExtractionEnabled() if !includeVendor { excludedDirs = append(excludedDirs, "vendor") } diff --git a/go/extractor/util/extractvendordirs.go b/go/extractor/util/extractvendordirs.go new file mode 100644 index 000000000000..778d5120cf20 --- /dev/null +++ b/go/extractor/util/extractvendordirs.go @@ -0,0 +1,9 @@ +package util + +import ( + "os" +) + +func IsVendorDirExtractionEnabled() bool { + return os.Getenv("CODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS") == "true" +} From ea3e5c8a99011495c02e9ae2a8ff0afbc6a02234 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Mon, 19 Aug 2024 17:57:12 +0100 Subject: [PATCH 06/13] Clarify comment --- go/extractor/configurebaseline/configurebaseline.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/go/extractor/configurebaseline/configurebaseline.go b/go/extractor/configurebaseline/configurebaseline.go index e318111fef91..fa8023f24a8c 100644 --- a/go/extractor/configurebaseline/configurebaseline.go +++ b/go/extractor/configurebaseline/configurebaseline.go @@ -33,7 +33,8 @@ func GetConfigBaselineAsJSON(rootDir string) ([]byte, error) { } else { filepath.WalkDir(rootDir, func(dirPath string, d fs.DirEntry, err error) error { if err != nil { - // Mask any unreadable paths. + // Ignore any unreadable paths -- if this script can't see it, very likely + // it will not be extracted either. return nil } if isGolangVendorDirectory(dirPath) { From 8b9617cd3810c07a32ec173a1b47747d4f258008 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Tue, 20 Aug 2024 15:55:02 +0100 Subject: [PATCH 07/13] Update bazel build files --- go/extractor/configurebaseline/BUILD.bazel | 1 + go/extractor/util/BUILD.bazel | 1 + 2 files changed, 2 insertions(+) diff --git a/go/extractor/configurebaseline/BUILD.bazel b/go/extractor/configurebaseline/BUILD.bazel index 7c5161683f5b..b12e89abaf3c 100644 --- a/go/extractor/configurebaseline/BUILD.bazel +++ b/go/extractor/configurebaseline/BUILD.bazel @@ -7,4 +7,5 @@ go_library( srcs = ["configurebaseline.go"], importpath = "github.com/github/codeql-go/extractor/configurebaseline", visibility = ["//visibility:public"], + deps = ["//go/extractor/util"], ) diff --git a/go/extractor/util/BUILD.bazel b/go/extractor/util/BUILD.bazel index d0195e05be23..b7a7783aa799 100644 --- a/go/extractor/util/BUILD.bazel +++ b/go/extractor/util/BUILD.bazel @@ -5,6 +5,7 @@ load("@rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "util", srcs = [ + "extractvendordirs.go", "semver.go", "util.go", ], From 15b5bcc67c7028a95e792e00bea91bd163eaa90a Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Tue, 20 Aug 2024 17:01:54 +0100 Subject: [PATCH 08/13] Output to stdout, not stderr --- .../cli/go-configure-baseline/go-configure-baseline.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/go/extractor/cli/go-configure-baseline/go-configure-baseline.go b/go/extractor/cli/go-configure-baseline/go-configure-baseline.go index b7f88230267e..c8159908e0a2 100644 --- a/go/extractor/cli/go-configure-baseline/go-configure-baseline.go +++ b/go/extractor/cli/go-configure-baseline/go-configure-baseline.go @@ -1,6 +1,8 @@ package main import ( + "fmt" + "github.com/github/codeql-go/extractor/configurebaseline" ) @@ -9,6 +11,6 @@ func main() { if err != nil { panic(err) } else { - println(string(jsonResult)) + fmt.Println(string(jsonResult)) } } From 3acab640b2b990857f9ecad64a8ee166bc109310 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Tue, 20 Aug 2024 17:07:09 +0100 Subject: [PATCH 09/13] Add configure-baseline integration test --- .../go/configure-baseline/src/a/vendor/avendor.go | 1 + .../go/configure-baseline/src/a/vendor/modules.txt | 0 .../go/configure-baseline/src/b/vendor/bvendor.go | 1 + .../go/configure-baseline/src/b/vendor/modules.txt | 0 .../go/configure-baseline/src/c/vendor/cvendor.go | 1 + .../all-platforms/go/configure-baseline/src/root.go | 1 + .../all-platforms/go/configure-baseline/test.py | 9 +++++++++ 7 files changed, 13 insertions(+) create mode 100644 go/ql/integration-tests/all-platforms/go/configure-baseline/src/a/vendor/avendor.go create mode 100644 go/ql/integration-tests/all-platforms/go/configure-baseline/src/a/vendor/modules.txt create mode 100644 go/ql/integration-tests/all-platforms/go/configure-baseline/src/b/vendor/bvendor.go create mode 100644 go/ql/integration-tests/all-platforms/go/configure-baseline/src/b/vendor/modules.txt create mode 100644 go/ql/integration-tests/all-platforms/go/configure-baseline/src/c/vendor/cvendor.go create mode 100644 go/ql/integration-tests/all-platforms/go/configure-baseline/src/root.go create mode 100644 go/ql/integration-tests/all-platforms/go/configure-baseline/test.py diff --git a/go/ql/integration-tests/all-platforms/go/configure-baseline/src/a/vendor/avendor.go b/go/ql/integration-tests/all-platforms/go/configure-baseline/src/a/vendor/avendor.go new file mode 100644 index 000000000000..6e423a610721 --- /dev/null +++ b/go/ql/integration-tests/all-platforms/go/configure-baseline/src/a/vendor/avendor.go @@ -0,0 +1 @@ +package abc diff --git a/go/ql/integration-tests/all-platforms/go/configure-baseline/src/a/vendor/modules.txt b/go/ql/integration-tests/all-platforms/go/configure-baseline/src/a/vendor/modules.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/go/ql/integration-tests/all-platforms/go/configure-baseline/src/b/vendor/bvendor.go b/go/ql/integration-tests/all-platforms/go/configure-baseline/src/b/vendor/bvendor.go new file mode 100644 index 000000000000..6e423a610721 --- /dev/null +++ b/go/ql/integration-tests/all-platforms/go/configure-baseline/src/b/vendor/bvendor.go @@ -0,0 +1 @@ +package abc diff --git a/go/ql/integration-tests/all-platforms/go/configure-baseline/src/b/vendor/modules.txt b/go/ql/integration-tests/all-platforms/go/configure-baseline/src/b/vendor/modules.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/go/ql/integration-tests/all-platforms/go/configure-baseline/src/c/vendor/cvendor.go b/go/ql/integration-tests/all-platforms/go/configure-baseline/src/c/vendor/cvendor.go new file mode 100644 index 000000000000..6e423a610721 --- /dev/null +++ b/go/ql/integration-tests/all-platforms/go/configure-baseline/src/c/vendor/cvendor.go @@ -0,0 +1 @@ +package abc diff --git a/go/ql/integration-tests/all-platforms/go/configure-baseline/src/root.go b/go/ql/integration-tests/all-platforms/go/configure-baseline/src/root.go new file mode 100644 index 000000000000..6e423a610721 --- /dev/null +++ b/go/ql/integration-tests/all-platforms/go/configure-baseline/src/root.go @@ -0,0 +1 @@ +package abc diff --git a/go/ql/integration-tests/all-platforms/go/configure-baseline/test.py b/go/ql/integration-tests/all-platforms/go/configure-baseline/test.py new file mode 100644 index 000000000000..ea4143496662 --- /dev/null +++ b/go/ql/integration-tests/all-platforms/go/configure-baseline/test.py @@ -0,0 +1,9 @@ +import os.path +import json + +def test(codeql, go): + codeql.database.init(source_root="src") + baseline_info_path = os.path.join("test-db", "baseline-info.json") + with open(baseline_info_path, "r") as f: + baseline_info = json.load(f) + assert set(baseline_info["languages"]["go"]["files"]) == set(["root.go", os.path.join("c", "vendor", "cvendor.go")]), "Expected root.go and cvendor.go in baseline" From fc301206d1d8deeccfc8bb45cf4334d6bf2b5277 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Tue, 20 Aug 2024 17:11:58 +0100 Subject: [PATCH 10/13] Change note --- go/ql/lib/change-notes/2024-08-20-vendor-dirs-baseline.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 go/ql/lib/change-notes/2024-08-20-vendor-dirs-baseline.md diff --git a/go/ql/lib/change-notes/2024-08-20-vendor-dirs-baseline.md b/go/ql/lib/change-notes/2024-08-20-vendor-dirs-baseline.md new file mode 100644 index 000000000000..cab6b49f3baa --- /dev/null +++ b/go/ql/lib/change-notes/2024-08-20-vendor-dirs-baseline.md @@ -0,0 +1,4 @@ +--- +category: fix +--- +* Golang vendor directories not at the root of a repository are now correctly excluded from the baseline Go file count. This means code coverage information will be more accurate. From c99a84689b8665d8d2664218c524365fd4aabc53 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Wed, 21 Aug 2024 09:56:08 +0100 Subject: [PATCH 11/13] Switch test expectations to use unix-style paths --- .../all-platforms/go/configure-baseline/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/ql/integration-tests/all-platforms/go/configure-baseline/test.py b/go/ql/integration-tests/all-platforms/go/configure-baseline/test.py index ea4143496662..b0dbb86365bc 100644 --- a/go/ql/integration-tests/all-platforms/go/configure-baseline/test.py +++ b/go/ql/integration-tests/all-platforms/go/configure-baseline/test.py @@ -6,4 +6,4 @@ def test(codeql, go): baseline_info_path = os.path.join("test-db", "baseline-info.json") with open(baseline_info_path, "r") as f: baseline_info = json.load(f) - assert set(baseline_info["languages"]["go"]["files"]) == set(["root.go", os.path.join("c", "vendor", "cvendor.go")]), "Expected root.go and cvendor.go in baseline" + assert set(baseline_info["languages"]["go"]["files"]) == set(["root.go", "c/vendor/cvendor.go")]), "Expected root.go and cvendor.go in baseline" From 2939cefc68d38685c069ad90aa780a8b9a264308 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Wed, 21 Aug 2024 10:15:44 +0100 Subject: [PATCH 12/13] Use platform path separators for file testing, and forward-slashes for reporting to CodeQL --- go/extractor/configurebaseline/configurebaseline.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/go/extractor/configurebaseline/configurebaseline.go b/go/extractor/configurebaseline/configurebaseline.go index fa8023f24a8c..f8e2c998f8c1 100644 --- a/go/extractor/configurebaseline/configurebaseline.go +++ b/go/extractor/configurebaseline/configurebaseline.go @@ -18,7 +18,7 @@ func fileExists(path string) bool { // Decides if `dirPath` is a vendor directory by testing whether it is called `vendor` // and contains a `modules.txt` file. func isGolangVendorDirectory(dirPath string) bool { - return path.Base(dirPath) == "vendor" && fileExists(path.Join(dirPath, "modules.txt")) + return filepath.Base(dirPath) == "vendor" && fileExists(filepath.Join(dirPath, "modules.txt")) } type BaselineConfig struct { @@ -38,7 +38,8 @@ func GetConfigBaselineAsJSON(rootDir string) ([]byte, error) { return nil } if isGolangVendorDirectory(dirPath) { - vendorDirs = append(vendorDirs, path.Join(dirPath, "**")) + // Note that CodeQL expects a forward-slash-separated path, even on Windows. + vendorDirs = append(vendorDirs, path.Join(filepath.ToSlash(dirPath), "**")) return filepath.SkipDir } else { return nil From f13f19d5dc749666da62136cb1e8e5efa27e2000 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Wed, 21 Aug 2024 10:22:42 +0100 Subject: [PATCH 13/13] Fix typo --- .../all-platforms/go/configure-baseline/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/ql/integration-tests/all-platforms/go/configure-baseline/test.py b/go/ql/integration-tests/all-platforms/go/configure-baseline/test.py index b0dbb86365bc..e92cc868cab5 100644 --- a/go/ql/integration-tests/all-platforms/go/configure-baseline/test.py +++ b/go/ql/integration-tests/all-platforms/go/configure-baseline/test.py @@ -6,4 +6,4 @@ def test(codeql, go): baseline_info_path = os.path.join("test-db", "baseline-info.json") with open(baseline_info_path, "r") as f: baseline_info = json.load(f) - assert set(baseline_info["languages"]["go"]["files"]) == set(["root.go", "c/vendor/cvendor.go")]), "Expected root.go and cvendor.go in baseline" + assert set(baseline_info["languages"]["go"]["files"]) == set(["root.go", "c/vendor/cvendor.go"]), "Expected root.go and cvendor.go in baseline"