[lit] Only return a found bash executable on Windows if it can understand Windows...
authorGreg Bedwell <greg_bedwell@sn.scee.net>
Tue, 23 Oct 2018 11:34:04 +0000 (11:34 +0000)
committerGreg Bedwell <greg_bedwell@sn.scee.net>
Tue, 23 Oct 2018 11:34:04 +0000 (11:34 +0000)
Some versions of bash.exe, for example WSL's version expect paths in the form
/mnt/c/path/to/dir rather than c:\\path\\to\\dir so will cause failures
for any tests that require an external shell if used by lit.  If we're on
Windows and looking for an external shell, check that the found version
of bash is able to parse a native path before returning that version.

This patch also partially reverts the behaviour of r228221 by
restoring the warning if bash cannot be found.  This shouldn't pollute
the lit stderr anymore as we're now using internal shell by default on
Windows.  If someone is explicitly specifying to use an external shell, it's
probably worth alerting them to the fact that bash could not be found.

Differential Revision: https://reviews.llvm.org/D52831

llvm-svn: 345019

llvm/utils/lit/lit/LitConfig.py

index e8fb1533a86147f75806a419a2f83fda9bdb6668..97c091085816df2b941675f1221bad90b0cee6f7 100644 (file)
@@ -120,6 +120,22 @@ class LitConfig(object):
         if self.bashPath is None:
             self.bashPath = ''
 
+        # Check whether the found version of bash is able to cope with paths in
+        # the host path format. If not, don't return it as it can't be used to
+        # run scripts. For example, WSL's bash.exe requires '/mnt/c/foo' rather
+        # than 'C:\\foo' or 'C:/foo'.
+        if self.isWindows and self.bashPath:
+            command = [self.bashPath, '-c',
+                       '[[ -f "%s" ]]' % self.bashPath.replace('\\', '\\\\')]
+            _, _, exitCode = lit.util.executeCommand(command)
+            if exitCode:
+                self.note('bash command failed: %s' % (
+                    ' '.join('"%s"' % c for c in command)))
+                self.bashPath = ''
+
+        if not self.bashPath:
+            self.warning('Unable to find a usable version of bash.')
+
         return self.bashPath
 
     def getToolsPath(self, dir, paths, tools):