[clang] ee34137 - [clang] Replace find_executable with shutil.which in creduce script

David Spickett via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 17 08:33:13 PDT 2023


Author: David Spickett
Date: 2023-04-17T15:33:06Z
New Revision: ee341373625163846f4ebc68e46aec6fb46c2c09

URL: https://github.com/llvm/llvm-project/commit/ee341373625163846f4ebc68e46aec6fb46c2c09
DIFF: https://github.com/llvm/llvm-project/commit/ee341373625163846f4ebc68e46aec6fb46c2c09.diff

LOG: [clang] Replace find_executable with shutil.which in creduce script

distutils is deprecated and shutil.which is the suggested
replacement for this function.

https://peps.python.org/pep-0632/#migration-advice
https://docs.python.org/3/library/shutil.html#shutil.which

which was added in 3.3 (https://docs.python.org/3/library/shutil.html#shutil.which)
and LLVM requires at least 3.6 (https://llvm.org/docs/GettingStarted.html#software).

There is one small differnce here that shutil.which ignores the PATH
when given a path argument. However in this case I think that's actually
the behaviour we want.

Reviewed By: zequanwu

Differential Revision: https://reviews.llvm.org/D148529

Added: 
    

Modified: 
    clang/utils/creduce-clang-crash.py

Removed: 
    


################################################################################
diff  --git a/clang/utils/creduce-clang-crash.py b/clang/utils/creduce-clang-crash.py
index 77bd4cf0fbfcf..fa3bd470ef725 100755
--- a/clang/utils/creduce-clang-crash.py
+++ b/clang/utils/creduce-clang-crash.py
@@ -11,6 +11,7 @@
 from argparse import ArgumentParser, RawTextHelpFormatter
 import os
 import re
+import shutil
 import stat
 import sys
 import subprocess
@@ -18,7 +19,6 @@
 import shlex
 import tempfile
 import shutil
-from distutils.spawn import find_executable
 import multiprocessing
 
 verbose = False
@@ -43,12 +43,12 @@ def check_cmd(cmd_name, cmd_dir, cmd_path=None):
   if cmd_path:
     # Make the path absolute so the creduce test can be run from any directory.
     cmd_path = os.path.abspath(cmd_path)
-    cmd = find_executable(cmd_path)
+    cmd = shutil.which(cmd_path)
     if cmd:
       return cmd
     sys.exit("ERROR: executable `%s` not found" % (cmd_path))
 
-  cmd = find_executable(cmd_name, path=cmd_dir)
+  cmd = shutil.which(cmd_name, path=cmd_dir)
   if cmd:
     return cmd
 


        


More information about the cfe-commits mailing list