From a054a5a7ad0384b10c6a50248c78d420c0b67e66 Mon Sep 17 00:00:00 2001
From: Christian Sigg <csigg@google.com>
Date: Mon, 25 Jan 2021 08:53:44 -0800
Subject: [PATCH] Escape captured Windows' `where.exe` output.

This is in preparation of upgrading to bazel 4.0, which flipped `--incompatible_restrict_string_escapes`.

PiperOrigin-RevId: 353656022
Change-Id: Ide31ead6e968c94f3d6106a78ebc1b6b00746eab
---
 third_party/remote_config/common.bzl | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/third_party/remote_config/common.bzl b/third_party/remote_config/common.bzl
index d7e69326205..e12effb3449 100644
--- a/third_party/remote_config/common.bzl
+++ b/third_party/remote_config/common.bzl
@@ -24,10 +24,12 @@ def which(repository_ctx, program_name):
     if is_windows(repository_ctx):
         if not program_name.endswith(".exe"):
             program_name = program_name + ".exe"
-        result = execute(repository_ctx, ["C:\\Windows\\System32\\where.exe", program_name])
-    else:
-        result = execute(repository_ctx, ["which", program_name])
-    return result.stdout.rstrip()
+        return execute(
+            repository_ctx,
+            ["C:\\Windows\\System32\\where.exe", program_name],
+        ).stdout.replace("\\", "\\\\").rstrip()
+
+    return execute(repository_ctx, ["which", program_name]).stdout.rstrip()
 
 def get_python_bin(repository_ctx):
     """Gets the python bin path.