Skip to content

Commit 0fd34dc

Browse files
committed
add analysis test for PyCcToolchainInfo returned by py_cc_toolchain
1 parent dcc78b6 commit 0fd34dc

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

tests/cc/py_cc_toolchain/py_cc_toolchain_tests.bzl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def _test_py_cc_toolchain_impl(env, target):
4444
)
4545
toolchain.python_version().equals("3.999")
4646

47+
# ===== Verify headers info =====
4748
headers_providers = toolchain.headers().providers_map()
4849
headers_providers.keys().contains_exactly(["CcInfo", "DefaultInfo"])
4950

@@ -68,6 +69,32 @@ def _test_py_cc_toolchain_impl(env, target):
6869
matching.str_matches("*/cc_toolchains/data.txt"),
6970
)
7071

72+
# ===== Verify headers_abi3 info =====
73+
headers_abi3_providers = toolchain.headers_abi3().providers_map()
74+
headers_abi3_providers.keys().contains_exactly(["CcInfo", "DefaultInfo"])
75+
76+
cc_info = headers_abi3_providers.get("CcInfo", factory = cc_info_subject)
77+
78+
compilation_context = cc_info.compilation_context()
79+
compilation_context.direct_headers().contains_exactly([
80+
env.ctx.file.header,
81+
])
82+
compilation_context.direct_public_headers().contains_exactly([
83+
env.ctx.file.header,
84+
])
85+
86+
# NOTE: The include dir gets added twice, once for the source path,
87+
# and once for the config-specific path, but we don't care about that.
88+
compilation_context.system_includes().contains_at_least_predicates([
89+
matching.str_matches("*/fake_include"),
90+
])
91+
92+
default_info = headers_abi3_providers.get("DefaultInfo", factory = subjects.default_info)
93+
default_info.runfiles().contains_predicate(
94+
matching.str_matches("*/cc_toolchains/data.txt"),
95+
)
96+
97+
# ===== Verify libs info =====
7198
libs_providers = toolchain.libs().providers_map()
7299
libs_providers.keys().contains_exactly(["CcInfo", "DefaultInfo"])
73100

tests/support/py_cc_toolchain_info_subject.bzl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def _py_cc_toolchain_info_subject_new(info, *, meta):
1919
# buildifier: disable=uninitialized
2020
public = struct(
2121
headers = lambda *a, **k: _py_cc_toolchain_info_subject_headers(self, *a, **k),
22+
headers_abi3 = lambda *a, **k: _py_cc_toolchain_info_subject_headers_abi3(self, *a, **k),
2223
libs = lambda *a, **k: _py_cc_toolchain_info_subject_libs(self, *a, **k),
2324
python_version = lambda *a, **k: _py_cc_toolchain_info_subject_python_version(self, *a, **k),
2425
actual = info,
@@ -35,6 +36,15 @@ def _py_cc_toolchain_info_subject_headers(self):
3536
),
3637
)
3738

39+
def _py_cc_toolchain_info_subject_headers_abi3(self):
40+
return subjects.struct(
41+
self.actual.headers_abi3,
42+
meta = self.meta.derive("headers_abi3()"),
43+
attrs = dict(
44+
providers_map = subjects.dict,
45+
),
46+
)
47+
3848
def _py_cc_toolchain_info_subject_libs(self):
3949
return subjects.struct(
4050
self.actual.libs,

0 commit comments

Comments
 (0)