bazel-contrib / bazel-gazelle

Gazelle is a Bazel build file generator for Bazel projects. It natively supports Go and protobuf, and it may be extended to support new languages and custom rule sets.
Apache License 2.0
1.21k stars 381 forks source link

bzlmod/go_work: support relative paths #1914

Closed rockwotj closed 2 months ago

rockwotj commented 2 months ago

What type of PR is this?

Feature

What package or component does this PR mostly affect?

go_deps.from_file for bzlmod

What does this PR do? Why is it needed?

We have a use case where we have multiple go modules in a single repo, but adding go.work breaks some existing tooling, if it's added to the root. We want to add it to another location like: bazel/thirdparty but then we need to support having entries in go.work that look like: ../../src/go/rpk. This patch allows leading parent segments (..) in go.work files to support our use case.

Which issues(s) does this PR fix?

Did not file an issue (I can if desired).

Other notes for review

This doesn't guard against relative paths that point outside the repo. I think if desired we could calculate the maximum number of parent segments and limit them. I also have no desire to do full path normalization...

rockwotj commented 2 months ago

I found a work around and don't need this (which was kind of a hack to be honest)

fmeum commented 2 months ago

Could you share the workaround for posterity?

rockwotj commented 2 months ago

https://github.com/redpanda-data/redpanda/commit/5ee6285538fcef659f01a53faf7bfb82fe0ccf3a

Kind of a hack still, but when computing the label the go.work file's location is not accounted for so we can put it in a different directory and the labels stay the same. Fixing that would mean it should normalize paths which would also be the proper fix to allow ../ directives