Fix annotations_test on windows systems that don't support symlinks (#665)
diff --git a/python/pip_install/extract_wheels/lib/BUILD b/python/pip_install/extract_wheels/lib/BUILD index 49ed483..3e2f307 100644 --- a/python/pip_install/extract_wheels/lib/BUILD +++ b/python/pip_install/extract_wheels/lib/BUILD
@@ -34,13 +34,15 @@ ], ), "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( @@ -57,7 +59,10 @@ data = [":mock_annotations"], env = {"MOCK_ANNOTATIONS": "$(rootpath :mock_annotations)"}, tags = ["unit"], - deps = [":lib"], + deps = [ + ":lib", + "//python/runfiles", + ], ) py_test(
diff --git a/python/pip_install/extract_wheels/lib/annotations_test.py b/python/pip_install/extract_wheels/lib/annotations_test.py index 96573e1..94b92a1 100644 --- a/python/pip_install/extract_wheels/lib/annotations_test.py +++ b/python/pip_install/extract_wheels/lib/annotations_test.py
@@ -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): @@ -16,7 +17,9 @@ 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) @@ -59,14 +62,22 @@ 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": {},