rules_go icon indicating copy to clipboard operation
rules_go copied to clipboard

nogo patches doesn't seem to account for `symlink_prefix`

Open omar-scio opened this issue 9 months ago • 1 comments

It seems that this feature (added in https://github.com/bazel-contrib/rules_go/pull/4102) does not account for build --symlink_prefix=<something>.

My .bazelrc says:

build --symlink_prefix=.bazel/

Upon build, I get this:

nogo: errors found by nogo during build-time code analysis:
go/core/utils.go:716:8: Use len(x) == 0 rather than x == "": s == "" (empty_string_check)

-------------------Suggested Fix---------------------
--- a/go/core/utils.go
+++ b/go/core/utils.go
@@ -713,7 +713,7 @@
 }

 func TestRulesGo(s string) string {
-    if s == "" {
+    if len(s) == 0 {
         return "{}"
     }
     return s

-----------------------------------------------------
To apply the suggested fix, run the following command:
$ patch -p1 < bazel-out/darwin_arm64-fastbuild/bin/go/core/core.nogo.patch

This is not quite right given the path is invalid: nogo reports bazel-out/darwin_arm64-fastbuild/bin/go/core/core.nogo.patch when the correct path is .bazel/out/darwin_arm64-fastbuild/bin/go/core/core.nogo.patch. Is rules_go not properly accounting for symlinks?

Environment facts:

  1. Build label: 7.4.1
  2. Go version 1.23
  3. rules_go version v0.53.0
  4. gazelle version v0.35.0

omar-scio avatar Mar 23 '25 01:03 omar-scio

Bazel doesn't expose the symlink prefix to rules and in its exec root always uses bazel-out, which is also the source of these paths in nogo output.

You could file a feature request for Bazel to expose the prefix.

fmeum avatar Mar 24 '25 11:03 fmeum