[PATCH] D134015: [Utils] Refactor update_cc_test_checks.py to use shutil
John McIver via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 20 22:42:14 PDT 2022
jmciver updated this revision to Diff 461792.
jmciver edited the summary of this revision.
jmciver added a comment.
Add a local `find_executable` function to `update_cc_test_checks.py` that takes the necessary functionality from `distutils.spawn.find_executable` and makes use of `shutil.which`.
The local `find_executable`:
- Appends `.exe` to the executable name when the environment is `win32`
- Test if executable is specified by an absolute or relative path and if iit is return the absolute or relative executable
I have tested in both Windows 11 and Linux using `PATH`, `--clang` (both absolute and relative), and `--llvm-bin` (both absolute and relative).
https://github.com/python/cpython/blob/main/Lib/distutils/spawn.py#L95
https://github.com/python/cpython/blob/main/Lib/shutil.py#L1441
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D134015/new/
https://reviews.llvm.org/D134015
Files:
llvm/utils/update_cc_test_checks.py
Index: llvm/utils/update_cc_test_checks.py
===================================================================
--- llvm/utils/update_cc_test_checks.py
+++ llvm/utils/update_cc_test_checks.py
@@ -16,11 +16,11 @@
import argparse
import collections
-import distutils.spawn
import json
import os
import re
import shlex
+import shutil
import subprocess
import sys
import tempfile
@@ -140,6 +140,17 @@
args.opt = os.path.join(args.llvm_bin, 'opt')
+def find_executable(executable):
+ _, ext = os.path.splitext(executable)
+ if sys.platform == 'win32' and ext != '.exe':
+ executable = executable + '.exe'
+
+ if os.path.isfile(executable):
+ return executable
+
+ return shutil.which(executable)
+
+
def config():
parser = argparse.ArgumentParser(
description=__doc__,
@@ -167,7 +178,7 @@
args = common.parse_commandline_args(parser)
infer_dependent_args(args)
- if not distutils.spawn.find_executable(args.clang):
+ if not find_executable(args.clang):
print('Please specify --llvm-bin or --clang', file=sys.stderr)
sys.exit(1)
@@ -183,7 +194,7 @@
common.warn('Could not determine clang builtins directory, some tests '
'might not update correctly.')
- if not distutils.spawn.find_executable(args.opt):
+ if not find_executable(args.opt):
# Many uses of this tool will not need an opt binary, because it's only
# needed for updating a test that runs clang | opt | FileCheck. So we
# defer this error message until we find that opt is actually needed.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134015.461792.patch
Type: text/x-patch
Size: 1551 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220921/725f4565/attachment.bin>
More information about the llvm-commits
mailing list