Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: patch includes in MODULE.bazel when publishing #3301

Open
jjmaestro opened this issue Dec 2, 2024 · 2 comments
Open

feat: patch includes in MODULE.bazel when publishing #3301

jjmaestro opened this issue Dec 2, 2024 · 2 comments

Comments

@jjmaestro
Copy link

MODULE.bazel can use include to organize dependencies but, per the docs:

Only the root module may use include(); it is an error if a bazel_dep's MODULE file uses include().

In Slack Thread @fmeum suggested that

combining all the [include] segments into a single MODULE.bazel file could be a feature of a tool based on the buildozer API
(...)
the tool needs to rename top-level variables that conflict. Or use a pattern such as IIFE (immediately invoked function expression).
(...)
It could even be combined with the Publish to BCR app to automatically patch in the full module file content

It would be great to have such a tool and/or automation in the BCR tools!

@fmeum
Copy link
Contributor

fmeum commented Dec 2, 2024

I'll bring this up at the next Rules Authors SIG meeting.

@jjmaestro
Copy link
Author

Here's a couple more things I thought about:

"pattern"

Maybe a "pattern" that could work nicely would be to invoke such a tool from a tools/bazel wrapper. Something like:

  • move MODULE.bazel to includes.MODULE.bazel at the root
  • add MODULE.bazel to .gitignore
  • have a wrapper in tools/bazel that invokes the tool which parses include.MODULE.bazel and materializes the MODULE.bazel

IMHO it would be ideal if buildozer had an expand_include command that would perform the recursive expansion.

renaming variables

For the renaming of the variables, the tool could probably use the path to the include file plus the MODULE prefix, e.g.:

# includes.MODULE.bazel at the root
include("//dir1/dir2/foo.MODULE.bazel")

bar = use_extension("//other/path:extension.bzl", "bar")
# dir1/dir2/foo.MODULE.bazel

bar = use_extension("//1/2/3:extension.bzl", "bar")

These would expand to:

# MODULE.bazel at the root

# include("//dir1/dir2/foo.MODULE.bazel")
dir1_dir2_foo_bar = use_extension("//1/2/3:extension.bzl", "bar")

bar = use_extension("//other/path:extension.bzl", "bar")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants