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

It should be possible to use the same extension as both a production and dev dependency #14635

Closed
shs96c opened this issue Jan 24, 2022 · 2 comments
Labels
area-Bzlmod Bzlmod-specific PRs, issues, and feature requests P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: feature request

Comments

@shs96c
Copy link
Contributor

shs96c commented Jan 24, 2022

Description of the problem / feature request:

It's often useful to use the same extension as both a production and development time dependency. eg.

# In MODULE.bazel
http = use_extension(":extensions.bzl", "http")
dev_http = use_extension(":extensions.bzl", "http", dev_dependency = True)

http.archive(
   name = "prod_dep"
   sha256 = "..."
   urls = [ ... ],
)

dev_http.archive(
  name = "dev_dep",
   sha256 = "..."
   urls = [ ... ],
)

When one tries this, the following error is shown:

ERROR: Traceback (most recent call last):
	File "<root>/MODULE.bazel", line 19, column 26, in <toplevel>
Error in use_extension: this extension is already being used at <root>/MODULE.bazel:10:22

As an aside, this message not include the name of the extension which makes debugging harder.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

See above

What's the output of bazel info release?

release 5.0.0

@gregestren gregestren added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. untriaged type: feature request labels Jan 31, 2022
@shs96c
Copy link
Contributor Author

shs96c commented Feb 4, 2022

I would hope that if a dev and production rule tried to create the same named workspace an error would be thrown. I think that's probably inevitable given my mental model of how this works, but best to check

@Wyverald Wyverald added area-Bzlmod Bzlmod-specific PRs, issues, and feature requests P2 We'll consider working on this in future. (Assignee optional) and removed untriaged labels Feb 4, 2022
@Wyverald
Copy link
Member

Wyverald commented Feb 4, 2022

Current thinking is to make the dev_http = use_extension(...) line legal, with the semantics that all dev_http.X tags will only take effect if the current module is the root module. This should be fairly easy to do.

My original thinking was that we could introduce some sort of scoping construct within MODULE.bazel files, to make several statements "dev" (read: effective only in the root module), instead of having dev_dependency=True on each individual statement. "Statement" here would include everything -- bazel_dep, overrides, tags, etc. The tricky part is that there's no easy Starlark syntax for this. So in lieu, the idea above would serve as a rough equivalent of grouping several tags as "dev", which suffices for our use cases for now.

Wyverald added a commit to Wyverald/bazel that referenced this issue Mar 3, 2022
Wyverald added a commit that referenced this issue Mar 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Bzlmod Bzlmod-specific PRs, issues, and feature requests P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: feature request
Projects
None yet
Development

No branches or pull requests

3 participants