Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2c12ab1

Browse files
Merged revisions 81662 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r81662 | ronald.oussoren | 2010-06-03 11:47:21 +0200 (Thu, 03 Jun 2010) | 9 lines Fix for issue #7724: ensure that distutils and python's own setup.py honor the MacOSX SDK when one is specified. This is needed to be able to build using the 10.4u SDK while running on OSX 10.6. This is a fixed version of the patch in r80963, I've tested this patch on OSX and Linux. ........
1 parent 1b51272 commit 2c12ab1

2 files changed

Lines changed: 128 additions & 21 deletions

File tree

Lib/distutils/unixccompiler.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
__revision__ = "$Id$"
1717

18-
import os, sys
18+
import os, sys, re
1919

2020
from distutils.dep_util import newer
2121
from distutils.ccompiler import \
@@ -320,10 +320,31 @@ def find_library_file(self, dirs, lib, debug=0):
320320
dylib_f = self.library_filename(lib, lib_type='dylib')
321321
static_f = self.library_filename(lib, lib_type='static')
322322

323+
if sys.platform == 'darwin':
324+
# On OSX users can specify an alternate SDK using
325+
# '-isysroot', calculate the SDK root if it is specified
326+
# (and use it further on)
327+
_sysconfig = __import__('sysconfig')
328+
cflags = _sysconfig.get_config_var('CFLAGS')
329+
m = re.search(r'-isysroot\s+(\S+)', cflags)
330+
if m is None:
331+
sysroot = '/'
332+
else:
333+
sysroot = m.group(1)
334+
335+
336+
323337
for dir in dirs:
324338
shared = os.path.join(dir, shared_f)
325339
dylib = os.path.join(dir, dylib_f)
326340
static = os.path.join(dir, static_f)
341+
342+
if sys.platform == 'darwin' and (
343+
dir.startswith('/System/') or dir.startswith('/usr/')):
344+
shared = os.path.join(sysroot, dir[1:], shared_f)
345+
dylib = os.path.join(sysroot, dir[1:], dylib_f)
346+
static = os.path.join(sysroot, dir[1:], static_f)
347+
327348
# We're second-guessing the linker here, with not much hard
328349
# data to go on: GCC seems to prefer the shared library, so I'm
329350
# assuming that *all* Unix C compilers do. And of course I'm

setup.py

Lines changed: 106 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,25 @@ def add_dir_to_list(dirlist, dir):
2828
if dir is not None and os.path.isdir(dir) and dir not in dirlist:
2929
dirlist.insert(0, dir)
3030

31+
def macosx_sdk_root():
32+
"""
33+
Return the directory of the current OSX SDK,
34+
or '/' if no SDK was specified.
35+
"""
36+
cflags = sysconfig.get_config_var('CFLAGS')
37+
m = re.search(r'-isysroot\s+(\S+)', cflags)
38+
if m is None:
39+
sysroot = '/'
40+
else:
41+
sysroot = m.group(1)
42+
return sysroot
43+
44+
def is_macosx_sdk_path(path):
45+
"""
46+
Returns True if 'path' can be located in an OSX SDK
47+
"""
48+
return path.startswith('/usr/') or path.startswith('/System/')
49+
3150
def find_file(filename, std_dirs, paths):
3251
"""Searches for the directory where a given file is located,
3352
and returns a possibly-empty list of additional directories, or None
@@ -39,15 +58,28 @@ def find_file(filename, std_dirs, paths):
3958
'paths' is a list of additional locations to check; if the file is
4059
found in one of them, the resulting list will contain the directory.
4160
"""
61+
if sys.platform == 'darwin':
62+
# Honor the MacOSX SDK setting when one was specified.
63+
# An SDK is a directory with the same structure as a real
64+
# system, but with only header files and libraries.
65+
sysroot = macosx_sdk_root()
4266

4367
# Check the standard locations
4468
for dir in std_dirs:
4569
f = os.path.join(dir, filename)
70+
71+
if sys.platform == 'darwin' and is_macosx_sdk_path(dir):
72+
f = os.path.join(sysroot, dir[1:], filename)
73+
4674
if os.path.exists(f): return []
4775

