Skip to content

Commit ce2911b

Browse files
authored
Fix annotations_test on windows systems that don't support symlinks (#665)
1 parent e18e1a3 commit ce2911b

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

python/pip_install/extract_wheels/lib/BUILD

+8-3
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ package_annotations_file(
3434
],
3535
),
3636
"pkg_c": package_annotation(
37-
additive_build_content = """\
37+
# The `join` and `strip` here accounts for potential differences
38+
# in new lines between unix and windows hosts.
39+
additive_build_content = "\n".join([line.strip() for line in """\
3840
cc_library(
3941
name = "my_target",
4042
hdrs = glob(["**/*.h"]),
4143
srcs = glob(["**/*.cc"]),
4244
)
43-
""",
45+
""".splitlines()]),
4446
data = [":my_target"],
4547
),
4648
"pkg_d": package_annotation(
@@ -57,7 +59,10 @@ py_test(
5759
data = [":mock_annotations"],
5860
env = {"MOCK_ANNOTATIONS": "$(rootpath :mock_annotations)"},
5961
tags = ["unit"],
60-
deps = [":lib"],
62+
deps = [
63+
":lib",
64+
"//python/runfiles",
65+
],
6166
)
6267

6368
py_test(

python/pip_install/extract_wheels/lib/annotations_test.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pathlib import Path
77

88
from python.pip_install.extract_wheels.lib.annotation import Annotation, AnnotationsMap
9+
from python.runfiles import runfiles
910

1011

1112
class AnnotationsTestCase(unittest.TestCase):
@@ -16,7 +17,9 @@ def test_annotations_constructor(self) -> None:
1617
annotations_env = os.environ.get("MOCK_ANNOTATIONS")
1718
self.assertIsNotNone(annotations_env)
1819

19-
annotations_path = Path.cwd() / annotations_env
20+
r = runfiles.Create()
21+
22+
annotations_path = Path(r.Rlocation("rules_python/{}".format(annotations_env)))
2023
self.assertTrue(annotations_path.exists())
2124

2225
annotations_map = AnnotationsMap(annotations_path)
@@ -59,14 +62,22 @@ def test_annotations_constructor(self) -> None:
5962
collection["pkg_c"],
6063
Annotation(
6164
{
62-
"additive_build_content": textwrap.dedent(
63-
"""\
65+
# The `join` and `strip` here accounts for potential
66+
# differences in new lines between unix and windows
67+
# hosts.
68+
"additive_build_content": "\n".join(
69+
[
70+
line.strip()
71+
for line in textwrap.dedent(
72+
"""\
6473
cc_library(
6574
name = "my_target",
6675
hdrs = glob(["**/*.h"]),
6776
srcs = glob(["**/*.cc"]),
6877
)
6978
"""
79+
).splitlines()
80+
]
7081
),
7182
"copy_executables": {},
7283
"copy_files": {},

0 commit comments

Comments
 (0)