diff --git a/build_defs/go.build_defs b/build_defs/go.build_defs index bc9c73df..0c8f8af7 100644 --- a/build_defs/go.build_defs +++ b/build_defs/go.build_defs @@ -613,7 +613,7 @@ def go_test(name:str, srcs:list, resources:list=None, data:list|dict=None, deps: ) cmds, tools = _go_binary_cmds(static=static, definitions=definitions, gcov=cgo) - test_cmd = f'$TEST {flags} 2>&1 | tee $TMP_DIR/test.results' + test_cmd = f'$TEST {flags} 2>&1 | $TOOLS_JUNIT_REPORT | tee $RESULTS_FILE' worker_cmd = f'$(worker {worker})' if worker else "" if worker_cmd: test_cmd = f'{worker_cmd} && {test_cmd} ' @@ -646,6 +646,9 @@ def go_test(name:str, srcs:list, resources:list=None, data:list|dict=None, deps: debug_tools = debug_tools, cmd = cmds, test_cmd = test_cmd, + test_tools = { + "junit_report": "//third_party/go:junit_report", + }, debug_cmd = debug_cmd, visibility = visibility, test_sandbox = sandbox, @@ -912,7 +915,12 @@ def _go_install_module(name:str, module:str, install:list, src:str, outs:list, d ] if binary: - outs = [f'pkg/{CONFIG.OS}_{CONFIG.ARCH}/bin/{name}'] + # This decouples the name of the target from the name of the installed binary when it's unambiguous what the + # output binary should be. This is especially useful when installing a module like + # github.com/jstemmer/go-junit-report/v2 which results in a binary called v2 which isn't a very helpful name for + # a build target. + bin_name = basename(install[0]) if len(install) == 1 else name + outs = [f'pkg/{CONFIG.OS}_{CONFIG.ARCH}/bin/{bin_name}'] else: outs = [f'pkg/{CONFIG.OS}_{CONFIG.ARCH}/{out}' for out in _remove_redundant_outs(outs)] diff --git a/third_party/go/BUILD b/third_party/go/BUILD index b818b00f..e82a4ac6 100644 --- a/third_party/go/BUILD +++ b/third_party/go/BUILD @@ -45,6 +45,21 @@ go_module( visibility = ["PUBLIC"], ) +go_mod_download( + name = "junit_report_download", + module = "github.com/marcuscaisey/go-junit-report/v2", + version = "f9f65c7e2eb4a7e4a98b4cc8757772ae1092d211", +) + +go_module( + name = "junit_report", + binary = True, + download = ":junit_report_download", + licences = ["MIT"], + module = "github.com/jstemmer/go-junit-report/v2", + visibility = ["PUBLIC"], +) + go_module( name = "spew", install = ["spew"],