bytecompile: switch to handling destdir in the script launcher env

pull/11530/head
Eli Schwartz 2 years ago
parent 6a1427401c
commit 877d5ea8e0
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 14
      mesonbuild/modules/python.py
  2. 26
      mesonbuild/scripts/pycompile.py

@ -322,13 +322,13 @@ class PythonModule(ExtensionModule):
for t in installdata.targets:
if should_append(t.out_name):
py_files.append(os.path.join(installdata.prefix, t.outdir, os.path.basename(t.fname)))
py_files.append((t.out_name, os.path.join(installdata.prefix, t.outdir, os.path.basename(t.fname))))
for d in installdata.data:
if should_append(d.install_path_name):
py_files.append(os.path.join(installdata.prefix, d.install_path))
py_files.append((d.install_path_name, os.path.join(installdata.prefix, d.install_path)))
for d in installdata.install_subdirs:
if should_append(d.install_path_name, True):
py_files.append(os.path.join(installdata.prefix, d.install_path))
py_files.append((d.install_path_name, os.path.join(installdata.prefix, d.install_path)))
import importlib.resources
pycompile = os.path.join(self.interpreter.environment.get_scratch_dir(), 'pycompile.py')
@ -340,13 +340,15 @@ class PythonModule(ExtensionModule):
i = T.cast(PythonExternalProgram, i)
manifest = f'python-{i.info["version"]}-installed.json'
manifest_json = []
for f in py_files:
for name, f in py_files:
if f.startswith((os.path.join(installdata.prefix, i.platlib), os.path.join(installdata.prefix, i.purelib))):
manifest_json.append(f)
manifest_json.append(name)
with open(os.path.join(self.interpreter.environment.get_scratch_dir(), manifest), 'w', encoding='utf-8') as f:
json.dump(manifest_json, f)
cmd = i.command + [pycompile, manifest, str(optlevel)]
script = backend.get_executable_serialisation(cmd, verbose=True)
script = backend.get_executable_serialisation(cmd, verbose=True,
installdir_map={'py_purelib': i.purelib, 'py_platlib': i.platlib})
ret.append(script)
return ret

@ -20,28 +20,26 @@
import json, os, subprocess, sys
from compileall import compile_file
destdir = os.environ.get('DESTDIR')
quiet = int(os.environ.get('MESON_INSTALL_QUIET', 0))
def destdir_join(d1, d2):
if not d1:
return d2
# c:\destdir + c:\prefix must produce c:\destdir\prefix
parts = os.path.splitdrive(d2)
return d1 + parts[1]
def compileall(files):
for f in files:
if destdir is not None:
# f is prefixed by {py_xxxxlib}, both variants are 12 chars
# the key is the middle 10 chars of the prefix
key = f[1:11].upper()
f = f[12:]
ddir = None
fullpath = os.environ['MESON_INSTALL_DESTDIR_'+key] + f
f = os.environ['MESON_INSTALL_'+key] + f
if fullpath != f:
ddir = os.path.dirname(f)
fullpath = destdir_join(destdir, f)
else:
ddir = None
fullpath = f
if os.path.isdir(fullpath):
for root, _, files in os.walk(fullpath):
ddir = os.path.dirname(os.path.splitdrive(f)[0] + root[len(destdir):])
if ddir is not None:
ddir = root.replace(fullpath, f, 1)
for dirf in files:
if dirf.endswith('.py'):
fullpath = os.path.join(root, dirf)

Loading…
Cancel
Save