Skip to content

Commit 1d0bf7a

Browse files
committed
fix analysis tests
1 parent 32e51b9 commit 1d0bf7a

File tree

3 files changed

+63
-35
lines changed

3 files changed

+63
-35
lines changed

tests/cc/current_py_cc_headers/current_py_cc_headers_tests.bzl

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,7 @@ load("//tests/support:support.bzl", "CC_TOOLCHAIN")
2222

2323
_tests = []
2424

25-
def _test_current_toolchain_headers(name):
26-
analysis_test(
27-
name = name,
28-
impl = _test_current_toolchain_headers_impl,
29-
target = "//python/cc:current_py_cc_headers",
30-
config_settings = {
31-
"//command_line_option:extra_toolchains": [CC_TOOLCHAIN],
32-
},
33-
attrs = {
34-
"header_files": attr.label_list(
35-
default = [
36-
"//tests/support/cc_toolchains:py_header_files",
37-
],
38-
allow_files = True,
39-
),
40-
},
41-
)
42-
43-
def _test_current_toolchain_headers_impl(env, target):
25+
def _verify_headers_target(env, target):
4426
# Check that the forwarded CcInfo looks vaguely correct.
4527
compilation_context = env.expect.that_target(target).provider(
4628
CcInfo,
@@ -70,6 +52,27 @@ def _test_current_toolchain_headers_impl(env, target):
7052
matching.str_matches("*/cc_toolchains/data.txt"),
7153
)
7254

55+
def _test_current_toolchain_headers(name):
56+
analysis_test(
57+
name = name,
58+
impl = _test_current_toolchain_headers_impl,
59+
target = "//python/cc:current_py_cc_headers",
60+
config_settings = {
61+
"//command_line_option:extra_toolchains": [CC_TOOLCHAIN],
62+
},
63+
attrs = {
64+
"header_files": attr.label_list(
65+
default = [
66+
"//tests/support/cc_toolchains:py_headers_files",
67+
],
68+
allow_files = True,
69+
),
70+
},
71+
)
72+
73+
def _test_current_toolchain_headers_impl(env, target):
74+
_verify_headers_target(env, target)
75+
7376
_tests.append(_test_current_toolchain_headers)
7477

7578
def _test_toolchain_is_registered_by_default(name):
@@ -87,19 +90,24 @@ _tests.append(_test_toolchain_is_registered_by_default)
8790
def _test_current_toolchain_headers_abi3(name):
8891
analysis_test(
8992
name = name,
90-
impl = _test_current_toolchain_headers_impl,
93+
impl = _test_current_toolchain_headers_abi3_impl,
9194
target = "//python/cc:current_py_cc_headers_abi3",
9295
config_settings = {
9396
"//command_line_option:extra_toolchains": [CC_TOOLCHAIN],
9497
},
9598
attrs = {
96-
"header": attr.label(
97-
default = "//tests/support/cc_toolchains:fake_header.h",
98-
allow_single_file = True,
99+
"header_files": attr.label_list(
100+
default = [
101+
"//tests/support/cc_toolchains:py_headers_abi3_files",
102+
],
103+
allow_files = True,
99104
),
100105
},
101106
)
102107

108+
def _test_current_toolchain_headers_abi3_impl(env, target):
109+
_verify_headers_target(env, target)
110+
103111
_tests.append(_test_current_toolchain_headers_abi3)
104112

105113
def current_py_cc_headers_test_suite(name):

tests/cc/py_cc_toolchain/py_cc_toolchain_tests.bzl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ def _test_py_cc_toolchain(name):
2828
impl = _test_py_cc_toolchain_impl,
2929
target = "//tests/support/cc_toolchains:fake_py_cc_toolchain_impl",
3030
attrs = {
31+
"header_abi3_files": attr.label_list(
32+
default = ["//tests/support/cc_toolchains:py_headers_abi3_files"],
33+
allow_files = True,
34+
),
3135
"header_files": attr.label_list(
32-
default = ["//tests/support/cc_toolchains:py_header_files"],
36+
default = ["//tests/support/cc_toolchains:py_headers_files"],
3337
allow_files = True,
3438
),
3539
},
@@ -76,17 +80,17 @@ def _test_py_cc_toolchain_impl(env, target):
7680
cc_info = headers_abi3_providers.get("CcInfo", factory = cc_info_subject)
7781

7882
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-
])
83+
compilation_context.direct_headers().contains_exactly(
84+
env.ctx.files.header_abi3_files,
85+
)
86+
compilation_context.direct_public_headers().contains_exactly(
87+
env.ctx.files.header_abi3_files,
88+
)
8589

8690
# NOTE: The include dir gets added twice, once for the source path,
8791
# and once for the config-specific path, but we don't care about that.
8892
compilation_context.system_includes().contains_at_least_predicates([
89-
matching.str_matches("*/fake_include"),
93+
matching.str_matches("*/py_include"),
9094
])
9195

9296
default_info = headers_abi3_providers.get("DefaultInfo", factory = subjects.default_info)

tests/support/cc_toolchains/BUILD.bazel

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,18 @@ package(default_visibility = ["//:__subpackages__"])
2323

2424
# Factored out for testing
2525
filegroup(
26-
name = "py_header_files",
26+
name = "py_headers_files",
2727
srcs = [
2828
"py_header.h",
29+
":py_headers_abi3_files",
30+
],
31+
)
32+
33+
# Factored out for testing
34+
filegroup(
35+
name = "py_headers_abi3_files",
36+
srcs = [
37+
"py_abi3_header.h",
2938
"py_include/py_include.h",
3039
],
3140
)
@@ -46,20 +55,27 @@ toolchain(
4655
py_cc_toolchain(
4756
name = "fake_py_cc_toolchain_impl",
4857
headers = ":py_headers",
49-
headers_abi3 = ":py_headers",
58+
headers_abi3 = ":py_headers_abi3",
5059
libs = ":fake_libs",
5160
python_version = "3.999",
5261
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
5362
)
5463

5564
cc_library(
56-
name = "py_headers",
57-
hdrs = [":py_header_files"],
65+
name = "py_headers_abi3",
66+
hdrs = [":py_headers_abi3_files"],
5867
data = ["data.txt"],
5968
includes = ["py_include"],
6069
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
6170
)
6271

72+
cc_library(
73+
name = "py_headers",
74+
hdrs = [":py_headers_files"],
75+
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
76+
deps = [":py_headers_abi3"],
77+
)
78+
6379
cc_library(
6480
name = "fake_libs",
6581
srcs = ["libpython3.so"],

0 commit comments

Comments
 (0)