Skip to content

Commit 83381f2

Browse files
mingwandroidAlexpuxlovetox
authored andcommitted
sysconfig: make _sysconfigdata.py relocatable
Co-authored-by: Алексей <[email protected]> Co-authored-by: lovetox <[email protected]>
1 parent 0a3dfa6 commit 83381f2

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Lib/sysconfig/__main__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import sys
3+
import textwrap
34
from sysconfig import (
45
_ALWAYS_STR,
56
_PYTHON_BUILD,
@@ -209,11 +210,32 @@ def _generate_posix_vars():
209210
os.makedirs(pybuilddir, exist_ok=True)
210211
destfile = os.path.join(pybuilddir, name + '.py')
211212

213+
replacement = """
214+
keys_to_replace = [
215+
'BINDIR', 'BINLIBDEST', 'CONFINCLUDEDIR',
216+
'CONFINCLUDEPY', 'DESTDIRS', 'DESTLIB', 'DESTSHARED',
217+
'INCLDIRSTOMAKE', 'INCLUDEDIR', 'INCLUDEPY',
218+
'LIBDEST', 'LIBDIR', 'LIBPC', 'LIBPL', 'MACHDESTLIB',
219+
'MANDIR', 'SCRIPTDIR', 'datarootdir', 'exec_prefix',
220+
'TZPATH', 'AR', 'EXENAME', 'LLVM_PROF_MERGER',
221+
'VENVLAUNCHERDIR',
222+
]
223+
224+
prefix = build_time_vars['BINDIR'][:-4]
225+
build_time_vars['prefix'] = sys.base_prefix
226+
227+
for key in keys_to_replace:
228+
value = build_time_vars[key]
229+
build_time_vars[key] = value.replace(prefix, sys.base_prefix)
230+
"""
231+
212232
with open(destfile, 'w', encoding='utf8') as f:
233+
f.write('import sys\n')
213234
f.write('# system configuration generated and used by'
214235
' the sysconfig module\n')
215236
f.write('build_time_vars = ')
216237
_print_config_dict(vars, stream=f)
238+
f.write('\n%s' % textwrap.dedent(replacement))
217239

218240
# Create file used for sys.path fixup -- see Modules/getpath.c
219241
with open('pybuilddir.txt', 'w', encoding='utf8') as f:

0 commit comments

Comments
 (0)