[Python-checkins] python/dist/src/Mac/OSX fixapplepython23.py, NONE, 1.3.4.1 Makefile, 1.54.4.1, 1.54.4.2

jackjansen at users.sourceforge.net jackjansen at users.sourceforge.net
Thu Jan 6 23:33:58 CET 2005


Update of /cvsroot/python/python/dist/src/Mac/OSX
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2094

Modified Files:
      Tag: release24-maint
	Makefile 
Added Files:
      Tag: release24-maint
	fixapplepython23.py 
Log Message:
Backported from the trunk:
- When doing a frameworkinstall test whether Apple's Python 2.3 may
  need fixing
- Added quotes around destroot arguments.


--- NEW FILE: fixapplepython23.py ---
"""fixapplepython23 - Fix Apple-installed Python 2.3 (on Mac OS X 10.3)

Python 2.3 (and 2.3.X for X<5) have the problem that building an extension
for a framework installation may accidentally pick up the framework
of a newer Python, in stead of the one that was used to build the extension.

This script modifies the Makefile (in .../lib/python2.3/config) to use
the newer method of linking extensions with "-undefined dynamic_lookup"
which fixes this problem.

The script will first check all prerequisites, and return a zero exit
status also when nothing needs to be fixed.
"""
import sys
import os
import gestalt

MAKEFILE='/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/Makefile'
CHANGES=((
    'LDSHARED=\t$(CC) $(LDFLAGS) -bundle -framework $(PYTHONFRAMEWORK)\n',
    'LDSHARED=\t$(CC) $(LDFLAGS) -bundle -undefined dynamic_lookup\n'
    ),(
    'BLDSHARED=\t$(CC) $(LDFLAGS) -bundle -framework $(PYTHONFRAMEWORK)\n',
    'BLDSHARED=\t$(CC) $(LDFLAGS) -bundle -undefined dynamic_lookup\n'
    ),(
    'CC=\t\tgcc\n',
    'CC=\t\t/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/PantherPythonFix/run-gcc\n'
    ),(
    'CXX=\t\tc++\n',
    'CXX=\t\t/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/PantherPythonFix/run-g++\n'
))

GCC_SCRIPT='/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/PantherPythonFix/run-gcc'
GXX_SCRIPT='/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/PantherPythonFix/run-g++'
SCRIPT="""#!/bin/sh
export MACOSX_DEPLOYMENT_TARGET=10.3
exec %s "${@}"
"""

def findline(lines, start):
    """return line starting with given string or -1"""
    for i in range(len(lines)):
        if lines[i][:len(start)] == start:
            return i
    return -1
    
def fix(makefile, do_apply):
    """Fix the Makefile, if required."""
    fixed = False
    lines = open(makefile).readlines()
    
    for old, new in CHANGES:
        i = findline(lines, new)
        if i >= 0:
            # Already fixed
            continue
        i = findline(lines, old)
        if i < 0:
            print 'fixapplepython23: Python installation not fixed (appears broken)'
            print 'fixapplepython23: missing line:', old
            return 2
        lines[i] = new
        fixed = True
       
    if fixed:
        if do_apply:
            print 'fixapplepython23: Fix to Apple-installed Python 2.3 applied'
            os.rename(makefile, makefile + '~')
            open(makefile, 'w').writelines(lines)
            return 0
        else:
            print 'fixapplepython23: Fix to Apple-installed Python 2.3 should be applied'
            return 1
    else:
        print 'fixapplepython23: No fix needed, appears to have been applied before'
        return 0
        
def makescript(filename, compiler):
    """Create a wrapper script for a compiler"""
    dirname = os.path.split(filename)[0]
    if not os.access(dirname, os.X_OK):
        os.mkdir(dirname, 0755)
    fp = open(filename, 'w')
    fp.write(SCRIPT % compiler)
    fp.close()
    os.chmod(filename, 0755)
    print 'fixapplepython23: Created', filename
    
def main():
    # Check for -n option
    if len(sys.argv) > 1 and sys.argv[1] == '-n':
        do_apply = False
    else:
        do_apply = True
    # First check OS version
    if gestalt.gestalt('sysv') < 0x1030:
        print 'fixapplepython23: no fix needed on MacOSX < 10.3'
        sys.exit(0)
    # Test that a framework Python is indeed installed
    if not os.path.exists(MAKEFILE):
        print 'fixapplepython23: Python framework does not appear to be installed (?), nothing fixed'
        sys.exit(0)
    # Check that we can actually write the file
    if do_apply and not os.access(MAKEFILE, os.W_OK):
        print 'fixapplepython23: No write permission, please run with "sudo"'
        sys.exit(2)
    # Create the shell scripts
    if do_apply:
        if not os.access(GCC_SCRIPT, os.X_OK):
            makescript(GCC_SCRIPT, "gcc")
        if not os.access(GXX_SCRIPT, os.X_OK):
            makescript(GXX_SCRIPT, "g++")
    #  Finally fix the makefile
    rv = fix(MAKEFILE, do_apply)
    sys.exit(rv)
    
if __name__ == '__main__':
    main()
    

