]> granicus.if.org Git - python/commitdiff
Issue #15298: fix an OS X bootstrap issue with _sysconfigdata.py.
authorTrent Nelson <trent@trent.me>
Wed, 17 Oct 2012 08:23:50 +0000 (04:23 -0400)
committerTrent Nelson <trent@trent.me>
Wed, 17 Oct 2012 08:23:50 +0000 (04:23 -0400)
Reported by: Ned Deily.

Lib/sysconfig.py

index 41a233bb6f9f88015f780cdb47e9b413e7888223..3450b12d72760082fdc4d404eb78076c72957a40 100644 (file)
@@ -390,18 +390,31 @@ def _generate_posix_vars():
     if _PYTHON_BUILD:
         vars['LDSHARED'] = vars['BLDSHARED']
 
-    pybuilddir = 'build/lib.%s-%s' % (get_platform(), sys.version[:3])
-    if hasattr(sys, "gettotalrefcount"):
-        pybuilddir += '-pydebug'
-    os.makedirs(pybuilddir, exist_ok=True)
-    destfile = os.path.join(pybuilddir, '_sysconfigdata.py')
-
+    # There's a chicken-and-egg situation on OS X with regards to the
+    # _sysconfigdata module after the changes introduced by #15298:
+    # get_config_vars() is called by get_platform() as part of the
+    # `make pybuilddir.txt` target -- which is a precursor to the
+    # _sysconfigdata.py module being constructed.  Unfortunately,
+    # get_config_vars() eventually calls _init_posix(), which attempts
+    # to import _sysconfigdata, which we won't have built yet.  So,
+    # write out _sysconfigdata.py to the current directory first,
+    # then call get_platform() to get the pybuilddir, then move it.
+    destfile = '_sysconfigdata.py'
     with open(destfile, 'w', encoding='utf8') as f:
         f.write('# system configuration generated and used by'
                 ' the sysconfig module\n')
         f.write('build_time_vars = ')
         pprint.pprint(vars, stream=f)
 
+    pybuilddir = 'build/lib.%s-%s' % (get_platform(), sys.version[:3])
+    if hasattr(sys, "gettotalrefcount"):
+        pybuilddir += '-pydebug'
+    os.makedirs(pybuilddir, exist_ok=True)
+    target = os.path.join(pybuilddir, destfile)
+
+    # Relocate _sysconfigdata.py into its final home.
+    os.rename(destfile, target)
+
     # Create file used for sys.path fixup -- see Modules/getpath.c
     with open('pybuilddir.txt', 'w', encoding='ascii') as f:
         f.write(pybuilddir)