mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 09:41:05 +01:00
Specifically this should improve linking by producing one large binary instead of one-per-directory. The inclusion of the driver hits the size issue. Separating out things which have more llvm deps has been discussed, but I'm not doing that here because I think the semantics layer will need to depend on clang for interop, and we'd lose a lot of the benefits that way. Also, having just one place to look seems simpler. Includes supporting changes to file_test infrastructure, the most significant of which is probably passing tests via file instead of a really large args thing, using a custom rule to do that. That's because dealing with the layered filegroups that allow the toolchain setup is more complicated, and this approach scales well. Combined test time is ~9s, so not sharding right now. I wasn't sure if people would prefer having the autoupdate script under testing, so I left it alone for now.
69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
# Exceptions. See /LICENSE for license information.
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
"""Rules for building file tests.
|
|
|
|
file_test uses the tests_as_input_file rule to transform test dependencies into
|
|
a file which can be accessed as a list. This avoids long argument parsing.
|
|
"""
|
|
|
|
load("@rules_cc//cc:defs.bzl", "cc_test")
|
|
|
|
DataFilesInfo = provider(
|
|
"Data files for this target.",
|
|
fields = {
|
|
"data_files": "Data files for this target",
|
|
},
|
|
)
|
|
|
|
def _tests_as_input_file_rule_impl(ctx):
|
|
data_files = []
|
|
for tests in ctx.attr.data:
|
|
data_files.extend(
|
|
[f.path for f in tests[DefaultInfo].data_runfiles.files.to_list()],
|
|
)
|
|
data_files.extend(
|
|
[f.path for f in tests[DefaultInfo].files.to_list()],
|
|
)
|
|
ctx.actions.write(ctx.outputs.data_files, "\n".join(data_files) + "\n")
|
|
|
|
_tests_as_input_file_rule = rule(
|
|
attrs = {
|
|
"data": attr.label_list(allow_files = True),
|
|
},
|
|
outputs = {
|
|
"data_files": "%{name}.txt",
|
|
},
|
|
implementation = _tests_as_input_file_rule_impl,
|
|
)
|
|
|
|
def file_test(name, tests, data = [], args = [], **kwargs):
|
|
"""Generates tests using the file_test base.
|
|
|
|
There will be one main test using `name` that can be sharded, and includes
|
|
all files. Additionally, per-file tests will be generated as
|
|
`name.file_path`; these per-file tests will be manual.
|
|
|
|
Args:
|
|
name: The base name of the tests.
|
|
tests: The list of test files to use as data, typically a glob.
|
|
data: Passed to cc_test.
|
|
args: Passed to cc_test.
|
|
**kwargs: Passed to cc_test.
|
|
"""
|
|
|
|
# Ensure tests are always a filegroup for tests_as_input_file_rule.
|
|
tests_file = "{0}.tests".format(name)
|
|
_tests_as_input_file_rule(
|
|
name = tests_file,
|
|
data = tests,
|
|
testonly = 1,
|
|
)
|
|
cc_test(
|
|
name = name,
|
|
data = [tests_file] + tests + data,
|
|
args = ["--test_targets_file=$(rootpath :{0})".format(tests_file)] + args,
|
|
**kwargs
|
|
)
|