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

Draft code and test for http module extension #16000

Closed
wants to merge 9 commits into from

Conversation

SalmaSamy
Copy link
Contributor

No description provided.

@meteorcloudy meteorcloudy marked this pull request as draft July 29, 2022 12:40
src/test/py/bazel/bzlmod/bazel_module_test.py Outdated Show resolved Hide resolved
for mod in module_ctx.modules:
for file in mod.tags.file:
# Will use the first file that appears in the tree
if file.name in files:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be worried about some transitive dependency deep down the tree breaking the main module due to a name collision. Maybe non-root modules could be required to prefix the name with their module name? That would make collisions mich less likely while still allowing the root module to use essentially any name.

Copy link
Member

@Wyverald Wyverald Aug 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very good point, and one that I think basically kills the proposal.

The requirement to prepend the module name can work, but is rather unwieldy IMO. We could also automatically prepend the module name, but that would be a bit surprising.

My preference now is to use home-made extensions every time, which completely eradicates the name collision problem, and is actually not very verbose IMO. Compare the following two snippets:

# MODULE.bazel
module(name="foo")
http = use_extension("@bazel_tools//tools/build_defs/repo:http.bzl", "http")
http.archive(name="foo_archive", ...)
http.file(name="foo_file", ...)
use_repo(http, archive="foo_archive", file="foo_file")
# MODULE.bazel
my_deps = use_extension("//:my_deps.bzl", "my_deps_ext")
use_repo(my_deps, "archive", "file")

# my_deps.bzl
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")

def my_deps():  # a WORKSPACE macro
  http_archive(name = "archive", ...)
  http_file(name = "file", ...)

my_deps_ext = module_extension(implementation=lambda ctx: my_deps())

The former one does not actually bring much more convenience in my opinion, especially as the my_deps macro in the latter scenario often already exists.

@SalmaSamy SalmaSamy changed the title Draft code and test Draft code and test for http module extension Aug 3, 2022
@meteorcloudy
Copy link
Member

This one is no longer needed

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

Successfully merging this pull request may close these issues.

4 participants