Skip to content

Commit

Permalink
bazel: remove unused go_ld_test
Browse files Browse the repository at this point in the history
This was an attempt to make unit tests work where we linked against libraries and ld from Fedora.
This is no longer needed.
  • Loading branch information
malt3 committed Dec 1, 2023
1 parent 4ca88cd commit 432c429
Showing 1 changed file with 0 additions and 73 deletions.
73 changes: 0 additions & 73 deletions bazel/go/go_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -40,76 +40,3 @@ def go_test(ld = None, count = 3, **kwargs):
kwargs["gc_linkopts"] += ["-I", ld]

_go_test(**kwargs)

def _vars_script(env, ld, cmd):
ret = ["#!/bin/sh"]
for k, v in env.items():
ret.append('export {}="{}"'.format(k, v))
ret.append('exec {} {} "$@"'.format(ld, cmd))
return "\n".join(ret) + "\n"

def _ld_binary_impl(ctx):
source_info = ctx.attr.src[DefaultInfo]
ld_info = ctx.attr.ld[DefaultInfo]

executable = None
if source_info.files_to_run and source_info.files_to_run.executable:
command = _vars_script(ctx.attr.env, ld_info.files_to_run.executable.short_path, source_info.files_to_run.executable.short_path)
executable = ctx.actions.declare_file("{}_under_ld".format(ctx.file.src.basename))
ctx.actions.write(
output = executable,
content = command,
is_executable = True,
)

runfiles = ctx.runfiles(files = ctx.files.src)
runfiles = runfiles.merge(source_info.data_runfiles)
runfiles = runfiles.merge(ctx.runfiles(files = ctx.files.ld))
runfiles = runfiles.merge(ld_info.data_runfiles)
return [DefaultInfo(
executable = executable,
files = depset([executable]),
runfiles = runfiles,
)]

_attrs = {
"env": attr.string_dict(
doc = "Environment variables for the test",
),
"ld": attr.label(
executable = True,
cfg = "exec",
doc = "ld wrapper executable",
),
"src": attr.label(
allow_single_file = True,
mandatory = True,
doc = "Target to build.",
),
}

ld_test = rule(
implementation = _ld_binary_impl,
attrs = _attrs,
executable = True,
test = True,
)

def go_ld_test(**kwargs):
"""go_ld_test is a wrapper for go_test that uses the specified ld to run the test binary under.
Args:
**kwargs: all arguments are passed to go_test.
"""

# Sets test count to 3.
kwargs.setdefault("args", [])
kwargs["args"].append("--test.count=3")

# Disable test wrapper
kwargs.setdefault("env", {})
kwargs["env"]["GO_TEST_WRAP"] = "0"

ld_test(
**kwargs
)

0 comments on commit 432c429

Please sign in to comment.