Automated rollback of commit 1c930292e79d22107a946aafea210b09806bde43. *** Reason for rollback *** Bazel thinks about character encoding is that it parses all of its input as ISO 8859-1 and emits all of its output as ISO 8859-1. This is, of course, broken, but in practice, it works reasonably well because UTF-8 survives being parsed and then re-encoded as ISO 8859-1 intact. It looks like https://github.com/bazelbuild/bazel/pull/15846 breaks that invariant. For example, if the byte 0xd6 ("ö" in ISO 8859-1) is on the input, it would be emitted as 0xc3 0xb6 in the runfiles manifest. Equivalently, if the input is 0xc3 0xb6 ("ö" in UTF-8) is on the input, it would mean "ö" in ISO 8859-1, and would therefore be emitted as 0xc3 0x83 0xc2 0xb6 in UTF-8. *** Original change description *** Fix bugs with unicode filenames in runfiles. We had a cc_test using a bunch of files (`data = glob(["data/**"]),`), some which were in subdirectories where the directory name had unicode characters (e.g. `data/test_öΩ/`). This resulted in an error: ``` ERROR: C:/users/.../BUILD.bazel:233:8: Creating runfiles tree bazel-out/x64_windows-opt/test-shared.exe.runfiles failed: build-runfiles.exe failed: error executing command cd /d C:\user... *** RELNOTES:none PiperOrigin-RevId: 511428267 Change-Id: If35c7aa62237e3ed3f45575f949d977981f1a833
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/SourceManifestAction.java b/src/main/java/com/google/devtools/build/lib/analysis/SourceManifestAction.java index e91419e..6feb2b9 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/SourceManifestAction.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/SourceManifestAction.java
@@ -14,6 +14,7 @@ package com.google.devtools.build.lib.analysis; import static com.google.common.collect.ImmutableList.toImmutableList; +import static java.nio.charset.StandardCharsets.ISO_8859_1; import static java.nio.charset.StandardCharsets.UTF_8; import com.google.common.annotations.VisibleForTesting; @@ -224,7 +225,7 @@ * @throws IOException */ private void writeFile(OutputStream out, Map<PathFragment, Artifact> output) throws IOException { - Writer manifestFile = new BufferedWriter(new OutputStreamWriter(out, UTF_8)); + Writer manifestFile = new BufferedWriter(new OutputStreamWriter(out, ISO_8859_1)); List<Map.Entry<PathFragment, Artifact>> sortedManifest = new ArrayList<>(output.entrySet()); sortedManifest.sort(ENTRY_COMPARATOR); for (Map.Entry<PathFragment, Artifact> line : sortedManifest) {
diff --git a/src/main/tools/build-runfiles-windows.cc b/src/main/tools/build-runfiles-windows.cc index da39672..0a0b0ab 100644 --- a/src/main/tools/build-runfiles-windows.cc +++ b/src/main/tools/build-runfiles-windows.cc
@@ -164,8 +164,8 @@ continue; } + size_t space_pos = line.find_first_of(' '); wstring wline = blaze_util::CstringToWstring(line); - size_t space_pos = wline.find_first_of(' '); wstring link, target; if (space_pos == string::npos) { link = wline;