Skip to content

Commit 1cbaca4

Browse files
committed
fix: Resolve the test manifest with the runfiles lib.
This makes it possible for the test to work with sibling repository layout. Tested by running the :gazelle_python_manifest.test in build_file_generation with all combinations of both values of --legacy_external_runfiles, --enable_bzlmod and --sibling_repository_layout.
1 parent 49cdf7d commit 1cbaca4

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

gazelle/manifest/defs.bzl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def gazelle_python_manifest(
116116
attrs = {
117117
"env": {
118118
"_TEST_MANIFEST": "$(rootpath {})".format(manifest),
119-
"_TEST_MANIFEST_GENERATOR_HASH": "$(rootpath {})".format(manifest_generator_hash),
119+
"_TEST_MANIFEST_GENERATOR_HASH": "$(rlocationpath {})".format(manifest_generator_hash),
120120
"_TEST_REQUIREMENTS": "$(rootpath {})".format(requirements),
121121
},
122122
"size": "small",
@@ -130,7 +130,10 @@ def gazelle_python_manifest(
130130
manifest_generator_hash,
131131
],
132132
rundir = ".",
133-
deps = [Label("//manifest")],
133+
deps = [
134+
Label("//manifest"),
135+
Label("@com_github_bazelbuild_rules_go//go/runfiles"),
136+
],
134137
# kwargs could contain test-specific attributes like size or timeout
135138
**dict(attrs, **kwargs)
136139
)

gazelle/manifest/test/test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"path/filepath"
2727
"testing"
2828

29+
"github.com/bazelbuild/rules_go/go/runfiles"
2930
"github.com/bazelbuild/rules_python/gazelle/manifest"
3031
)
3132

@@ -49,7 +50,12 @@ func TestGazelleManifestIsUpdated(t *testing.T) {
4950
t.Fatal("failed to find the Gazelle manifest file integrity")
5051
}
5152

52-
manifestGeneratorHashPath := os.Getenv("_TEST_MANIFEST_GENERATOR_HASH")
53+
manifestGeneratorHashPath, err := runfiles.Rlocation(
54+
os.Getenv("_TEST_MANIFEST_GENERATOR_HASH"))
55+
if err != nil {
56+
t.Fatal("failed to resolve runfiles path of manifest: %v", err)
57+
}
58+
5359
manifestGeneratorHash, err := os.Open(manifestGeneratorHashPath)
5460
if err != nil {
5561
t.Fatalf("opening %q: %v", manifestGeneratorHashPath, err)

0 commit comments

Comments
 (0)