4876
# Check the additional directories
4977
for dir in paths:
5078
f = os.path.join(dir, filename)
79+
80+
if sys.platform == 'darwin' and is_macosx_sdk_path(dir):
81+
f = os.path.join(sysroot, dir[1:], filename)
82+
5183
if os.path.exists(f):
5284
return [dir]
5385

@@ -59,11 +91,19 @@ def find_library_file(compiler, libname, std_dirs, paths):
5991
if result is None:
6092
return None
6193

94+
if sys.platform == 'darwin':
95+
sysroot = macosx_sdk_root()
96+
6297
# Check whether the found file is in one of the standard directories
6398
dirname = os.path.dirname(result)
6499
for p in std_dirs:
65100
# Ensure path doesn't end with path separator
66101
p = p.rstrip(os.sep)
102+
103+
if sys.platform == 'darwin' and is_macosx_sdk_path(p):
104+
if os.path.join(sysroot, p[1:]) == dirname:
105+
return [ ]
106+
67107
if p == dirname:
68108
return [ ]
69109

@@ -72,6 +112,11 @@ def find_library_file(compiler, libname, std_dirs, paths):
72112
for p in paths:
73113
# Ensure path doesn't end with path separator
74114
p = p.rstrip(os.sep)
115+
116+
if sys.platform == 'darwin' and is_macosx_sdk_path(p):
117+
if os.path.join(sysroot, p[1:]) == dirname:
118+
return [ p ]
119+
75120
if p == dirname:
76121
return [p]
77122
else:
@@ -497,7 +542,7 @@ def detect_modules(self):
497542
# library and then a static library, instead of first looking
498543
# for dynamic libraries on the entire path.
499544
# This way a staticly linked custom readline gets picked up
500-
# before the (broken) dynamic library in /usr/lib.
545+
# before the (possibly broken) dynamic library in /usr/lib.
501546
readline_extra_link_args = ('-Wl,-search_paths_first',)
502547
else:
503548
readline_extra_link_args = ()
@@ -571,22 +616,23 @@ def detect_modules(self):
571616
openssl_ver = 0
572617
openssl_ver_re = re.compile(
573618
'^\s*#\s*define\s+OPENSSL_VERSION_NUMBER\s+(0x[0-9a-fA-F]+)' )
574-
for ssl_inc_dir in inc_dirs + search_for_ssl_incs_in:
575-
name = os.path.join(ssl_inc_dir, 'openssl', 'opensslv.h')
576-
if os.path.isfile(name):
577-
try:
578-
incfile = open(name, 'r')
579-
for line in incfile:
580-
m = openssl_ver_re.match(line)
581-
if m:
582-
openssl_ver = eval(m.group(1))
583-
break
584-
except IOError:
585-
pass
586619

587-
# first version found is what we'll use (as the compiler should)
588-
if openssl_ver:
589-
break
620+
# look for the openssl version header on the compiler search path.
621+
opensslv_h = find_file('openssl/opensslv.h', [],
622+
inc_dirs + search_for_ssl_incs_in)
623+
if opensslv_h:
624+
name = os.path.join(opensslv_h[0], 'openssl/opensslv.h')
625+
if sys.platform == 'darwin' and is_macosx_sdk_path(name):
626+
name = os.path.join(macosx_sdk_root(), name[1:])
627+
try:
628+
incfile = open(name, 'r')
629+
for line in incfile:
630+
m = openssl_ver_re.match(line)
631+
if m:
632+
openssl_ver = eval(m.group(1))
633+
except IOError as msg:
634+
print("IOError while reading opensshv.h:", msg)
635+
pass
590636

591637
#print('openssl_ver = 0x%08x' % openssl_ver)
592638
min_openssl_ver = 0x00907000
@@ -715,12 +761,18 @@ def gen_db_minor_ver_nums(major):
715761

716762
db_ver_inc_map = {}
717763

