Skip to content

Commit

Permalink
[build_scripts] use shutil.which instead of find_executable
Browse files Browse the repository at this point in the history
...if possible (ony available on python-3)

shutil.which is preferred, because it deals with additional windows
executable extensions, besides just .exe (ie, .bat - so
pyside2-uic.bat will be found)

See: https://bugs.python.org/issue2200

Also, distutils is deprecated
  • Loading branch information
pmolodo committed Apr 8, 2021
1 parent f57e281 commit 99c7013
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions build_scripts/build_usd.py
Expand Up @@ -23,8 +23,6 @@
#
from __future__ import print_function

from distutils.spawn import find_executable

import argparse
import codecs
import contextlib
Expand All @@ -48,9 +46,14 @@

if sys.version_info.major >= 3:
from urllib.request import urlopen
from shutil import which
else:
from urllib2 import urlopen

# Doesn't deal with .bat / .cmd like shutil.which, but only option
# available with stock python-2
from distutils.spawn import find_executable as which

# Helpers for printing output
verbosity = 1

Expand Down Expand Up @@ -119,7 +122,7 @@ def GetVisualStudioCompilerAndVersion():
if not Windows():
return None

msvcCompiler = find_executable('cl')
msvcCompiler = which('cl')
if msvcCompiler:
# VisualStudioVersion environment variable should be set by the
# Visual Studio Command Prompt.
Expand Down Expand Up @@ -1777,10 +1780,10 @@ def __init__(self, args):
# use urllib2 all the time is that some older versions of Python
# don't support TLS v1.2, which is required for downloading some
# dependencies.
if find_executable("curl"):
if which("curl"):
self.downloader = DownloadFileWithCurl
self.downloaderName = "curl"
elif Windows() and find_executable("powershell"):
elif Windows() and which("powershell"):
self.downloader = DownloadFileWithPowershell
self.downloaderName = "powershell"
else:
Expand Down Expand Up @@ -1975,8 +1978,8 @@ def ForceBuildDependency(self, dep):
dependenciesToBuild.append(dep)

# Verify toolchain needed to build required dependencies
if (not find_executable("g++") and
not find_executable("clang") and
if (not which("g++") and
not which("clang") and
not GetXcodeDeveloperDirectory() and
not GetVisualStudioCompilerAndVersion()):
PrintError("C++ compiler not found -- please install a compiler")
Expand All @@ -1998,7 +2001,7 @@ def ForceBuildDependency(self, dep):
PrintError("Python 3.8+ is not supported on Windows")
sys.exit(1)

if find_executable("cmake"):
if which("cmake"):
# Check cmake requirements
if Windows():
# Windows build depend on boost 1.70, which is not supported before
Expand All @@ -2024,11 +2027,11 @@ def _JoinVersion(v):
sys.exit(1)

if context.buildDocs:
if not find_executable("doxygen"):
if not which("doxygen"):
PrintError("doxygen not found -- please install it and adjust your PATH")
sys.exit(1)

if not find_executable("dot"):
if not which("dot"):
PrintError("dot not found -- please install graphviz and adjust your "
"PATH")
sys.exit(1)
Expand All @@ -2038,9 +2041,9 @@ def _JoinVersion(v):
# not found, so check for it here to avoid confusing users. This list of
# PySide executable names comes from cmake/modules/FindPySide.cmake
pyside2Uic = ["pyside2-uic", "python2-pyside2-uic", "pyside2-uic-2.7"]
found_pyside2Uic = any([find_executable(p) for p in pyside2Uic])
found_pyside2Uic = any([which(p) for p in pyside2Uic])
pysideUic = ["pyside-uic", "python2-pyside-uic", "pyside-uic-2.7"]
found_pysideUic = any([find_executable(p) for p in pysideUic])
found_pysideUic = any([which(p) for p in pysideUic])
if not found_pyside2Uic and not found_pysideUic:
if Windows():
# Windows does not support PySide2 with Python2.7
Expand All @@ -2057,7 +2060,7 @@ def _JoinVersion(v):

if JPEG in requiredDependencies:
# NASM is required to build libjpeg-turbo
if (Windows() and not find_executable("nasm")):
if (Windows() and not which("nasm")):
PrintError("nasm not found -- please install it and adjust your PATH")
sys.exit(1)

Expand Down

0 comments on commit 99c7013

Please sign in to comment.