Issue #18080: When building a C extension module on OS X, if the comp… · python/cpython@9734568 (original) (raw)

1

1

`"""Tests for distutils.unixccompiler."""

`

``

2

`+

import os

`

2

3

`import sys

`

3

4

`import unittest

`

4

``

`-

from test.support import run_unittest

`

``

5

`+

from test.support import EnvironmentVarGuard, run_unittest

`

5

6

``

6

7

`from distutils import sysconfig

`

7

8

`from distutils.unixccompiler import UnixCCompiler

`

`@@ -94,7 +95,6 @@ def gcv(v):

`

94

95

`sysconfig.get_config_var = gcv

`

95

96

`self.assertEqual(self.cc.rpath_foo(), '-Wl,--enable-new-dtags,-R/foo')

`

96

97

``

97

``

-

98

98

`# non-GCC GNULD

`

99

99

`sys.platform = 'bar'

`

100

100

`def gcv(v):

`

`@@ -115,6 +115,38 @@ def gcv(v):

`

115

115

`sysconfig.get_config_var = gcv

`

116

116

`self.assertEqual(self.cc.rpath_foo(), '-R/foo')

`

117

117

``

``

118

`+

@unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for OS X')

`

``

119

`+

def test_osx_cc_overrides_ldshared(self):

`

``

120

`+

Issue #18080:

`

``

121

`+

ensure that setting CC env variable also changes default linker

`

``

122

`+

def gcv(v):

`

``

123

`+

if v == 'LDSHARED':

`

``

124

`+

return 'gcc-4.2 -bundle -undefined dynamic_lookup '

`

``

125

`+

return 'gcc-4.2'

`

``

126

`+

sysconfig.get_config_var = gcv

`

``

127

`+

with EnvironmentVarGuard() as env:

`

``

128

`+

env['CC'] = 'my_cc'

`

``

129

`+

del env['LDSHARED']

`

``

130

`+

sysconfig.customize_compiler(self.cc)

`

``

131

`+

self.assertEqual(self.cc.linker_so[0], 'my_cc')

`

``

132

+

``

133

`+

@unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for OS X')

`

``

134

`+

def test_osx_explict_ldshared(self):

`

``

135

`+

Issue #18080:

`

``

136

`+

ensure that setting CC env variable does not change

`

``

137

`+

explicit LDSHARED setting for linker

`

``

138

`+

def gcv(v):

`

``

139

`+

if v == 'LDSHARED':

`

``

140

`+

return 'gcc-4.2 -bundle -undefined dynamic_lookup '

`

``

141

`+

return 'gcc-4.2'

`

``

142

`+

sysconfig.get_config_var = gcv

`

``

143

`+

with EnvironmentVarGuard() as env:

`

``

144

`+

env['CC'] = 'my_cc'

`

``

145

`+

env['LDSHARED'] = 'my_ld -bundle -dynamic'

`

``

146

`+

sysconfig.customize_compiler(self.cc)

`

``

147

`+

self.assertEqual(self.cc.linker_so[0], 'my_ld')

`

``

148

+

``

149

+

118

150

`def test_suite():

`

119

151

`return unittest.makeSuite(UnixCCompilerTestCase)

`

120

152

``