Skip to content

Commit

Permalink
better detection of python lib / include dirs in build_usd.py
Browse files Browse the repository at this point in the history
This addresses two issues:

- Building using a venv-installed python
  - The venv-installed pythons would try to pull the libraries from
    the venv-directory, when they only reside at the "original"\
    installed python location

- Building with a python that was moved after building on Linux
  - We experienced issues where the `INCLUDEPY` and `LIBDIR` sysconfig
    vars were baked at build time.  Thus these would no longer be
    reliable if running a python executable that was moved to a
    different location after building.

Note that or python-2.7, `installed_base` doesn't exist, so we fall back
to `base`.  This should be fairly backward-compatible, as we check if
the dir (for include) or file (for lib) doesn't exist, and try alternate
methods if not.
  • Loading branch information
pmolodo committed Mar 4, 2022
1 parent ff1e6fd commit 535f6da
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions build_scripts/build_usd.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,38 @@ def _GetPythonLibraryFilename(context):
pythonLibPath = os.path.join(pythonBaseDir, "lib",
_GetPythonLibraryFilename(context))
else:
pythonIncludeDir = sysconfig.get_config_var("INCLUDEPY")
if Windows():
pythonIncludeDir = sysconfig.get_path("include")
if not pythonIncludeDir or not os.path.isdir(pythonIncludeDir):
# as a backup, and for legacy reasons - not preferred because
# it may be baked at build time
pythonIncludeDir = sysconfig.get_config_var("INCLUDEPY")

# if in a venv, installed_base will be the "original" python,
# which is where the libs are ("base" will be the venv dir)
pythonBaseDir = sysconfig.get_config_var("installed_base")
if not pythonBaseDir or not os.path.isdir(pythonBaseDir):
# for python-2.7
pythonBaseDir = sysconfig.get_config_var("base")

if Windows():
pythonLibPath = os.path.join(pythonBaseDir, "libs",
_GetPythonLibraryFilename(context))
elif Linux():
pythonLibDir = sysconfig.get_config_var("LIBDIR")
pythonMultiarchSubdir = sysconfig.get_config_var("multiarchsubdir")
if pythonMultiarchSubdir:
pythonLibDir = pythonLibDir + pythonMultiarchSubdir
pythonLibPath = os.path.join(pythonLibDir,
_GetPythonLibraryFilename(context))
# Try multiple ways to get the python lib dir
for pythonLibDir in (sysconfig.get_config_var("LIBDIR"),
os.path.join(pythonBaseDir, "lib")):
if pythonMultiarchSubdir:
pythonLibPath = \
os.path.join(pythonLibDir + pythonMultiarchSubdir,
_GetPythonLibraryFilename(context))
if os.path.isfile(pythonLibPath):
break
pythonLibPath = os.path.join(pythonLibDir,
_GetPythonLibraryFilename(context))
if os.path.isfile(pythonLibPath):
break
elif MacOS():
pythonBaseDir = sysconfig.get_config_var("base")
pythonLibPath = os.path.join(pythonBaseDir, "lib",
_GetPythonLibraryFilename(context))
else:
Expand Down

0 comments on commit 535f6da

Please sign in to comment.