Skip to content

Commit

Permalink
Fix annotations_test on windows systems that don't support symlinks (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre authored Mar 20, 2022
1 parent e18e1a3 commit ce2911b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
11 changes: 8 additions & 3 deletions python/pip_install/extract_wheels/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ package_annotations_file(
],
),
"pkg_c": package_annotation(
additive_build_content = """\
# The `join` and `strip` here accounts for potential differences
# in new lines between unix and windows hosts.
additive_build_content = "\n".join([line.strip() for line in """\
cc_library(
name = "my_target",
hdrs = glob(["**/*.h"]),
srcs = glob(["**/*.cc"]),
)
""",
""".splitlines()]),
data = [":my_target"],
),
"pkg_d": package_annotation(
Expand All @@ -57,7 +59,10 @@ py_test(
data = [":mock_annotations"],
env = {"MOCK_ANNOTATIONS": "$(rootpath :mock_annotations)"},
tags = ["unit"],
deps = [":lib"],
deps = [
":lib",
"//python/runfiles",
],
)

py_test(
Expand Down
17 changes: 14 additions & 3 deletions python/pip_install/extract_wheels/lib/annotations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pathlib import Path

from python.pip_install.extract_wheels.lib.annotation import Annotation, AnnotationsMap
from python.runfiles import runfiles


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

annotations_path = Path.cwd() / annotations_env
r = runfiles.Create()

annotations_path = Path(r.Rlocation("rules_python/{}".format(annotations_env)))
self.assertTrue(annotations_path.exists())

annotations_map = AnnotationsMap(annotations_path)
Expand Down Expand Up @@ -59,14 +62,22 @@ def test_annotations_constructor(self) -> None:
collection["pkg_c"],
Annotation(
{
"additive_build_content": textwrap.dedent(
"""\
# The `join` and `strip` here accounts for potential
# differences in new lines between unix and windows
# hosts.
"additive_build_content": "\n".join(
[
line.strip()
for line in textwrap.dedent(
"""\
cc_library(
name = "my_target",
hdrs = glob(["**/*.h"]),
srcs = glob(["**/*.cc"]),
)
"""
).splitlines()
]
),
"copy_executables": {},
"copy_files": {},
Expand Down

0 comments on commit ce2911b

Please sign in to comment.