Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

refactor: inline some rules_docker 'skylib' helpers #724

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
40 changes: 30 additions & 10 deletions k8s/object.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,42 @@ load(
_get_layers = "get_from_target",
_layer_tools = "tools",
)
load(
"@io_bazel_rules_docker//skylib:label.bzl",
_string_to_label = "string_to_label",
)
load(
"@io_bazel_rules_docker//skylib:path.bzl",
_get_runfile_path = "runfile",
)

# Note: could use https://docs.aspect.build/rules/aspect_bazel_lib/docs/paths#to_rlocation_path
# if we had a dependency on aspect_bazel_lib
def _get_runfile_path(ctx, f):
"""Return the runfiles relative path of f."""
if ctx.workspace_name:
return ctx.workspace_name + "/" + f.short_path
else:
return f.short_path

# Note: could use https://docs.aspect.build/rules/aspect_bazel_lib/docs/utils#to_label
# if we had a dependency on aspect_bazel_lib
def _string_to_label(label_list, string_list):
"""Return a mapping from label strings to the resolved label.

Args:
label_list: The list of labels
string_list: The list of strings

Returns:
A mapping from label strings to the resolved label.
"""
label_string_dict = dict()
for i in range(len(label_list)):
string = string_list[i]
label = label_list[i]
label_string_dict[string] = label
return label_string_dict

def _runfiles(ctx, f):
return "${RUNFILES}/%s" % _get_runfile_path(ctx, f)

def _deduplicate(iterable):
"""Performs a deduplication (similar to `list(set(...))`)

This is necessary because `set` is not available in Skylark.
This is necessary because `set` is not available in Starlark.
"""
return {k: None for k in iterable}.keys()

Expand Down Expand Up @@ -124,7 +144,7 @@ def _impl(ctx):
},
).to_json(),
)
all_inputs += [substitutions_file]
all_inputs.append(substitutions_file)

ctx.actions.expand_template(
template = ctx.file._template,
Expand Down