Author: Aiden Grossman Date: 2026-05-06T10:57:05-07:00 New Revision: aed43ea84be698c0927e8d70deb1bfd66fa7f7da
URL: https://github.com/llvm/llvm-project/commit/aed43ea84be698c0927e8d70deb1bfd66fa7f7da DIFF: https://github.com/llvm/llvm-project/commit/aed43ea84be698c0927e8d70deb1bfd66fa7f7da.diff LOG: Revert "[lit] [compiler-rt] Add llvm-lit global command cache to speed up tes…" This reverts commit 4e007c117e00efceacb9cd0560544491d1474106. Added: Modified: compiler-rt/test/lit.common.cfg.py llvm/utils/lit/lit/LitConfig.py llvm/utils/lit/lit/util.py Removed: llvm/utils/lit/tests/unit/Util.py ################################################################################ diff --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py index 12446b4708d20..fef8f7ab297cc 100644 --- a/compiler-rt/test/lit.common.cfg.py +++ b/compiler-rt/test/lit.common.cfg.py @@ -20,8 +20,20 @@ def get_path_from_clang(args, allow_failure): f"--target={config.target_triple}", *args, ] - path = lit_config.run_command_cached(clang_cmd, allow_failure, text=True) - return path.strip(), clang_cmd + path = None + try: + result = subprocess.run( + clang_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True + ) + path = result.stdout.decode().strip() + except subprocess.CalledProcessError as e: + msg = f"Failed to run {clang_cmd}\nrc:{e.returncode}\nstdout:{e.stdout}\ne.stderr{e.stderr}" + if allow_failure: + lit_config.warning(msg) + else: + lit_config.fatal(msg) + return path, clang_cmd + def find_compiler_libdir(): """ @@ -580,12 +592,10 @@ def get_ios_commands_dir(): # There is no simulator-specific sw_vers/sysctl, so we use the host OS version os_detection_prefix = [] - darwin_os_version = lit_config.run_command_cached( - os_detection_prefix + ["sw_vers", "-productVersion"], - universal_newlines=True, - text=True, + darwin_os_version = subprocess.check_output( + os_detection_prefix + ["sw_vers", "-productVersion"], universal_newlines=True ) - darwin_os_version = tuple(int(x) for x in darwin_os_version.strip().split(".")) + darwin_os_version = tuple(int(x) for x in darwin_os_version.split(".")) if len(darwin_os_version) == 2: darwin_os_version = (darwin_os_version[0], darwin_os_version[1], 0) @@ -598,15 +608,17 @@ def get_ios_commands_dir(): config.darwin_os_version = darwin_os_version # Detect x86_64h - output = lit_config.run_command_cached( - os_detection_prefix + ["sysctl", "hw.cpusubtype"], text=True, allow_failure=True - ) - if output: + try: + output = subprocess.check_output( + os_detection_prefix + ["sysctl", "hw.cpusubtype"] + ) output_re = re.match("^hw.cpusubtype: ([0-9]+)$", output) if output_re: cpu_subtype = int(output_re.group(1)) if cpu_subtype == 8: # x86_64h config.available_features.add("x86_64h") + except: + pass # 32-bit iOS simulator is deprecated and removed in latest Xcode. if config.apple_platform == "iossim": @@ -943,11 +955,18 @@ def is_windows_lto_supported(): if lit.util.which("log"): # Querying the log can only done by a privileged user so # so check if we can query the log. - res = lit_config.run_command_cached( - ["log", "show", "--last", "1m", "--predicate", "1 == 0"], allow_failure=True - ) - if res is not None: + exit_code = -1 + with open("/dev/null", "r") as f: + # Run a `log show` command the should finish fairly quickly and produce very little output. + exit_code = subprocess.call( + ["log", "show", "--last", "1m", "--predicate", "1 == 0"], + stdout=f, + stderr=f, + ) + if exit_code == 0: config.available_features.add("darwin_log_cmd") + else: + lit_config.warning("log command found but cannot queried") else: lit_config.warning("log command not found. Some tests will be skipped.") elif config.android: diff --git a/llvm/utils/lit/lit/LitConfig.py b/llvm/utils/lit/lit/LitConfig.py index 4be2a0f6d8121..3b0dfaa981d4a 100644 --- a/llvm/utils/lit/lit/LitConfig.py +++ b/llvm/utils/lit/lit/LitConfig.py @@ -263,22 +263,6 @@ def fatal(self, message): self._write_message("fatal", message) sys.exit(2) - def run_command_cached(self, cmd, allow_failure=False, **kwargs): - """ - Run a command with subprocess.run, with a cache global to this llvm-lit invocation - If allow_failure is True, lit_config.fatal will be invoked if the command fails. - All additional kwargs are passed to subprocess.run - """ - if type(cmd) is list: - cmd = tuple(cmd) - return lit.util.runCommandCached(self, cmd, allow_failure, **kwargs) - elif type(cmd) is str: - return lit.util.runCommandCached(self, cmd, allow_failure, **kwargs) - else: - raise ValueError( - f"runCommandCached expected list or str, got {type(cmd)}: {cmd}" - ) - @enum.unique class DiagnosticLevel(enum.IntEnum): diff --git a/llvm/utils/lit/lit/util.py b/llvm/utils/lit/lit/util.py index 13eea2045242e..a800f1f6e1419 100644 --- a/llvm/utils/lit/lit/util.py +++ b/llvm/utils/lit/lit/util.py @@ -12,7 +12,7 @@ import subprocess import sys import threading -import functools + def pythonize_bool(value): if value is None: @@ -441,26 +441,3 @@ def killProcessAndChildren(pid): psutilProc.kill() except psutil.NoSuchProcess: pass - - [email protected] -def runCommandCached(lit_config, cmd, allow_failure, **kwargs): - """ - Run a command with subprocess.run, with a cache global to this llvm-lit invocation - If allow_failure is True, lit_config.fatal will be invoked if the command fails. - All additional kwargs are passed to subprocess.run - """ - try: - result = subprocess.run( - cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, **kwargs - ) - return result.stdout - except FileNotFoundError as e: - msg = f"Failed to run {cmd}: {e}" - except subprocess.CalledProcessError as e: - msg = f"Failed to run {cmd}\nrc:{e.returncode}\nstdout:{e.stdout}\ne.stderr{e.stderr}" - - if not allow_failure: - lit_config.fatal(msg) - - return None diff --git a/llvm/utils/lit/tests/unit/Util.py b/llvm/utils/lit/tests/unit/Util.py deleted file mode 100644 index a93fbff71c53b..0000000000000 --- a/llvm/utils/lit/tests/unit/Util.py +++ /dev/null @@ -1,88 +0,0 @@ -# RUN: %{python} %s -# UNSUPPORTED: system-windows - -import unittest -import platform -import time - -from lit.util import runCommandCached -from lit.LitConfig import LitConfig - - -class TestCommandCache(unittest.TestCase): - @staticmethod - def _lit_config(): - return LitConfig( - progname="lit", - path=[], - diagnostic_level="note", - useValgrind=False, - valgrindLeakCheck=False, - valgrindArgs=[], - noExecute=False, - debug=False, - isWindows=(platform.system() == "Windows"), - order="smart", - params={}, - ) - - def test_basic(self): - lit_config = self._lit_config() - - self.assertEqual(lit_config.run_command_cached(["echo", "-n", "hi"]), b"hi") - self.assertNotEqual(lit_config.run_command_cached("ls"), None) - - # Test that arguments (e.g. text=True) get forwarded to subprocess.run - self.assertEqual( - lit_config.run_command_cached(["echo", "-n", "hi"], text=True), "hi" - ) - - # shell=True is not implied - self.assertEqual( - lit_config.run_command_cached("ls -al", allow_failure=True), None - ) - self.assertNotEqual( - lit_config.run_command_cached("ls -al", allow_failure=True, shell=True), - None, - ) - - self.assertEqual( - lit_config.run_command_cached("exit 0", shell=True, allow_failure=True), b"" - ) - - def test_fatal(self): - lit_config = self._lit_config() - - # Test fatal errors - fatal_counter = 0 - - def wrap_fatal(msg): - nonlocal fatal_counter - fatal_counter += 1 - - lit_config.fatal = wrap_fatal - lit_config.run_command_cached(["asdfghjkl"]) - self.assertEqual(fatal_counter, 1) - - self.assertEqual( - lit_config.run_command_cached(["asdfghjkl"], allow_failure=True), None - ) - self.assertEqual( - lit_config.run_command_cached("exit 1", shell=True, allow_failure=True), - None, - ) - self.assertEqual(fatal_counter, 1) - - def test_cache(self): - lit_config = self._lit_config() - - # Check the date (with nanoseconds) - date = lit_config.run_command_cached("date -Ins", shell=True) - self.assertNotEqual(date, None) - - # Second time should be cached, i.e. equal to the first - self.assertEqual(lit_config.run_command_cached("date -Ins", shell=True), date) - - -if __name__ == "__main__": - unittest.main() _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
