Skip to content

Commit 392cafb

Browse files
Port of universal binary support for Mac OSX from python 2.5. This takes away
the need for the out-of-tree universal binary support that was used to build the 2.4.3 installer. Missing here relative to that tree are some changes to IDLE, IMHO those patches aren't appropriate for the 2.4 branch and users are better of using 2.5's IDLE.
1 parent 16ca35a commit 392cafb

52 files changed

Lines changed: 2465 additions & 358 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Lib/distutils/sysconfig.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ def _init_posix():
361361
# MACOSX_DEPLOYMENT_TARGET: configure bases some choices on it so
362362
# it needs to be compatible.
363363
# If it isn't set we set it to the configure-time value
364-
if sys.platform == 'darwin' and g.has_key('CONFIGURE_MACOSX_DEPLOYMENT_TARGET'):
365-
cfg_target = g['CONFIGURE_MACOSX_DEPLOYMENT_TARGET']
364+
if sys.platform == 'darwin' and g.has_key('MACOSX_DEPLOYMENT_TARGET'):
365+
cfg_target = g['MACOSX_DEPLOYMENT_TARGET']
366366
cur_target = os.getenv('MACOSX_DEPLOYMENT_TARGET', '')
367367
if cur_target == '':
368368
cur_target = cfg_target
@@ -495,6 +495,24 @@ def get_config_vars(*args):
495495
_config_vars['prefix'] = PREFIX
496496
_config_vars['exec_prefix'] = EXEC_PREFIX
497497

