summarylogtreecommitdiffstats
path: root/0001-sysconfig-make-_sysconfigdata.py-relocatable.patch
blob: 19ba00d56d6225959fe9079f0e327b8fb15bb41e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
From 6ca397e7d4776d652e039ed57779ed4d0d4e7898 Mon Sep 17 00:00:00 2001
From: Ray Donnelly <mingw.android@gmail.com>
Date: Thu, 17 Jun 2021 18:51:10 +0530
Subject: [PATCH 001/N] sysconfig: make _sysconfigdata.py relocatable
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Алексей <alexey.pawlow@gmail.com>
Co-authored-by: lovetox <8661218+lovetox@users.noreply.github.com>
---
 Lib/sysconfig.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py
index e3f79bf..45eab2a 100644
--- a/Lib/sysconfig.py
+++ b/Lib/sysconfig.py
@@ -2,6 +2,7 @@
 
 import os
 import sys
+import textwrap
 from os.path import pardir, realpath
 
 __all__ = [
@@ -413,11 +414,30 @@ def _generate_posix_vars():
     os.makedirs(pybuilddir, exist_ok=True)
     destfile = os.path.join(pybuilddir, name + '.py')
 
+    replacement = """
+        keys_to_replace = [
+            'BINDIR', 'BINLIBDEST', 'CONFINCLUDEDIR',
+            'CONFINCLUDEPY', 'DESTDIRS', 'DESTLIB', 'DESTSHARED',
+            'INCLDIRSTOMAKE', 'INCLUDEDIR', 'INCLUDEPY',
+            'LIBDEST', 'LIBDIR', 'LIBPC', 'LIBPL', 'MACHDESTLIB',
+            'MANDIR', 'SCRIPTDIR', 'datarootdir', 'exec_prefix',
+            'TZPATH',
+        ]
+
+        prefix = build_time_vars['BINDIR'][:-4]
+
+        for key in keys_to_replace:
+            value = build_time_vars[key]
+            build_time_vars[key] = value.replace(prefix, sys.prefix)
+    """
+
     with open(destfile, 'w', encoding='utf8') as f:
+        f.write('import sys\n')
         f.write('# system configuration generated and used by'
                 ' the sysconfig module\n')
         f.write('build_time_vars = ')
         pprint.pprint(vars, stream=f)
+        f.write('\n%s' % textwrap.dedent(replacement))
 
     # Create file used for sys.path fixup -- see Modules/getpath.c
     with open('pybuilddir.txt', 'w', encoding='utf8') as f:
-- 
2.33.0