Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 626b03a

Browse filesBrowse files
authored
fix: Fix encoding of runfiles manifest and repository mapping files. (bazel-contrib#2568)
See bazelbuild/bazel#374 (comment): > all output files produced by Bazel should use UTF-8 and \n line endings on > all platforms, including Windows. Previously this would use the legacy ANSI codepage on Windows.
1 parent 188598a commit 626b03a
Copy full SHA for 626b03a

File tree

Expand file treeCollapse file tree

5 files changed

+17
-15
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+17
-15
lines changed

‎CHANGELOG.md

Copy file name to clipboardExpand all lines: CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ Unreleased changes template.
6363
* (gazelle) Providing multiple input requirements files to `gazelle_python_manifest` now works correctly.
6464
* (pypi) Handle trailing slashes in pip index URLs in environment variables,
6565
fixes [#2554](https://github.com/bazelbuild/rules_python/issues/2554).
66+
* (runfiles) Runfile manifest and repository mapping files are now interpreted
67+
as UTF-8 on all platforms.
6668

6769
{#v0-0-0-added}
6870
### Added

‎examples/bzlmod/runfiles/runfiles_test.py

Copy file name to clipboardExpand all lines: examples/bzlmod/runfiles/runfiles_test.py
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,36 @@ def testCurrentRepository(self):
2727

2828
def testRunfilesWithRepoMapping(self):
2929
data_path = runfiles.Create().Rlocation("example_bzlmod/runfiles/data/data.txt")
30-
with open(data_path) as f:
30+
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
3131
self.assertEqual(f.read().strip(), "Hello, example_bzlmod!")
3232

3333
def testRunfileWithRlocationpath(self):
3434
data_rlocationpath = os.getenv("DATA_RLOCATIONPATH")
3535
data_path = runfiles.Create().Rlocation(data_rlocationpath)
36-
with open(data_path) as f:
36+
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
3737
self.assertEqual(f.read().strip(), "Hello, example_bzlmod!")
3838

3939
def testRunfileInOtherModuleWithOurRepoMapping(self):
4040
data_path = runfiles.Create().Rlocation(
4141
"our_other_module/other_module/pkg/data/data.txt"
4242
)
43-
with open(data_path) as f:
43+
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
4444
self.assertEqual(f.read().strip(), "Hello, other_module!")
4545

4646
def testRunfileInOtherModuleWithItsRepoMapping(self):
4747
data_path = lib.GetRunfilePathWithRepoMapping()
48-
with open(data_path) as f:
48+
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
4949
self.assertEqual(f.read().strip(), "Hello, other_module!")
5050

5151
def testRunfileInOtherModuleWithCurrentRepository(self):
5252
data_path = lib.GetRunfilePathWithCurrentRepository()
53-
with open(data_path) as f:
53+
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
5454
self.assertEqual(f.read().strip(), "Hello, other_module!")
5555

5656
def testRunfileInOtherModuleWithRlocationpath(self):
5757
data_rlocationpath = os.getenv("OTHER_MODULE_DATA_RLOCATIONPATH")
5858
data_path = runfiles.Create().Rlocation(data_rlocationpath)
59-
with open(data_path) as f:
59+
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
6060
self.assertEqual(f.read().strip(), "Hello, other_module!")
6161

6262

‎examples/bzlmod_build_file_generation/runfiles/runfiles_test.py

Copy file name to clipboardExpand all lines: examples/bzlmod_build_file_generation/runfiles/runfiles_test.py
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,36 @@ def testRunfilesWithRepoMapping(self):
2929
data_path = runfiles.Create().Rlocation(
3030
"example_bzlmod_build_file_generation/runfiles/data/data.txt"
3131
)
32-
with open(data_path) as f:
32+
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
3333
self.assertEqual(f.read().strip(), "Hello, example_bzlmod!")
3434

3535
def testRunfileWithRlocationpath(self):
3636
data_rlocationpath = os.getenv("DATA_RLOCATIONPATH")
3737
data_path = runfiles.Create().Rlocation(data_rlocationpath)
38-
with open(data_path) as f:
38+
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
3939
self.assertEqual(f.read().strip(), "Hello, example_bzlmod!")
4040

4141
def testRunfileInOtherModuleWithOurRepoMapping(self):
4242
data_path = runfiles.Create().Rlocation(
4343
"our_other_module/other_module/pkg/data/data.txt"
4444
)
45-
with open(data_path) as f:
45+
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
4646
self.assertEqual(f.read().strip(), "Hello, other_module!")
4747

4848
def testRunfileInOtherModuleWithItsRepoMapping(self):
4949
data_path = lib.GetRunfilePathWithRepoMapping()
50-
with open(data_path) as f:
50+
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
5151
self.assertEqual(f.read().strip(), "Hello, other_module!")
5252

5353
def testRunfileInOtherModuleWithCurrentRepository(self):
5454
data_path = lib.GetRunfilePathWithCurrentRepository()
55-
with open(data_path) as f:
55+
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
5656
self.assertEqual(f.read().strip(), "Hello, other_module!")
5757

5858
def testRunfileInOtherModuleWithRlocationpath(self):
5959
data_rlocationpath = os.getenv("OTHER_MODULE_DATA_RLOCATIONPATH")
6060
data_path = runfiles.Create().Rlocation(data_rlocationpath)
61-
with open(data_path) as f:
61+
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
6262
self.assertEqual(f.read().strip(), "Hello, other_module!")
6363

6464

‎python/runfiles/runfiles.py

Copy file name to clipboardExpand all lines: python/runfiles/runfiles.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def RlocationChecked(self, path: str) -> Optional[str]:
5656
def _LoadRunfiles(path: str) -> Dict[str, str]:
5757
"""Loads the runfiles manifest."""
5858
result = {}
59-
with open(path, "r") as f:
59+
with open(path, "r", encoding="utf-8", newline="\n") as f:
6060
for line in f:
6161
line = line.rstrip("\n")
6262
if line.startswith(" "):
@@ -367,7 +367,7 @@ def _ParseRepoMapping(repo_mapping_path: Optional[str]) -> Dict[Tuple[str, str],
367367
if not repo_mapping_path:
368368
return {}
369369
try:
370-
with open(repo_mapping_path, "r") as f:
370+
with open(repo_mapping_path, "r", encoding="utf-8", newline="\n") as f:
371371
content = f.read()
372372
except FileNotFoundError:
373373
return {}

‎tests/runfiles/runfiles_test.py

Copy file name to clipboardExpand all lines: tests/runfiles/runfiles_test.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ def __init__(
552552
def __enter__(self) -> Any:
553553
tmpdir = os.environ.get("TEST_TMPDIR")
554554
self._path = os.path.join(tempfile.mkdtemp(dir=tmpdir), self._name)
555-
with open(self._path, "wt") as f:
555+
with open(self._path, "wt", encoding="utf-8", newline="\n") as f:
556556
f.writelines(l + "\n" for l in self._contents)
557557
return self
558558

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.