Skip to content

Commit

Permalink
oci_push to support Windows builds (#565)
Browse files Browse the repository at this point in the history
Co-authored-by: Bartosz Popiela <bartosz.popiela@bp.com>
Co-authored-by: Alex Eagle <alex@aspect.dev>
  • Loading branch information
3 people committed May 11, 2024
1 parent ad6ff89 commit 21c4897
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion oci/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,8 @@ bzl_library(
name = "util",
srcs = ["util.bzl"],
visibility = ["//oci:__subpackages__"],
deps = ["@bazel_skylib//lib:versions"],
deps = [
"@bazel_skylib//lib:paths",
"@bazel_skylib//lib:versions",
],
)
4 changes: 3 additions & 1 deletion oci/private/push.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ _attrs = {
default = "push.sh.tpl",
allow_single_file = True,
),
"_windows_constraint": attr.label(default = "@platforms//os:windows"),
}

def _quote_args(args):
Expand Down Expand Up @@ -178,14 +179,15 @@ def _impl(ctx):
runfiles = runfiles.merge(yq.default.default_runfiles)
runfiles = runfiles.merge(crane.default.default_runfiles)

return DefaultInfo(executable = executable, runfiles = runfiles)
return DefaultInfo(executable = util.maybe_wrap_launcher_for_windows(ctx, executable), runfiles = runfiles)

oci_push_lib = struct(
implementation = _impl,
attrs = _attrs,
toolchains = [
"@rules_oci//oci:crane_toolchain_type",
"@aspect_bazel_lib//lib:yq_toolchain_type",
"@bazel_tools//tools/sh:toolchain_type",
],
)

Expand Down
8 changes: 6 additions & 2 deletions oci/private/util.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Utilities"""

load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//lib:versions.bzl", "versions")

_IMAGE_PLATFORM_VARIANT_DEFAULTS = {
Expand Down Expand Up @@ -150,16 +152,18 @@ SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
for %%a in ("{bash_bin}") do set "bash_bin_dir=%%~dpa"
set PATH=%bash_bin_dir%;%PATH%
set "parent_dir=%~dp0"
set "parent_dir=!parent_dir:\=/!"
set args=%*
rem Escape \ and * in args before passing it with double quote
if defined args (
set args=!args:\=\\\\!
set args=!args:"=\"!
)
"{bash_bin}" -c "{launcher} !args!"
"{bash_bin}" -c "%parent_dir%{launcher} !args!"
""".format(
bash_bin = ctx.toolchains["@bazel_tools//tools/sh:toolchain_type"].path,
launcher = bash_launcher.path,
launcher = paths.relativize(bash_launcher.path, win_launcher.dirname),
),
is_executable = True,
)
Expand Down

0 comments on commit 21c4897

Please sign in to comment.