764+
if sys.platform == 'darwin':
765+
sysroot = macosx_sdk_root()
766+
718767
class db_found(Exception): pass
719768
try:
720769
# See whether there is a Sleepycat header in the standard
721770
# search path.
722771
for d in inc_dirs + db_inc_paths:
723772
f = os.path.join(d, "db.h")
773+
if sys.platform == 'darwin' and is_macosx_sdk_path(d):
774+
f = os.path.join(sysroot, d[1:], "db.h")
775+
724776
if db_setup_debug: print("db: looking for db.h in", f)
725777
if os.path.exists(f):
726778
f = open(f, "rb").read()
@@ -767,7 +819,22 @@ class db_found(Exception): pass
767819
db_incdir.replace("include", 'lib64'),
768820
db_incdir.replace("include", 'lib'),
769821
]
770-
db_dirs_to_check = list(filter(os.path.isdir, db_dirs_to_check))
822+
823+
if sys.platform != 'darwin':
824+
db_dirs_to_check = list(filter(os.path.isdir, db_dirs_to_check))
825+
826+
else:
827+
# Same as other branch, but takes OSX SDK into account
828+
tmp = []
829+
for dn in db_dirs_to_check:
830+
if is_macosx_sdk_path(dn):
831+
if os.path.isdir(os.path.join(sysroot, dn[1:])):
832+
tmp.append(dn)
833+
else:
834+
if os.path.isdir(dn):
835+
tmp.append(dn)
836+
837+
db_dirs_to_check = tmp
771838

772839
# Look for a version specific db-X.Y before an ambiguoius dbX
773840
# XXX should we -ever- look for a dbX name? Do any
@@ -816,8 +883,15 @@ class db_found(Exception): pass
816883
# Scan the default include directories before the SQLite specific
817884
# ones. This allows one to override the copy of sqlite on OSX,
818885
# where /usr/include contains an old version of sqlite.
886+
if sys.platform == 'darwin':
887+
sysroot = macosx_sdk_root()
888+
819889
for d in inc_dirs + sqlite_inc_paths:
820890
f = os.path.join(d, "sqlite3.h")
891+
892+
if sys.platform == 'darwin' and is_macosx_sdk_path(d):
893+
f = os.path.join(sysroot, d[1:], "sqlite3.h")
894+
821895
if os.path.exists(f):
822896
if sqlite_setup_debug: print("sqlite: found %s"%f)
823897
incf = open(f).read()
@@ -1253,14 +1327,22 @@ def detect_tkinter_darwin(self, inc_dirs, lib_dirs):
12531327
join(os.getenv('HOME'), '/Library/Frameworks')
12541328
]
12551329

1330+
sysroot = macosx_sdk_root()
1331+
12561332
# Find the directory that contains the Tcl.framework and Tk.framework
12571333
# bundles.
12581334
# XXX distutils should support -F!
12591335
for F in framework_dirs:
12601336
# both Tcl.framework and Tk.framework should be present
1337+
1338+
12611339
for fw in 'Tcl', 'Tk':
1262-
if not exists(join(F, fw + '.framework')):
1263-
break
1340+
if is_macosx_sdk_path(F):
1341+
if not exists(join(sysroot, F[1:], fw + '.framework')):
1342+
break
1343+
else:
1344+
if not exists(join(F, fw + '.framework')):
1345+
break
12641346
else:
12651347
# ok, F is now directory with both frameworks. Continure
12661348
# building
@@ -1297,8 +1379,12 @@ def detect_tkinter_darwin(self, inc_dirs, lib_dirs):
12971379

12981380
# Note: cannot use os.popen or subprocess here, that
12991381
# requires extensions that are not available here.
1300-
os.system("file %s/Tk.framework/Tk | grep 'for architecture' > %s"%(F, tmpfile))
1382+
if is_macosx_sdk_path(F):
1383+
os.system("file %s/Tk.framework/Tk | grep 'for architecture' > %s"%(os.path.join(sysroot, F[1:]), tmpfile))
1384+
else:
1385+
os.system("file %s/Tk.framework/Tk | grep 'for architecture' > %s"%(F, tmpfile))
13011386
fp = open(tmpfile)
1387+
13021388
detected_archs = []
13031389
for ln in fp:
13041390
a = ln.split()[-1]

0 commit comments

Comments
 (0)