Skip to content

Commit

Permalink
Fix testmaingen inputs
Browse files Browse the repository at this point in the history
Summary:
`testmaingen` does not need to know about all source files of the package - only about `..._test.go` files.

The new 1.20 test runner blows up if it receives non-test files: D68591069

#build_rule_type[go_library,go_binary,go_unittest,go_test]

Reviewed By: podtserkovskiy

Differential Revision: D68638284

fbshipit-source-id: 438542acdc41618516d736c698a9a8c2346568ef
  • Loading branch information
echistyakov authored and facebook-github-bot committed Jan 27, 2025
1 parent 50a45b1 commit 2d98453
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
6 changes: 3 additions & 3 deletions go/go_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _gen_test_main(
pkg_name: str,
coverage_mode: [GoCoverageMode, None],
coverage_vars: dict[str, cmd_args],
srcs: cmd_args) -> Artifact:
test_go_files: cmd_args) -> Artifact:
"""
Generate a `main.go` which calls tests from the given sources.
"""
Expand All @@ -47,7 +47,7 @@ def _gen_test_main(
cmd.extend(["--cover-mode", coverage_mode.value])
for _, vars in coverage_vars.items():
cmd.append(vars)
cmd.append(srcs)
cmd.append(test_go_files)
ctx.actions.run(cmd_args(cmd), category = "go_test_main_gen")
return output

Expand Down Expand Up @@ -109,7 +109,7 @@ def go_test_impl(ctx: AnalysisContext) -> list[Provider]:

# Generate a main function which runs the tests and build that into another
# package.
gen_main = _gen_test_main(ctx, pkg_name, coverage_mode, coverage_vars, tests.srcs_list)
gen_main = _gen_test_main(ctx, pkg_name, coverage_mode, coverage_vars, tests.test_go_files)
main, _ = build_package(ctx, pkg_name + ".test", True, [gen_main], package_root = "", pkgs = pkgs, coverage_mode = coverage_mode, race = ctx.attrs._race, asan = ctx.attrs._asan, cgo_gen_dir_name = "cgo_gen_test_main")

# Link the above into a Go binary.
Expand Down
9 changes: 4 additions & 5 deletions go/package_builder.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def build_package(

go_list_out = go_list(ctx, pkg_name, srcs, package_root, build_tags, cgo_enabled, with_tests = tests, asan = asan)

srcs_list_argsfile = ctx.actions.declare_output(paths.basename(pkg_name) + "_srcs_list.go_package_argsfile")
test_go_files_argsfile = ctx.actions.declare_output(paths.basename(pkg_name) + "_test_go_files.go_package_argsfile")
coverage_vars_argsfile = ctx.actions.declare_output(paths.basename(pkg_name) + "_coverage_vars.go_package_argsfile")
dynamic_outputs = [out, out_shared, srcs_list_argsfile, coverage_vars_argsfile, cgo_gen_dir]
dynamic_outputs = [out, out_shared, test_go_files_argsfile, coverage_vars_argsfile, cgo_gen_dir]

all_pkgs = merge_pkgs([
pkgs,
Expand All @@ -67,8 +67,7 @@ def build_package(

all_test_go_files = go_list.test_go_files + go_list.x_test_go_files

src_list_for_argsfile = go_list.go_files + (all_test_go_files if tests else [])
ctx.actions.write(outputs[srcs_list_argsfile], cmd_args(src_list_for_argsfile, ""))
ctx.actions.write(outputs[test_go_files_argsfile], cmd_args((all_test_go_files if tests else []), ""))

go_files_to_cover = go_list.go_files + cgo_go_files + (all_test_go_files if tests else [])
covered_go_files, coverage_vars_out = _cover(ctx, pkg_name, go_files_to_cover, coverage_mode)
Expand Down Expand Up @@ -114,7 +113,7 @@ def build_package(
pkg = out,
pkg_shared = out_shared,
coverage_vars = cmd_args(coverage_vars_argsfile, format = "@{}"),
srcs_list = cmd_args(srcs_list_argsfile, format = "@{}", hidden = srcs),
test_go_files = cmd_args(test_go_files_argsfile, format = "@{}", hidden = srcs),
), GoPackageInfo(
build_out = out,
cgo_gen_dir = cgo_gen_dir,
Expand Down
2 changes: 1 addition & 1 deletion go/packages.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ GoPkg = record(
pkg = field(Artifact),
pkg_shared = field(Artifact),
coverage_vars = field(cmd_args),
srcs_list = field(cmd_args),
test_go_files = field(cmd_args),
)

GoStdlib = provider(
Expand Down

0 comments on commit 2d98453

Please sign in to comment.