498+
if sys.platform == 'darwin':
499+
kernel_version = os.uname()[2] # Kernel version (8.4.3)
500+
major_version = int(kernel_version.split('.')[0])
501+
502+
if major_version < 8:
503+
# On Mac OS X before 10.4, check if -arch and -isysroot
504+
# are in CFLAGS or LDFLAGS and remove them if they are.
505+
# This is needed when building extensions on a 10.3 system
506+
# using a universal build of python.
507+
for key in ('LDFLAGS', 'BASECFLAGS',
508+
# The values below are derived from the earlier ones,
509+
# but subsitution has been by now.
510+
'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
511+
flags = _config_vars[key]
512+
flags = re.sub('-arch\s+\w+\s', ' ', flags)
513+
flags = re.sub('-isysroot [^ \t]*', ' ', flags)
514+
_config_vars[key] = flags
515+
498516
if args:
499517
vals = []
500518
for name in args:

Lib/distutils/unixccompiler.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,49 @@
4242
# should just happily stuff them into the preprocessor/compiler/linker
4343
# options and carry on.
4444

45+
def _darwin_compiler_fixup(compiler_so, cc_args):
46+
"""
47+
This function will strip '-isysroot PATH' and '-arch ARCH' from the
48+
compile flag if the user has specified one of them in extra_compile_flags.
49+
50+
This is needed because '-arch ARCH' adds another architecture to the
51+
build, without a way to remove an architecture. Furthermore GCC will
52+
barf if multiple '-isysroot' arguments are present.
53+
"""
54+
stripArch = stripSysroot = 0
55+
56+
compiler_so = list(compiler_so)
57+
kernel_version = os.uname()[2] # 8.4.3
58+
major_version = int(kernel_version.split('.')[0])
59+
60+
if major_version < 8:
61+
# OSX before 10.4.0, these don't support -arch and -isysroot at
62+
# all.
63+
stripArch = stripSysroot = True
64+
else:
65+
stripArch = '-arch' in cc_args
66+
stripSysroot = '-isysroot' in cc_args
67+
68+
if stripArch:
69+
while 1:
70+
try:
71+
index = compiler_so.index('-arch')
72+
# Strip this argument and the next one:
73+
del compiler_so[index:index+2]
74+
except ValueError:
75+
break
76+
77+
if stripSysroot:
78+
try:
79+
index = compiler_so.index('-isysroot')
80+
# Strip this argument and the next one:
81+
del compiler_so[index:index+2]
82+
except ValueError:
83+
pass
84+
85+
return compiler_so
86+
87+
4588
class UnixCCompiler(CCompiler):
4689

4790
compiler_type = 'unix'
@@ -108,8 +151,11 @@ def preprocess(self, source,
108151
raise CompileError, msg
109152

110153
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
154+
compiler_so = self.compiler_so
155+
if sys.platform == 'darwin':
156+
compiler_so = _darwin_compiler_fixup(compiler_so, cc_args + extra_postargs)
111157
try:
112-
self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
158+
self.spawn(compiler_so + cc_args + [src, '-o', obj] +
113159
extra_postargs)
114160
except DistutilsExecError, msg:
115161
raise CompileError, msg
@@ -173,6 +219,10 @@ def link(self, target_desc, objects,
173219
linker = self.linker_so[:]
174220
if target_lang == "c++" and self.compiler_cxx:
175221
linker[0] = self.compiler_cxx[0]
222+
223+
if sys.platform == 'darwin':
224+
linker = _darwin_compiler_fixup(linker, ld_args)
225+
176226
self.spawn(linker + ld_args)
177227
except DistutilsExecError, msg:
178228
raise LinkError, msg

Lib/distutils/util.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,55 @@ def get_platform ():
6767
m = rel_re.match(release)
6868
if m:
6969
release = m.group()
70+
elif osname[:6] == "darwin":
71+
#
72+
# For our purposes, we'll assume that the system version from
73+
# distutils' perspective is what MACOSX_DEPLOYMENT_TARGET is set
74+
# to. This makes the compatibility story a bit more sane because the
75+
# machine is going to compile and link as if it were
76+
# MACOSX_DEPLOYMENT_TARGET.
77+
from distutils.sysconfig import get_config_vars
78+
cfgvars = get_config_vars()
79+
80+
macver = os.environ.get('MACOSX_DEPLOYMENT_TARGET')
81+
if not macver:
82+
macver = cfgvars.get('MACOSX_DEPLOYMENT_TARGET')
83+
84+
if not macver:
85+
# Get the system version. Reading this plist is a documented
86+
# way to get the system version (see the documentation for
87+
# the Gestalt Manager)
88+
try:
89+
f = open('/System/Library/CoreServices/SystemVersion.plist')
90+
except IOError:
91+
# We're on a plain darwin box, fall back to the default
92+
# behaviour.
93+
pass
94+
else:
95+
m = re.search(
96+
r'<key>ProductUserVisibleVersion</key>\s*' +
97+
r'<string>(.*?)</string>', f.read())
98+
f.close()
99+
if m is not None:
100+
macver = '.'.join(m.group(1).split('.')[:2])
101+
# else: fall back to the default behaviour
102+
103+
if macver:
104+
from distutils.sysconfig import get_config_vars
105+
release = macver
106+
osname = 'macosx'
107+
platver = os.uname()[2]
108+
osmajor = int(platver.split('.')[0])
109+
110+
if osmajor >= 8 and \
111+
get_config_vars().get('UNIVERSALSDK', '').strip():
112+
# The universal build will build fat binaries, but not on
113+
# systems before 10.4
114+
machine = 'fat'
115+
116+
elif machine in ('PowerPC', 'Power_Macintosh'):
117+
# Pick a sane name for the PPC architecture
118+
machine = 'ppc'
70119

71120
return "%s-%s-%s" % (osname, release, machine)
72121

Lib/idlelib/EditorWindow.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,16 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
6565
'Python%d%d.chm' % sys.version_info[:2])
6666
if os.path.isfile(chmfile):
6767
dochome = chmfile
68+
69+
elif sys.platform == 'darwin':
70+
dochome = os.path.join(sys.prefix,
71+
'Resources/English.lproj/Documentation/index.html')
6872
dochome = os.path.normpath(dochome)
6973
if os.path.isfile(dochome):
7074
EditorWindow.help_url = dochome
75+
if sys.platform == 'darwin':
76+
# Safari requires real file:-URLs
77+
EditorWindow.help_url = 'file://' + EditorWindow.help_url
7178
else:
7279
EditorWindow.help_url = "http://www.python.org/doc/current"
7380
currentTheme=idleConf.CurrentTheme()

Lib/plat-mac/buildtools.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,15 @@ def process_common_macho(template, progress, code, rsrcname, destname, is_update
293293
dft_icnsname = os.path.join(sys.prefix, 'Resources/Python.app/Contents/Resources/PythonApplet.icns')
294294
if os.path.exists(dft_icnsname):
295295
icnsname = dft_icnsname
296+
else:
297+
# This part will work when we're in the build environment
298+
import __main__
299+
dft_icnsname = os.path.join(
300+
os.path.dirname(__main__.__file__),
301+
'PythonApplet.icns')
302+
if os.paht.exists(dft_icnsname):
303+
icnsname = dft_icnsname
304+
296305
if not os.path.exists(rsrcname):
297306
rsrcname = None
298307
if progress:

Lib/platform.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,8 @@ def mac_ver(release='',versioninfo=('','',''),machine=''):
601601
versioninfo = (version,stage,nonrel)
602602
if sysa:
603603
machine = {0x1: '68k',
604-
0x2: 'PowerPC'}.get(sysa,'')
604+
0x2: 'PowerPC',
605+
0xa: 'i386'}.get(sysa,'')
605606
return release,versioninfo,machine
606607

607608
def _java_getprop(name,default):

Lib/test/test_applesingle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
dataforkdata = 'hello\r\0world\n'
1616
resourceforkdata = 'goodbye\ncruel\0world\r'
1717

18-
applesingledata = struct.pack("ll16sh", AS_MAGIC, AS_VERSION, "foo", 2) + \
19-
struct.pack("llllll", 1, 50, len(dataforkdata),
18+
applesingledata = struct.pack(">ll16sh", AS_MAGIC, AS_VERSION, "foo", 2) + \
19+
struct.pack(">llllll", 1, 50, len(dataforkdata),
2020
2, 50+len(dataforkdata), len(resourceforkdata)) + \
2121
dataforkdata + \
2222
resourceforkdata

Mac/BuildScript/README.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Building a MacPython distribution
2+
=================================
3+
4+
The ``build-install.py`` script creates MacPython distributions, including
5+
sleepycat db4, sqlite3 and readline support. It builds a complete
6+
framework-based Python out-of-tree, installs it in a funny place with
7+
$DESTROOT, massages that installation to remove .pyc files and such, creates
8+
an Installer package from the installation plus other files in ``resources``
9+
and ``scripts`` and placed that on a ``.dmg`` disk image.
10+
11+
Here are the steps you ned to follow to build a MacPython installer:
12+
13+
- Run ``./build-installer.py``. Optionally you can pass a number of arguments
14+
to specify locations of various files. Please see the top of
15+
``build-installer.py`` for its usage.
16+
- When done the script will tell you where the DMG image is.
17+
18+
The script needs to be run on Mac OS X 10.4 with Xcode 2.2 or later and
19+
the 10.4u SDK.
20+
21+
When all is done, announcements can be posted to at least the following
22+
places:
23+
- pythonmac-sig@python.org
24+
- python-dev@python.org
25+
- python-announce@python.org
26+
- archivist@info-mac.org
27+
- adcnews@apple.com
28+
- news@macnn.com
29+
- http://www.macupdate.com
30+
- http://guide.apple.com/usindex.lasso
31+
- http://www.apple.com/downloads/macosx/submit
32+
- http://www.versiontracker.com/ (userid Jack.Jansen@oratrix.com)
33+
- http://www.macshareware.net (userid jackjansen)
34+
35+
Also, check out Stephan Deibels http://pythonology.org/market contact list

0 commit comments

Comments
 (0)