-
Notifications
You must be signed in to change notification settings - Fork 15
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
fix(native_image): clean up construction of inputs #70
Conversation
d41ec9f
to
94796f0
Compare
Stacked on #71 |
`depset` structures should be kept as flat as possible. C++ toolchain files are also already `depset`s and thus shouldn't be passed into `tools`. Signed-off-by: Sam Gammon <[email protected]>
#71 merged, rebased (and signed-off and signed) will examine expected build failure and hopefully solve so i can hand off to you |
- fix: explicitly check against modern rule status before resolving toolchain, unconditionally take it if running modern applies on top of #70 Signed-off-by: Sam Gammon <[email protected]>
- fix: explicitly check against modern rule status before resolving toolchain, unconditionally take it if running modern - fix: direct deps for `native_image_tool` attr - fix: preserve legacy rule behavior applies on top of #70 Signed-off-by: Sam Gammon <[email protected]>
- fix: explicitly check against modern rule status before resolving toolchain, unconditionally take it if running modern - fix: direct deps for `native_image_tool` attr - fix: preserve legacy rule behavior applies on top of sgammon#70 Signed-off-by: Sam Gammon <[email protected]>
@fmeum adjusted to avoid breakages with legacy rules (from a0c767a): diff --git a/internal/native_image/rules.bzl b/internal/native_image/rules.bzl
index c667cf1..03fa527 100644
--- a/internal/native_image/rules.bzl
+++ b/internal/native_image/rules.bzl
@@ -107,28 +107,39 @@ def _graal_binary_implementation(ctx):
direct_inputs = []
transitive_inputs = [classpath_depset]
- if graal_attr == None:
+ # if we aren't handed a specific `native-image` tool binary, or we are running
+ # under the modern `native_image` rule, then attempt to resolve via toolchains...
+ if graal_attr == None and not (ctx.attr._legacy_rule):
# resolve via toolchains
info = ctx.toolchains[_GVM_TOOLCHAIN_TYPE].graalvm
- graal_attr = info.native_image_bin
+
+ # but fall back to explicitly-provided tool, which should override, with the
+ # remainder of the resolved toolchain present
+ resolved_graal = graal_attr or info.native_image_bin
gvm_toolchain = info
extra_tool_deps.append(info.gvm_files)
graal_inputs, _ = ctx.resolve_tools(tools = [
- graal_attr,
+ resolved_graal,
] + extra_tool_deps)
graal = graal_inputs.to_list()[0]
+
+ # if we're using an explicit tool, add it to the direct inputs
+ if graal_attr:
+ direct_inputs.append(graal_inputs)
+
+ # add toolchain files to transitive inputs
transitive_inputs.append(gvm_toolchain.gvm_files[DefaultInfo].files)
- else:
- # otherwise, use the legacy code path
+ elif graal_attr != None:
+ # otherwise, use the legacy code path. the `graal` value is used in the run
+ # `executable` so it isn't listed in deps for earlier Bazel versions.
graal_inputs, _, _ = ctx.resolve_command(tools = [
graal_attr,
])
graal = graal_inputs[0]
- direct_inputs.append(graal_inputs)
-
- if graal_attr == None:
+ direct_inputs.append(graal)
+ else:
# still failed to resolve: cannot resolve via either toolchains or attributes.
fail("""
No `native-image` tool found. Please either define a `native_image_tool` in your target,
@@ -263,6 +274,7 @@ def _graal_binary_implementation(ctx):
args.add("-H:+JNI")
inputs = depset(direct_inputs, transitive = transitive_inputs)
+
run_params = {
"outputs": [binary],
"arguments": [args],
it was direct_inputs.append(graal_inputs) that was causing the classic rules to fail with
it seems to fix it to append only the file, like direct_inputs.append(graal) # graal is `graal_inputs[0]` and it shouldn't affect your use in bazelbuild/bazel#19361, since that code path is only used by the legacy rules. |
Kudos, SonarCloud Quality Gate passed! |
depset
structures should be kept as flat as possible. C++ toolchain files are also alreadydepset
s and thus shouldn't be passed intotools
.