Skip to content

Conversation

@charles-zablit
Copy link
Contributor

@charles-zablit charles-zablit commented May 6, 2025

Summary

LLDB tests will fail with the "command not found" error if there are spaces in the command path.

This PR fixes the issue by quoting the command.

Description

The path of a command that was substituted in a test file (for instance lld-link) may contain spaces. On windows, it will start will C:\Program Files\.... This will cause the command to be parsed as ['C:\Program', 'Files\...', ....

This causes the tests to fail.

Fix

During the parsing stage of the test file, we use shlex.quote to shell escape the command path. The command is test parsed correctly by ShUtil.ShParser.parse and the rest of the flow is executed as expected.

@llvmbot
Copy link
Member

llvmbot commented May 6, 2025

@llvm/pr-subscribers-testing-tools

Author: Charles Zablit (charles-zablit)

Changes

Summary

LLDB tests will fail with the "command not found" error if there are spaces in the command path.

This PR fixes the issue by quoting the command.

Description

The path of a command that was substituted in a test file (for instance lld-link) may contain spaces. On windows, it will start will C:\Program Files\.... This will cause the command to be parsed as ['C:\Program', 'Files\...', ....

This causes the tests to fail.

Fix

During the parsing stage of the test file, we use shlex.quote to shell escape the command path. The command is test parsed correctly by ShUtil.ShParser.parse and the rest of the flow is executed as expected.


Full diff: https://github.com/llvm/llvm-project/pull/138714.diff

1 Files Affected:

  • (modified) llvm/utils/lit/lit/llvm/subst.py (+3)
diff --git a/llvm/utils/lit/lit/llvm/subst.py b/llvm/utils/lit/lit/llvm/subst.py
index 09ab3555a6b44..9d74db89bd6b4 100644
--- a/llvm/utils/lit/lit/llvm/subst.py
+++ b/llvm/utils/lit/lit/llvm/subst.py
@@ -1,5 +1,6 @@
 import os
 import re
+import shlex
 
 import lit.util
 
@@ -118,6 +119,8 @@ def resolve(self, config, search_dirs):
             command_str = str(self.command)
 
         if command_str:
+            # A command path with spaces will fail to be parsed by ShParser if they are not quoted.
+            command_str = shlex.quote(command_str)
             if self.extra_args:
                 command_str = " ".join([command_str] + self.extra_args)
         else:

@adrian-prantl
Copy link
Collaborator

Maybe you can find a way to unit-test this to document the expected behavior of the function?

@charles-zablit
Copy link
Contributor Author

Closing this as I was invoking the tests incorrectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants