Skip to content

Commit 01fdc2a

Browse files
jmciverMaskRay
authored andcommitted
[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
1 parent c39311e commit 01fdc2a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

llvm/utils/update_cc_test_checks.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
import argparse
1818
import collections
19-
import distutils.spawn
2019
import json
2120
import os
2221
import re
2322
import shlex
23+
import shutil
2424
import subprocess
2525
import sys
2626
import tempfile
@@ -140,6 +140,14 @@ def infer_dependent_args(args):
140140
args.opt = os.path.join(args.llvm_bin, 'opt')
141141

142142

143+
def find_executable(executable):
144+
_, ext = os.path.splitext(executable)
145+
if sys.platform == 'win32' and ext != '.exe':
146+
executable = executable + '.exe'
147+
148+
return shutil.which(executable)
149+
150+
143151
def config():
144152
parser = argparse.ArgumentParser(
145153
description=__doc__,
@@ -167,7 +175,7 @@ def config():
167175
args = common.parse_commandline_args(parser)
168176
infer_dependent_args(args)
169177

170-
if not distutils.spawn.find_executable(args.clang):
178+
if not find_executable(args.clang):
171179
print('Please specify --llvm-bin or --clang', file=sys.stderr)
172180
sys.exit(1)
173181

@@ -183,7 +191,7 @@ def config():
183191
common.warn('Could not determine clang builtins directory, some tests '
184192
'might not update correctly.')
185193

186-
if not distutils.spawn.find_executable(args.opt):
194+
if not find_executable(args.opt):
187195
# Many uses of this tool will not need an opt binary, because it's only
188196
# needed for updating a test that runs clang | opt | FileCheck. So we
189197
# defer this error message until we find that opt is actually needed.

0 commit comments

Comments
 (0)