Skip to content

Commit

Permalink
Try fixing windows
Browse files Browse the repository at this point in the history
  • Loading branch information
illicitonion committed Apr 11, 2022
1 parent 0b89c43 commit 46bceeb
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
2 changes: 2 additions & 0 deletions go/private/rules/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ bzl_library(
"//go/private:mode",
"//go/private:providers",
"//go/private/rules:transition",
"//go/private/skylib/lib:copy_file",
],
)

Expand Down Expand Up @@ -117,6 +118,7 @@ bzl_library(
"//go/private:providers",
"//go/private/rules:binary",
"//go/private/rules:transition",
"//go/private/skylib/lib:copy_file",
"@bazel_skylib//lib:structs",
],
)
Expand Down
19 changes: 13 additions & 6 deletions go/private/rules/binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ load(
"go_transition",
"transition_attrs",
)
load(
"//go/private/skylib/lib:copy_file.bzl",
"copy_bash",
"copy_cmd",
)
load(
"//go/private:mode.bzl",
"LINKMODE_C_ARCHIVE",
Expand Down Expand Up @@ -393,11 +398,10 @@ def _forward_binary_output(ctx):
di = ctx.attr.transition_dep[0][DefaultInfo]

copied_executable = ctx.actions.declare_file(ctx.label.name)
ctx.actions.symlink(
output = copied_executable,
target_file = ep.executable,
is_executable = True,
)
if ctx.attr.is_windows:
copy_cmd(ctx, ep.executable, copied_executable)
else:
copy_bash(ctx, ep.executable, copied_executable)

data_runfiles = di.data_runfiles.merge(ctx.runfiles([copied_executable]))
default_runfiles = di.default_runfiles.merge(ctx.runfiles([copied_executable]))
Expand All @@ -411,7 +415,10 @@ def _forward_binary_output(ctx):

go_transition_binary = rule(
implementation = _forward_binary_output,
attrs = _merge(transition_attrs, {"transition_dep": attr.label(cfg = go_transition)}),
attrs = _merge(transition_attrs, {
"is_windows": attr.bool(),
"transition_dep": attr.label(cfg = go_transition),
}),
executable = True,
)

Expand Down
16 changes: 11 additions & 5 deletions go/private/rules/test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ load(
"go_transition",
"transition_attrs",
)
load(
"//go/private/skylib/lib:copy_file.bzl",
"copy_bash",
"copy_cmd",
)
load(
"//go/private:mode.bzl",
"LINKMODE_NORMAL",
Expand All @@ -65,11 +70,11 @@ def _forward_test_output(ctx):
di = ctx.attr.transition_dep[0][DefaultInfo]

copied_executable = ctx.actions.declare_file(ctx.label.name)
ctx.actions.symlink(
output = copied_executable,
target_file = ep.executable,
is_executable = True,
)

if ctx.attr.is_windows:
copy_cmd(ctx, ep.executable, copied_executable)
else:
copy_bash(ctx, ep.executable, copied_executable)

data_runfiles = di.data_runfiles.merge(ctx.runfiles([copied_executable]))
default_runfiles = di.default_runfiles.merge(ctx.runfiles([copied_executable]))
Expand All @@ -85,6 +90,7 @@ go_transition_test = rule(
implementation = _forward_test_output,
attrs = _merge(transition_attrs, {
"transition_dep": attr.label(cfg = go_transition),
"is_windows": attr.bool(),
# Workaround for bazelbuild/bazel#6293. See comment in lcov_merger.sh.
"_lcov_merger": attr.label(
executable = True,
Expand Down
9 changes: 8 additions & 1 deletion go/private/rules/transition.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,14 @@ def go_transition_wrapper(kind, transition_kind, name, use_basename, keys_to_str
# but preserve things like tags and exec_compatible_with,
# which are general to all tests rather than specific to go_test specifically,
# and should apply to generated tests and binaries too.
transition_kind(name = name, transition_dep = transitioned_name, **_minus_keys(kwargs, keys_to_strip))
transition_kwargs = _minus_keys(kwargs, keys_to_strip)
transition_kwargs["name"] = name
transition_kwargs["transition_dep"] = transitioned_name
transition_kwargs["is_windows"] = select({
"@bazel_tools//src/conditions:windows": True,
"//conditions:default": False,
})
transition_kind(**transition_kwargs)
tags = kwargs.pop("tags", [])
if "manual" not in tags:
tags += ["manual"]
Expand Down
6 changes: 6 additions & 0 deletions go/private/skylib/lib/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ bzl_library(
srcs = ["versions.bzl"],
visibility = ["//go:__subpackages__"],
)

bzl_library(
name = "copy_file",
srcs = ["copy_file.bzl"],
visibility = ["//go:__subpackages__"],
)

0 comments on commit 46bceeb

Please sign in to comment.