Index: Makefile
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/OSX/Makefile,v
retrieving revision 1.54.4.1
retrieving revision 1.54.4.2
diff -u -d -r1.54.4.1 -r1.54.4.2
--- Makefile	31 Dec 2004 11:23:20 -0000	1.54.4.1
+++ Makefile	6 Jan 2005 22:33:55 -0000	1.54.4.2
@@ -2,7 +2,7 @@
 # main Makefile. The next couple of variables are overridden on the 
 # commandline in that case.
 
-VERSION=2.5
+VERSION=2.4
 builddir = ../..
 srcdir = ../..
 prefix=/Library/Frameworks/Python.framework/Versions/$(VERSION)
@@ -60,7 +60,7 @@
 bundlebuilder=$(srcdir)/Lib/plat-mac/bundlebuilder.py
 
 installapps: install_PythonLauncher install_Python install_BuildApplet install_IDE \
-	install_IDLE install_PackageManager
+	install_IDLE install_PackageManager checkapplepython
 
 install_PythonLauncher:
 	cd $(srcdir)/Mac/OSX/PythonLauncher/PythonLauncher.pbproj ; \
@@ -120,12 +120,12 @@
 		echo See Mac/OSX/README for details; \
 	else \
 		echo $(BUILDPYTHON) $(srcdir)/Mac/scripts/BuildApplet.py \
-		    --destroot $(DESTDIR) \
+		    --destroot "$(DESTDIR)" \
 			--python $(INSTALLED_PYTHONW) \
 			--output $(DESTDIR)$(PYTHONAPPSDIR)/PythonIDE.app --noargv \
 			$(srcdir)/Mac/Tools/IDE/PythonIDE.py ; \
 		$(BUILDPYTHON) $(srcdir)/Mac/scripts/BuildApplet.py \
-		    --destroot $(DESTDIR) \
+		    --destroot "$(DESTDIR)" \
 			--python $(INSTALLED_PYTHONW) \
 			--output $(DESTDIR)$(PYTHONAPPSDIR)/PythonIDE.app --noargv \
 			$(srcdir)/Mac/Tools/IDE/PythonIDE.py; \
@@ -138,7 +138,7 @@
 	else \
 		echo $(BUILDPYTHON) $(bundlebuilder) \
 			--builddir $(DESTDIR)$(PYTHONAPPSDIR)/ \
-		    --destroot $(DESTDIR) \
+		    --destroot "$(DESTDIR)" \
 			--python $(INSTALLED_PYTHONW) \
 			--resource $(srcdir)/Mac/Tools/IDE/PythonIDE.rsrc \
 			--mainprogram $(srcdir)/Mac/Tools/IDE/PackageManager.py \
@@ -146,7 +146,7 @@
 			--creator Pimp build; \
 		$(BUILDPYTHON) $(bundlebuilder) \
 			--builddir $(DESTDIR)$(PYTHONAPPSDIR)/ \
-		    --destroot $(DESTDIR) \
+		    --destroot "$(DESTDIR)" \
 			--python $(INSTALLED_PYTHONW) \
 			--resource $(srcdir)/Mac/Tools/IDE/PythonIDE.rsrc \
 			--mainprogram $(srcdir)/Mac/Tools/IDE/PackageManager.py \
@@ -161,13 +161,13 @@
 	else \
 		echo $(BUILDPYTHON) $(srcdir)/Mac/scripts/BuildApplet.py \
 			--python $(INSTALLED_PYTHONW) \
-		    --destroot $(DESTDIR) \
+		    --destroot "$(DESTDIR)" \
 			--output $(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app \
 			--extra $(srcdir)/Lib/idlelib \
 			$(srcdir)/Tools/scripts/idle ; \
 		$(BUILDPYTHON) $(srcdir)/Mac/scripts/BuildApplet.py \
 			--python $(INSTALLED_PYTHONW) \
-		    --destroot $(DESTDIR) \
+		    --destroot "$(DESTDIR)" \
 			--output $(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app \
 			--extra $(srcdir)/Lib/idlelib:Contents/Resources/idlelib \
 			$(srcdir)/Tools/scripts/idle ; \
@@ -176,7 +176,7 @@
 
 install_BuildApplet:
 	$(BUILDPYTHON) $(srcdir)/Mac/scripts/BuildApplet.py \
-		--destroot $(DESTDIR) \
+		--destroot "$(DESTDIR)" \
 		--python $(INSTALLED_PYTHONW) \
 		--output $(DESTDIR)$(PYTHONAPPSDIR)/BuildApplet.app \
 		$(srcdir)/Mac/scripts/BuildApplet.py
@@ -264,3 +264,10 @@
 		$(DESTDIR)$(PYTHONAPPSDIR)/Extras/Demo
 	$(BUILDPYTHON) $(srcdir)/Mac/OSX/Extras.install.py $(srcdir)/Tools \
 		$(DESTDIR)$(PYTHONAPPSDIR)/Extras/Tools
+
+checkapplepython:
+	@if ! $(BUILDPYTHON) $(srcdir)/Mac/OSX/fixapplepython23.py -n; then \
+		echo "* WARNING: Apple-installed Python 2.3 will have trouble building extensions from now on."; \
+		echo "* WARNING: Run $(srcdir)/Mac/OSX/fixapplepython23.py with \"sudo\" to fix this."; \
+	fi
+    



More information about the Python-checkins mailing list