Skip to content

Commit 0777602

Browse files
committed
partially fix tests
1 parent cbc8774 commit 0777602

File tree

5 files changed

+36
-18
lines changed

5 files changed

+36
-18
lines changed

tests/cc/current_py_cc_headers/current_py_cc_headers_tests.bzl

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,40 @@ def _test_current_toolchain_headers(name):
3131
"//command_line_option:extra_toolchains": [CC_TOOLCHAIN],
3232
},
3333
attrs = {
34-
"header": attr.label(
35-
default = "//tests/support/cc_toolchains:fake_header.h",
36-
allow_single_file = True,
34+
"header_files": attr.label_list(
35+
default = [
36+
"//tests/support/cc_toolchains:py_header_files",
37+
],
38+
allow_files = True,
3739
),
3840
},
3941
)
4042

4143
def _test_current_toolchain_headers_impl(env, target):
44+
print(env.ctx.files.header_files)
45+
4246
# Check that the forwarded CcInfo looks vaguely correct.
4347
compilation_context = env.expect.that_target(target).provider(
4448
CcInfo,
4549
factory = cc_info_subject,
4650
).compilation_context()
47-
compilation_context.direct_headers().contains_exactly([
48-
env.ctx.file.header,
49-
])
50-
compilation_context.direct_public_headers().contains_exactly([
51-
env.ctx.file.header,
52-
])
51+
compilation_context.direct_headers().contains_exactly(
52+
env.ctx.files.header_files,
53+
)
54+
compilation_context.direct_public_headers().contains_exactly(
55+
env.ctx.files.header_files,
56+
)
57+
58+
# NOTE: Bazel 8 and lower put cc_library.includes into `.system_includes`,
59+
# while Bazel 9 put it in `.includes`. Both result in the includes being
60+
# added as system includes, so either is acceptable for the expected
61+
# `#include <Python.h>` to work.
62+
includes = compilation_context.actual.includes.to_list() + compilation_context.actual.system_includes.to_list()
5363

5464
# NOTE: The include dir gets added twice, once for the source path,
5565
# and once for the config-specific path.
56-
compilation_context.system_includes().contains_at_least_predicates([
57-
matching.str_matches("*/fake_include"),
66+
env.expect.that_collection(includes).contains_at_least_predicates([
67+
matching.str_matches("*/py_include"),
5868
])
5969

6070
# Check that the forward DefaultInfo looks correct

tests/support/cc_info_subject.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def _compilation_context_subject_new(info, *, meta):
8181

8282
# buildifier: disable=uninitialized
8383
public = struct(
84+
actual = info,
8485
# go/keep-sorted start
8586
direct_headers = lambda *a, **k: _compilation_context_subject_direct_headers(self, *a, **k),
8687
direct_public_headers = lambda *a, **k: _compilation_context_subject_direct_public_headers(self, *a, **k),
@@ -156,6 +157,7 @@ def _linking_context_subject_new(info, meta):
156157

157158
# buildifier: disable=uninitialized
158159
public = struct(
160+
actual = info,
159161
# go/keep-sorted start
160162
linker_inputs = lambda *a, **k: _linking_context_subject_linker_inputs(self, *a, **k),
161163
# go/keep-sorted end

tests/support/cc_toolchains/BUILD.bazel

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
load("@rules_cc//cc:cc_library.bzl", "cc_library")
1516
load("@rules_cc//cc/toolchains:cc_toolchain.bzl", "cc_toolchain")
1617
load("@rules_cc//cc/toolchains:cc_toolchain_suite.bzl", "cc_toolchain_suite")
1718
load("@rules_testing//lib:util.bzl", "PREVENT_IMPLICIT_BUILDING_TAGS")
@@ -20,7 +21,14 @@ load(":fake_cc_toolchain_config.bzl", "fake_cc_toolchain_config")
2021

2122
package(default_visibility = ["//:__subpackages__"])
2223

23-
exports_files(["fake_header.h"])
24+
# Factored out for testing
25+
filegroup(
26+
name = "py_header_files",
27+
srcs = [
28+
"py_header.h",
29+
"py_include/py_header.h",
30+
],
31+
)
2432

2533
filegroup(
2634
name = "libpython",
@@ -37,22 +45,20 @@ toolchain(
3745

3846
py_cc_toolchain(
3947
name = "fake_py_cc_toolchain_impl",
40-
headers = ":fake_headers",
48+
headers = ":py_headers",
4149
libs = ":fake_libs",
4250
python_version = "3.999",
4351
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
4452
)
4553

46-
# buildifier: disable=native-cc
4754
cc_library(
48-
name = "fake_headers",
49-
hdrs = ["fake_header.h"],
55+
name = "py_headers",
56+
hdrs = [":py_header_files"],
5057
data = ["data.txt"],
51-
includes = ["fake_include"],
58+
includes = ["py_include"],
5259
tags = PREVENT_IMPLICIT_BUILDING_TAGS,
5360
)
5461

55-
# buildifier: disable=native-cc
5662
cc_library(
5763
name = "fake_libs",
5864
srcs = ["libpython3.so"],

tests/support/cc_toolchains/py_header.h

Whitespace-only changes.

tests/support/cc_toolchains/py_include/py_include.h

Whitespace-only changes.

0 commit comments

Comments
 (0)