-
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
load() doesn't work inside function #1550
Comments
This is WAI. Bazel needs to knows the dependencies before analysis. This could be lifted a little but with a lot of engineering. Unless we have a strong use case for it, it is not going to be implemented. Closing but feel free to argue :) |
Do we have a way to make this less cumbersome yet? Skydoc has a similar problem since it depends on git_repository(
name = "io_bazel_rules_sass",
remote = "https://github.com/bazelbuild/rules_sass.git",
tag = "0.0.1",
)
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_repositories")
sass_repositories()
git_repository(
name = "io_bazel_skydoc",
remote = "https://github.com/bazelbuild/skydoc.git",
tag = "0.0.3",
)
load("@io_bazel_skydoc//skylark:skylark.bzl", "skydoc_repositories")
skydoc_repositories() |
Why can't you put the sass repository in the skydoc_repositories macro? If that's because you are loading them from skylark:skylark.bzl maybe splitting it up is the correct answer. |
I can move the
|
It's a really complex issue, making load available from macro make cycle inside a macro possible:
Then calling macro would require foo to be defined because of the load statement, However this whole statement is evaluated inside the same sky function. There is probably a solution to this but it would make the code really complex and take a long time to make right. |
Please help me understand why that's a cycle, because I'm very curious about why this issue is so complicated. Please keep in mind I know very little about the Bazel core. I would have assumed that Skylark does evaluation of the WORKSPACE file in a single pass evaluator, where the WORKSPACE file AST is treated like it's the body of a function def. Therefore it would stand to reason that the things which can be done in the WORKSPACE file can also be done when the evaluator recurses into the function defs it loads. But it sounds like there might be a separate evaluator that happens in multiple passes. |
This feature would really aid our build. The pubref
However creating a transitive block for a single top level dependency requires a load and a function call. For this reason I have had to resort to a single uber dependency declaration for our codebase -- the transitive block for this contains 250 jars. The alternative is to have a workspace files with dozens of declarations as above which would need to be copy pasted if we modularise the build. Now dependencies like Spring Boot (unfortunately we have a SB app in our stack), Hibernate, Jersey etc are a royal pain to curate manually. Similar cases exist with building go codebases -- unless the vendored approach is used and external dependencies in this case aren't managed by bazel. Perhaps this particular use-case will be solved by transitive workspaces. However, I think For huge codebases that aren't using code generation to manage parts of the build logic, load from macros is a very powerful abstraction. It ensures the workspace file can be properly modularised. |
The original issue by @jart is well-stated. I thinks that as good as the use case gets:
#1943 (if anything) will likely be the solution. |
This could be useful for projects that use gRPC as an external repository. This could not be done within the same grpc_deps.bzl due to the problem discussed in - bazelbuild/bazel#1550 - bazelbuild/bazel#1943
It isn't possible to call load() within a macro bazelbuild/bazel#1550
It isn't possible to call load() within a macro bazelbuild/bazel#1550
If a WORKSPACE file calls a function containing
native.load()
then the imported symbol will not be available to the function namespace in subsequent statements.Further explanation
Bazel projects oftentimes specify a
foo_repositories()
function so dependent repositories can easily schlep in transitive dependencies. (Here's the convention used by Closure Rules.) But what if one of those dependencies is another Bazel project following the same convention?Assume I wanted to define the following:
Then I get the following error:
If I change
load
tonative.load
then I get a different error:The workaround is that all repositories providing a foo_repositories() function must be explicitly specified in the WORKSPACE file. This makes the external dependency convention that Closure Rules has adopted less useful.
The text was updated successfully, but these errors were encountered: