Repository: bazelbuild/bazel
Issue: Windows: Bazel ostensibly requires Python for every command
Labels: type: bug
P3
area-Windows
team-OSS

### Description of the problem / feature request:

Bazel complains if it cannot find Python on that PATH, for every command. However, it also carries out the commands successfully.

### Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

On a fresh Windows 10:

1. download Bazel 0.18.0 
2. install the [MSVC redistributable DLLs](https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x64.exe)
3. in cmd.exe:
  ```
  C:\>md c:\src\foo

  C:\>cd c:\src\foo

  C:\src\foo>echo # hello>WORKSPACE

  C:\src\foo>md c:\src\foo\fake-msys\usr\bin

  C:\src\tmp>echo @exit /B 1 > c:\src\tmp\fake-msys\usr\bin\bash.bat

  C:\src\tmp>set BAZEL_SH=c:\src\tmp\fake-msys\usr\bin\bash.bat

  C:\src\tmp>bazel info release
  ERROR: python.exe not found on PATH
  release 0.18.0
  ```

### What operating system are you running Bazel on?

Windows Server 2016 (v1607)

Issue comments:
This is a bad first-time experience. See https://github.com/bazelbuild/bazel/issues/5254

Pull request review comments:

Patch that resolved the issue:
diff --git a/src/main/cpp/blaze_util_windows.cc b/src/main/cpp/blaze_util_windows.cc
index 3f3f8bfbb935e1..8d57784d3f8ff0 100644
--- a/src/main/cpp/blaze_util_windows.cc
+++ b/src/main/cpp/blaze_util_windows.cc
@@ -1437,7 +1437,6 @@ static string GetBinaryFromPath(const string& binary_name) {
     start = end + 1;
   } while (true);
 
-  BAZEL_LOG(ERROR) << binary_name.c_str() << " not found on PATH";
   return string();
 }
 
@@ -1447,7 +1446,11 @@ static string LocateBash() {
     return msys_bash;
   }
 
-  return GetBinaryFromPath("bash.exe");
+  string result = GetBinaryFromPath("bash.exe");
+  if (result.empty()) {
+    BAZEL_LOG(ERROR) << "bash.exe not found on PATH";
+  }
+  return result;
 }
 
 void DetectBashOrDie() {


Test patch:
diff --git a/src/test/py/bazel/BUILD b/src/test/py/bazel/BUILD
index 1116e039c247ff..d5f59d680c4530 100644
--- a/src/test/py/bazel/BUILD
+++ b/src/test/py/bazel/BUILD
@@ -166,6 +166,12 @@ py_test(
     }),
 )
 
+py_test(
+    name = "first_time_use_test",
+    srcs = ["first_time_use_test.py"],
+    deps = [":test_base"],
+)
+
 py_test(
     name = "query_test",
     size = "medium",
diff --git a/src/test/py/bazel/first_time_use_test.py b/src/test/py/bazel/first_time_use_test.py
new file mode 100644
index 00000000000000..5fc2033ad8e6e8
--- /dev/null
+++ b/src/test/py/bazel/first_time_use_test.py
@@ -0,0 +1,37 @@
+# Copyright 2018 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import unittest
+
+from src.test.py.bazel import test_base
+
+
+class FirstTimeUseTest(test_base.TestBase):
+
+  def _FailWithOutput(self, output):
+    self.fail('FAIL:\n | %s\n---' % '\n | '.join(output))
+
+  def testNoPythonRequirement(self):
+    """Regression test for https://github.com/bazelbuild/bazel/issues/6463"""
+    self.ScratchFile('WORKSPACE')
+    exit_code, stdout, stderr = self.RunBazel(['info', 'release'])
+    self.AssertExitCode(exit_code, 0, stderr)
+    for line in stdout + stderr:
+      if 'python' in line and 'not found on PATH' in line:
+        self._FailWithOutput(stdout + stderr)
+
+
+if __name__ == '__main__':
+  unittest.main()