-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
native.repository_name() and ctx.workspace_name() are similar function but with different name #4092
Comments
I am also finding it confusing that |
I'd also find it very useful to be able to get the "real" workspace name inside a macro, rather than having to specify it. Use case: I have a lot of include paths that include the workspace/repo name, so that it's always clear from looking at an Related issue, visible with multiple repos:
If we're in IMO the workspace name should always be the name declared in its workspace file, regardless of how it's named when imported by At least, there should be some way of retrieving the "real" name even if there is a legit case for altering what |
I have the same issue with Incidentally, the title of the issue makes this difficult to find. I spent a while trying to figure out if I was using |
+1 for being able to get the real workspace name from a macro. |
Ran into this problem myself today (dgp1130/rules_prerender@cc89f55) and had to make some awkward compromises to my desired API to make it work. Are there any objections to adding a new I'm open to making a PR for this if I can at least confirm that this is right path forward. Seems like we just need to add a new |
Refs #28. This introduces a new `prerender_resources()` macro, which is a lower-level of abstraction than `prerender_pages_unbundled()`. It is responsible for simply generating an executing the renderer and collecting its output in a directory. It does **not** perform any subsequent processing like extracting annotations or generating scripts or styles. As a result, this has no hard or implicit expectation that user code generates HTML files, making this a good candidate for scripts which generate raw data instead of actual web pages. One consequence of this is that it does *not* make sense to depend on `prerender_component()` targets, because the output is not a web page and will not be bundled. This means that `prerender_resources()` simply takes a `ts_library()` (or any JavaScript files) as inputs, giving the macro less responsibility. The downside however is that we need to replicate the `entry_point` behavior of `nodejs_binary()`, which is quite involved and I don't want to match that exactly. Instead, `prerender_resources()` requires the full workspace-relative path to be provided. This avoids ambiguity, but is a little annoying and easy to screw up. I did try to require the workspace itself in the path, but this would break `prerender_pages_unbundled()` because there is no way to look up the workspace name in a macro. For now, `prerender_resources()` just doesn't support source files in a different workspace, requiring users to manually copy them over.
[Migration guide](https://github.com/bazelbuild/rules_nodejs/wiki/Migrating-to-5.0) and [release notes](https://github.com/bazelbuild/rules_nodejs/releases/5.0.0) for the major version change. `@bazel/*` deps need to be kept on the same major version as `rules_nodejs`, so they were updated at the same time. Breaking changes which needed to be fixed included: 1. Swapped `node_repositories()` with `nodejs_register_toolchains()` (not really a breaking change and kept NodeJS version the same). 2. `[email protected]` sets `exports_directories_only = True` by default, [which breaks `ts_library()`](https://github.com/bazelbuild/rules_nodejs/wiki/Migrating-to-5.0#exports_directories_only). For now, I overrode this to be `exports_directories_only = False` to stay on the old behavior. Most likely upgrading to `ts_project()` will unblock this flag flip. 3. `ts_library()` was moved to `@npm//@bazel/concatjs:index.bzl`, so all the existing `load()` statements had to be updated. 4. `concatjs_devserver()` now seems to require the workspace name as a prefix to `additional_root_paths`. Unfortunately [there is no way to get the workspace name at loading time](bazelbuild/bazel#4092 (comment)) without hard-coding it which isn't feasible for `web_resources_devserver()` which needs to be usable outside the `rules_prerender` workspace. Fortunately `__main__` seems to work (default workspace name) even though this workspace has a custom name. I also tested on `ref/external` and confirmed that a separate workspace is able to load and use `web_resources_devserver()` as expected.
Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team ( |
My offer to contribute something here still stands, if anyone can confirm that is indeed the right approach to solve this particular problem and that the contribution would be accepted. |
A number of things have changed since then:
I would suggest the following "migration guide":
CC @Wyverald |
Thanks for the recommendations @fmeum. I tried applying this to my usage, but don't see a clear path to it. Specifically your point:
Are there any suggestions for how to handle runfiles paths in APIs where Make variable expansion is not happening? My particular usage of I suppose I could refactor that into a |
I updated my comment above to clarify that this only applies when using an existing rule, e.g. in a macro. When you write your own custom rule, you do have access to |
@fmeum, sorry I think I've forgotten a lot of the context here. I remember my original motivation was related to the change in dgp1130/rules_prerender@cc89f55, something about how Looking through my existing usages of Apologies for the noise. 😅 |
FWIW, repository_name() is the semantically accurate one. (Though bzlmod has changed some things about how useful this really is.) |
To get the workspace name of the call site, we do
native.repository_name()
in a macro andctx.workspace_name()
in a rule. The latter is behaving differently in the main repository probably (returning the name, whereas the repository name can be empty).This is a confusing API and it needs to be cleaned.
The text was updated successfully, but these errors were encountered: