lit: When running Tcl scripts via shell, try harder to find 'bash', but fall
authorDaniel Dunbar <daniel@zuster.org>
Mon, 19 Oct 2009 03:54:21 +0000 (03:54 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 19 Oct 2009 03:54:21 +0000 (03:54 +0000)
back to running them internally if that fails. PR5240.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84462 91177308-0d34-0410-b5e6-96231b3b80d8

utils/lit/LitConfig.py
utils/lit/TestRunner.py

index 4fb0ccc09353067e8dedd796e570591a5264d9e6..c334109e1deefe76352c41b4cadfee341c8aa4a2 100644 (file)
@@ -29,6 +29,7 @@ class LitConfig:
         self.noExecute = noExecute
         self.debug = debug
         self.isWindows = bool(isWindows)
         self.noExecute = noExecute
         self.debug = debug
         self.isWindows = bool(isWindows)
+        self.bashPath = None
 
         self.numErrors = 0
         self.numWarnings = 0
 
         self.numErrors = 0
         self.numWarnings = 0
@@ -41,6 +42,27 @@ class LitConfig:
                                       mustExist = True,
                                       config = config)
 
                                       mustExist = True,
                                       config = config)
 
+    def getBashPath(self):
+        """getBashPath - Get the path to 'bash'"""
+        import os, Util
+
+        if self.bashPath is not None:
+            return self.bashPath
+
+        self.bashPath = Util.which('bash', os.pathsep.join(self.path))
+        if self.bashPath is None:
+            # Check some known paths.
+            for path in ('/bin/bash', '/usr/bin/bash'):
+                if os.path.exists(path):
+                    self.bashPath = path
+                    break
+
+        if self.bashPath is None:
+            self.warning("Unable to find 'bash', running Tcl tests internally.")
+            self.bashPath = ''
+
+        return self.bashPath
+
     def _write_message(self, kind, message):
         import inspect, os, sys
 
     def _write_message(self, kind, message):
         import inspect, os, sys
 
index 7b549ac1c6156dcaf391794ceafd4c126061b2dc..34e828bf96098c831de52f3edb830979dabc34d3 100644 (file)
@@ -237,7 +237,9 @@ def executeTclScriptInternal(test, litConfig, tmpBase, commands, cwd):
     for c in cmds[1:]:
         cmd = ShUtil.Seq(cmd, '&&', c)
 
     for c in cmds[1:]:
         cmd = ShUtil.Seq(cmd, '&&', c)
 
-    if litConfig.useTclAsSh:
+    # FIXME: This is lame, we shouldn't need bash. See PR5240.
+    bashPath = litConfig.getBashPath()
+    if litConfig.useTclAsSh and bashPath:
         script = tmpBase + '.script'
 
         # Write script file
         script = tmpBase + '.script'
 
         # Write script file
@@ -252,7 +254,7 @@ def executeTclScriptInternal(test, litConfig, tmpBase, commands, cwd):
             print >>sys.stdout
             return '', '', 0
 
             print >>sys.stdout
             return '', '', 0
 
-        command = ['/bin/bash', script]
+        command = [litConfig.getBashPath(), script]
         out,err,exitCode = executeCommand(command, cwd=cwd,
                                           env=test.config.environment)
 
         out,err,exitCode = executeCommand(command, cwd=cwd,
                                           env=test.config.environment)