@@ -20,7 +20,6 @@ docker run --rm my-repository:latest
2020"""
2121
2222load ("@aspect_bazel_lib//lib:paths.bzl" , "BASH_RLOCATION_FUNCTION" , "to_rlocation_path" )
23- load ("@aspect_bazel_lib//lib:windows_utils.bzl" , "BATCH_RLOCATION_FUNCTION" )
2423load ("//oci/private:util.bzl" , "util" )
2524
2625doc = """Loads an OCI layout into a container daemon without needing to publish the image first.
@@ -114,7 +113,7 @@ attrs = {
114113
115114 See the _run_template attribute for the script that calls this loader tool.
116115 """ ,
117- allow_files = True ,
116+ allow_single_file = True ,
118117 mandatory = False ,
119118 executable = True ,
120119 cfg = "target" ,
@@ -129,33 +128,15 @@ attrs = {
129128 """ ,
130129 allow_single_file = True ,
131130 ),
132- "_run_template_windows" : attr .label (
133- default = Label ("//oci/private:load.bat.tpl" ),
134- doc = """ \
135- The template used to load the container when using `bazel run` on this target.
136-
137- See the `loader` attribute to replace the tool which is called.
138- Please reference the default template to see available substitutions.
139- """ ,
140- allow_single_file = True ,
141- ),
142131 "_tarball_sh" : attr .label (allow_single_file = True , default = "//oci/private:tarball.sh.tpl" ),
143132 "_runfiles" : attr .label (default = "@bazel_tools//tools/bash/runfiles" ),
144133 "_windows_constraint" : attr .label (default = "@platforms//os:windows" ),
145134}
146135
147- def _windows_host (ctx ):
148- """Returns true if the host platform is windows.
149-
150- The typical approach using ctx.target_platform_has_constraint does not work for transitioned
151- build targets. We need to know the host platform, not the target platform.
152- """
153- return ctx .configuration .host_path_separator == ";"
154-
155136def _load_impl (ctx ):
156137 jq = ctx .toolchains ["@aspect_bazel_lib//lib:jq_toolchain_type" ]
157138 coreutils = ctx .toolchains ["@aspect_bazel_lib//lib:coreutils_toolchain_type" ]
158- bsdtar = ctx .toolchains ["@tar.bzl//tar/toolchain:type " ]
139+ bsdtar = ctx .toolchains ["@aspect_bazel_lib//lib:tar_toolchain_type " ]
159140
160141 image = ctx .file .image
161142 repo_tags = ctx .file .repo_tags
@@ -219,47 +200,29 @@ def _load_impl(ctx):
219200
220201 # Create an executable runner script that will create the tarball at runtime,
221202 # as opposed to at build to avoid uploading large artifacts to remote cache.
222- if not _windows_host (ctx ):
223- runnable_loader = ctx .actions .declare_file (ctx .label .name + ".sh" )
224- ctx .actions .expand_template (
225- template = ctx .file ._run_template ,
226- output = runnable_loader ,
227- substitutions = {
228- "{{BASH_RLOCATION_FUNCTION}}" : BASH_RLOCATION_FUNCTION ,
229- "{{tar}}" : to_rlocation_path (ctx , bsdtar .tarinfo .binary ),
230- "{{mtree_path}}" : to_rlocation_path (ctx , mtree_spec ),
231- "{{loader}}" : to_rlocation_path (ctx , ctx .executable .loader ) if ctx .executable .loader else "" ,
232- "{{manifest_root}}" : manifest_json .root .path ,
233- "{{image_root}}" : image .root .path ,
234- "{{workspace_name}}" : ctx .workspace_name ,
235- },
236- is_executable = True ,
237- )
238- else :
239- runnable_loader = ctx .actions .declare_file (ctx .label .name + ".bat" )
240- ctx .actions .expand_template (
241- template = ctx .file ._run_template_windows ,
242- output = runnable_loader ,
243- substitutions = {
244- "{{BATCH_RLOCATION_FUNCTION}}" : BATCH_RLOCATION_FUNCTION ,
245- "{{tar}}" : to_rlocation_path (ctx , bsdtar .tarinfo .binary ),
246- "{{mtree_path}}" : to_rlocation_path (ctx , mtree_spec ),
247- "{{loader}}" : to_rlocation_path (ctx , ctx .executable .loader ) if ctx .executable .loader else "" ,
248- "{{manifest_root}}" : manifest_json .root .path ,
249- "{{image_root}}" : image .root .path ,
250- "{{workspace_name}}" : ctx .workspace_name ,
251- },
252- is_executable = True ,
253- )
203+ runnable_loader = ctx .actions .declare_file (ctx .label .name + ".sh" )
254204
255205 runtime_deps = []
256- if ctx .executable .loader :
257- runtime_deps .append (ctx .executable .loader )
206+ if ctx .file .loader :
207+ runtime_deps .append (ctx .file .loader )
258208 runfiles = ctx .runfiles (runtime_deps , transitive_files = tar_inputs )
259209 runfiles = runfiles .merge (ctx .attr .image [DefaultInfo ].default_runfiles )
260210 runfiles = runfiles .merge (ctx .attr ._runfiles .default_runfiles )
261- if ctx .executable .loader :
262- runfiles = runfiles .merge (ctx .attr .loader .default_runfiles )
211+
212+ ctx .actions .expand_template (
213+ template = ctx .file ._run_template ,
214+ output = runnable_loader ,
215+ substitutions = {
216+ "{{BASH_RLOCATION_FUNCTION}}" : BASH_RLOCATION_FUNCTION ,
217+ "{{tar}}" : to_rlocation_path (ctx , bsdtar .tarinfo .binary ),
218+ "{{mtree_path}}" : to_rlocation_path (ctx , mtree_spec ),
219+ "{{loader}}" : to_rlocation_path (ctx , ctx .file .loader ) if ctx .file .loader else "" ,
220+ "{{manifest_root}}" : manifest_json .root .path ,
221+ "{{image_root}}" : image .root .path ,
222+ "{{workspace_name}}" : ctx .workspace_name ,
223+ },
224+ is_executable = True ,
225+ )
263226
264227 return [
265228 DefaultInfo (
@@ -277,7 +240,7 @@ oci_load = rule(
277240 "@bazel_tools//tools/sh:toolchain_type" ,
278241 "@aspect_bazel_lib//lib:coreutils_toolchain_type" ,
279242 "@aspect_bazel_lib//lib:jq_toolchain_type" ,
280- "@tar.bzl//tar/toolchain:type " ,
243+ "@aspect_bazel_lib//lib:tar_toolchain_type " ,
281244 ],
282245 executable = True ,
283246)
0 commit comments