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

use transition to resolve correct tar in oci_load #762

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion oci/private/load.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,19 @@ attrs = {
"_tarball_sh": attr.label(allow_single_file = True, default = "//oci/private:tarball.sh.tpl"),
"_runfiles": attr.label(default = "@bazel_tools//tools/bash/runfiles"),
"_windows_constraint": attr.label(default = "@platforms//os:windows"),
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
"_tar": attr.label(
cfg = util.transition_to_target,
default = "@bsd_tar_toolchains//:resolved_toolchain",
),
}

def _load_impl(ctx):
jq = ctx.toolchains["@aspect_bazel_lib//lib:jq_toolchain_type"]
coreutils = ctx.toolchains["@aspect_bazel_lib//lib:coreutils_toolchain_type"]
bsdtar = ctx.toolchains["@aspect_bazel_lib//lib:tar_toolchain_type"]
bsdtar = ctx.attr._tar[0][platform_common.ToolchainInfo]

image = ctx.file.image
repo_tags = ctx.file.repo_tags
Expand Down
21 changes: 2 additions & 19 deletions oci/private/push.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,6 @@ multirun(
[rules_multirun]: https://github.com/keith/rules_multirun
"""

# Helper rule for ensuring that the crane and yq toolchains are actually
# resolved for the architecture we are targeting.
def _transition_to_target_impl(settings, _attr):
return {
# String conversion is needed to prevent a crash with Bazel 6.x.
"//command_line_option:extra_execution_platforms": [
str(platform)
for platform in settings["//command_line_option:platforms"]
],
}

_transition_to_target = transition(
implementation = _transition_to_target_impl,
inputs = ["//command_line_option:platforms"],
outputs = ["//command_line_option:extra_execution_platforms"],
)

_attrs = {
"image": attr.label(
allow_single_file = True,
Expand Down Expand Up @@ -184,7 +167,7 @@ _attrs = {
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
"_crane": attr.label(
cfg = _transition_to_target,
cfg = util.transition_to_target,
default = "@oci_crane_toolchains//:current_toolchain",
),
"_push_sh_tpl": attr.label(
Expand All @@ -193,7 +176,7 @@ _attrs = {
),
"_windows_constraint": attr.label(default = "@platforms//os:windows"),
"_jq": attr.label(
cfg = _transition_to_target,
cfg = util.transition_to_target,
default = "@jq_toolchains//:resolved_toolchain",
),
}
Expand Down
18 changes: 18 additions & 0 deletions oci/private/util.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,23 @@ def _platform_triplet(platform_str):
architecture, _, variant = architecture.partition("/")
return os, architecture, variant

# Helper rule for ensuring that the crane and yq toolchains are actually
# resolved for the architecture we are targeting.
def _transition_to_target_impl(settings, _attr):
return {
# String conversion is needed to prevent a crash with Bazel 6.x.
"//command_line_option:extra_execution_platforms": [
str(platform)
for platform in settings["//command_line_option:platforms"]
],
}

_transition_to_target = transition(
implementation = _transition_to_target_impl,
inputs = ["//command_line_option:platforms"],
outputs = ["//command_line_option:extra_execution_platforms"],
)

util = struct(
parse_image = _parse_image,
sha256 = _sha256,
Expand All @@ -234,4 +251,5 @@ util = struct(
build_manifest_json = _build_manifest_json,
assert_crane_version_at_least = _assert_crane_version_at_least,
platform_triplet = _platform_triplet,
transition_to_target = _transition_to_target,
)