This repo demonstrates how autogold doesn't work in bazel mode even with ENABLE_BAZEL_PACKAGES_LOAD_HACK=true
is set.
First, verify it works fine with vanila Go:
go test -v ./version/.
Then, verify it fails with bazel:
bazel test //version/...
The error is:
-- want
++ got
@@ -1,9 +1 @@
&version.Version{semver: &version.Version{
segments: []int64{
1,
2,
3,
},
si: 3,
original: "1.2.3",
}}
valast: format: 4:33: expected operand, found 'go'
found 'go'
?
It turned out the bazel hack from autogold
, bazelPackagePathToName infers the package name from the last component of the full package name.
In this example, we use a package github.com/hashicorp/go-version
but the package name is actually package version
.
Therefore, autogold will return go-version
when bazelPackagePathToName
is called. Obviously, go-version
is not valid syntax for Go.
Clone them somewhere, and run:
cd valast
gazelle -repo_root=. -go_prefix=github.com/hexops/valast
touch WORKSPACE
cd autogold
gazelle -repo_root=. -go_prefix=github.com/hexops/autogold/v2
touch WORKSPACE
Then, replace "@com_github_hexops_valast//:go_default_library"
with "@com_github_hexops_valast//:valast",
in autogold/BUILD.bazel
.
Modify local_repositiry
in WORKSPACE
and replace
directive in go.mod
.