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

fix: avoid using deprecated ctx.resolve_tools #459

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 8 additions & 21 deletions internal/native_image/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -37,41 +37,28 @@ def _build_action_message(ctx):
return (_mode_label[ctx.attr.optimization_mode or "default"])

def _graal_binary_implementation(ctx):
graal_attr = ctx.attr.native_image_tool
extra_tool_deps = []
gvm_toolchain = None
graal_attr = ctx.executable.native_image_tool

classpath_depset = depset(transitive = [
dep[JavaInfo].transitive_runtime_jars
for dep in ctx.attr.deps
])

graal = None
direct_inputs = []
transitive_inputs = [classpath_depset]

# resolve via toolchains
info = ctx.toolchains[_GVM_TOOLCHAIN_TYPE].graalvm

# 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)
gvm_toolchain = ctx.toolchains[_GVM_TOOLCHAIN_TYPE].graalvm

graal_inputs, _ = ctx.resolve_tools(tools = [
resolved_graal,
] + extra_tool_deps)

graal = graal_inputs.to_list()[0]
# if a native-image tool is explicitly provided, it should override the one
# provided by the toolchain, but not the rest of the files it provides
graal = graal_attr or gvm_toolchain.native_image_bin.files_to_run

# add toolchain files to transitive inputs
transitive_inputs.append(gvm_toolchain.gvm_files[DefaultInfo].files)

# if we're using an explicit tool, add it to the direct inputs
if graal:
direct_inputs.append(graal)
else:
# still failed to resolve: cannot resolve via either toolchains or attributes.
if not graal:
# cannot resolve via either toolchains or attributes.
fail("""
No `native-image` tool found. Please either define a `native_image_tool` in your target,
or install a GraalVM `native-image` toolchain.
Expand Down
Loading