llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[llvm-lit] RFC: Improve cross-platform compatibility and operating system security of the `llvm/utils/update_test_body.py` script

Open zhangweize9-cyber opened this issue 1 month ago • 0 comments

Summary, TL;DR:

Here's the original RFC draft:

Enhanced matching for temporary directory files to exclude system runtime files. Added whitelist matching to the rm command in llvm-lit to prevent accidental deletion of system files when cleaning up temporary files or directories.

Known issues:

  • Temporary file paths strongly depend on the APPDATA path in Windows NT.
  • Incorrect runtime path matching can lead to accidental deletion of temporary files in other directories.
  • Forward and backslash escaping can cause garbled characters in command-line text display.
  • On Windows NT and POSIX platforms, the PATH variable is either Path or all uppercase PATH.

To-do list: (llvm-lit root directory: PROJECT_ROOT/llvm/utils/lit/lit/)

  • [ ] feat(executeBuiltinRm): Add runtime path detection when clearing the cache. If a runtime path is detected, stop the program or only match and run test files in the working directory -- from pathlib import Path, Path.cwd() -- #235463
  • [ ] Handle ANSI escape characters in backslash paths on Windows NT systems -- bytes(raw_data, "utf-8").decode("unicode_escape") -- #235463
  • [ ] Handle project file paths under multiple drives -- os.getcwd()
  • [ ] Unify RUN: part to POSIX platform backslashes -- string.replace("\\", "/")

Future plans:

  • [ ] Support forward and backslash paths in llvm-lit binary executables for Windows NT and POSIX platforms.
  • [ ] Adapt shell environments to ensure consistent behavior across platforms.
  • [ ] Map certain special PowerShell commands to POSIX system binaries -- If you are windows 11 user, run command in cmd: winget install <powershell 7.1> to update powershell.
  • [ ] Address the case-insensitive issue of file paths on Windows NT platforms, for example, test and Test are the same path.

Heavyweight requirements that necessitate disruptive changes:

  • [ ] Rewrite the module dependency tree so that llvm-lit can run independently without depending on the ninja or bazel build tools.
  • [ ] Compatible with cmake configuration files.

Sub-issues & Pull Request

  • #235440
  • #235463

Reference functions:

Files Class Function Set
InprocBuiltins.py - executeBuiltinRm() -
TestingConfig.py TestingConfig fromdefaults() pass_vars
ShellEnvirorment.py ShellEnvirorment - -
ShellEnvirorment.py - processRedirects() -
ShellEnvirorment.py - as_binary_reader() -
TestRunner.py PipeIOConfig - -
Source: Teamily AI, TestRunner.py - _runShTest() -
Source: Teamily AI, InprocBuiltins.py, main.py - shutil.rmtree() tmpBase, ignore_errors=True
ShCommands.py Pipeline - -

zhangweize9-cyber avatar Oct 17 '26 13:10 zhangweize9-cyber