[llvm] 01fdc2a - [Utils] Refactor update_cc_test_checks.py to use shutil
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 21 10:55:41 PDT 2022
Author: John McIver
Date: 2022-09-21T10:55:33-07:00
New Revision: 01fdc2a3c9e0df4e54bb9b88f385f68e7b0d808c
URL: https://github.com/llvm/llvm-project/commit/01fdc2a3c9e0df4e54bb9b88f385f68e7b0d808c
DIFF: https://github.com/llvm/llvm-project/commit/01fdc2a3c9e0df4e54bb9b88f385f68e7b0d808c.diff
LOG: [Utils] Refactor update_cc_test_checks.py to use shutil
The package `distutils` is deprecated and removal is planned for Python 3.12. All calls to `distutils.spawn.find_executable` are replaced with local version of `find_executable` which makes use of `shutils.which`.
Reviewed By: arichardson, MaskRay
Differential Revision: https://reviews.llvm.org/D134015
Added:
Modified:
llvm/utils/update_cc_test_checks.py
Removed:
################################################################################
diff --git a/llvm/utils/update_cc_test_checks.py b/llvm/utils/update_cc_test_checks.py
index b9e91f19461b..e4a12e54eebb 100755
--- a/llvm/utils/update_cc_test_checks.py
+++ b/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,14 @@ def infer_dependent_args(args):
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'
+
+ return shutil.which(executable)
+
+
def config():
parser = argparse.ArgumentParser(
description=__doc__,
@@ -167,7 +175,7 @@ def config():
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 +191,7 @@ def config():
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.
More information about the llvm-commits
mailing list