3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-08 18:31:49 +00:00

Fix setting the path to the Python package directory.

There were several problems with the existing implementation.

* When specifying ``--prefix`` the implementation would assume the
  path was ``$(PREFIX)/lib/python-<VERSION>/dist-packages``. This
  is incorrect. ``dist-packages`` is Debian (and its derivatives,
  i.e Ubuntu) specific and won't work on other Linux distributions
  such as Arch Linux.

* When generating the ``Makefile``, ``$(PREFIX)`` was only emitted
  during the Python installation when ``--prefix`` was passed on
  the command line. When ``--prefix`` was not passed the absolute
  path to the Python package directory was emitted. This is not
  very consistent.

This patch checks that the detected Python package directory lives
under the install prefix and emits an error if it does not as this
indicates that the installation will be broken. If the Python package
directory does live under the install prefix it replaces that prefix
with the ``$(PREFIX)`` variable when emitting the ``Makefile`` for
consistency with the other install commands.

If a user really wants to install to a particular Python package
directory they can force it with the newly added ``--pypkgdir=``
flag.
This commit is contained in:
Dan Liew 2015-11-24 12:10:01 +00:00
parent b285ce7cee
commit 4c11037d70

View file

@ -550,6 +550,7 @@ def display_help(exit_code):
print(" -p <dir>, --prefix=<dir> installation prefix (default: %s)." % PREFIX)
else:
print(" --parallel=num use cl option /MP with 'num' parallel processes")
print(" --pypkgdir=<dir> Force a particular Python package directory (default %s)" % PYTHON_PACKAGE_DIR)
print(" -b <sudir>, --build=<subdir> subdirectory where Z3 will be built (default: build).")
print(" --githash=hash include the given hash in the binaries.")
print(" -d, --debug compile Z3 in debug mode.")
@ -593,12 +594,13 @@ def parse_options():
global VERBOSE, DEBUG_MODE, IS_WINDOWS, VS_X64, ONLY_MAKEFILES, SHOW_CPPS, VS_PROJ, TRACE, VS_PAR, VS_PAR_NUM
global DOTNET_ENABLED, JAVA_ENABLED, ML_ENABLED, STATIC_LIB, PREFIX, GMP, FOCI2, FOCI2LIB, PYTHON_PACKAGE_DIR, GPROF, GIT_HASH
global LINUX_X64, SLOW_OPTIMIZE, USE_OMP
pythonPkgDir=None
try:
options, remainder = getopt.gnu_getopt(sys.argv[1:],
'b:df:sxhmcvtnp:gj',
['build=', 'debug', 'silent', 'x64', 'help', 'makefiles', 'showcpp', 'vsproj',
'trace', 'nodotnet', 'staticlib', 'prefix=', 'gmp', 'foci2=', 'java', 'parallel=', 'gprof',
'githash=', 'x86', 'ml', 'optimize', 'noomp'])
'githash=', 'x86', 'ml', 'optimize', 'noomp', 'pypkgdir='])
except:
print("ERROR: Invalid command line option")
display_help(1)
@ -637,7 +639,8 @@ def parse_options():
SLOW_OPTIMIZE = True
elif not IS_WINDOWS and opt in ('-p', '--prefix'):
PREFIX = arg
PYTHON_PACKAGE_DIR = os.path.join('$(PREFIX)', 'lib', 'python%s' % distutils.sysconfig.get_python_version(), 'dist-packages')
elif opt in ('--pypkgdir'):
pythonPkgDir = arg
elif IS_WINDOWS and opt == '--parallel':
VS_PAR = True
VS_PAR_NUM = int(arg)
@ -659,6 +662,31 @@ def parse_options():
else:
print("ERROR: Invalid command line option '%s'" % opt)
display_help(1)
# Handle the Python package directory
def printPythonPackageMessage(errorType):
msg = (("%s: The detected Python package directory (%s)"
" does not live under the installation prefix (%s)"
". This will most likely lead to a broken installation.") %
(errorType, PYTHON_PACKAGE_DIR, PREFIX))
if errorType == "ERROR":
msg += (" However if you are confident you want to use that"
" Python package directory use --pypkgdir=%s to force"
" it.") % PYTHON_PACKAGE_DIR
print(msg)
if pythonPkgDir == None:
if not IS_WINDOWS:
# Try to use the default if it makes sense
if not PYTHON_PACKAGE_DIR.startswith(PREFIX):
printPythonPackageMessage("ERROR")
sys.exit(1)
# Do replacement to use $(PREFIX) in the Makefile
PYTHON_PACKAGE_DIR = PYTHON_PACKAGE_DIR.replace(PREFIX, "$(PREFIX)", 1)
else:
PYTHON_PACKAGE_DIR = pythonPkgDir
if not os.path.exists(PYTHON_PACKAGE_DIR):
print("WARNING: PYTHON_PACKAGE_DIR (%s) does not exist." % PYTHON_PACKAGE_DIR)
if not PYTHON_PACKAGE_DIR.startswith(PREFIX):
printPythonPackageMessage("WARNING")
# Return a list containing a file names included using '#include' in
# the given C/C++ file named fname.