mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
Issue #5309: distutils' build and build_ext commands now accept a `-j
`
option to enable parallel building of extension modules.
This commit is contained in:
parent
7e23d82cec
commit
2c0a916061
6 changed files with 117 additions and 28 deletions
|
@ -37,6 +37,9 @@ class BuildExtTestCase(TempdirManager,
|
|||
from distutils.command import build_ext
|
||||
build_ext.USER_BASE = site.USER_BASE
|
||||
|
||||
def build_ext(self, *args, **kwargs):
|
||||
return build_ext(*args, **kwargs)
|
||||
|
||||
def test_build_ext(self):
|
||||
global ALREADY_TESTED
|
||||
copy_xxmodule_c(self.tmp_dir)
|
||||
|
@ -44,7 +47,7 @@ class BuildExtTestCase(TempdirManager,
|
|||
xx_ext = Extension('xx', [xx_c])
|
||||
dist = Distribution({'name': 'xx', 'ext_modules': [xx_ext]})
|
||||
dist.package_dir = self.tmp_dir
|
||||
cmd = build_ext(dist)
|
||||
cmd = self.build_ext(dist)
|
||||
fixup_build_ext(cmd)
|
||||
cmd.build_lib = self.tmp_dir
|
||||
cmd.build_temp = self.tmp_dir
|
||||
|
@ -91,7 +94,7 @@ class BuildExtTestCase(TempdirManager,
|
|||
|
||||
def test_solaris_enable_shared(self):
|
||||
dist = Distribution({'name': 'xx'})
|
||||
cmd = build_ext(dist)
|
||||
cmd = self.build_ext(dist)
|
||||
old = sys.platform
|
||||
|
||||
sys.platform = 'sunos' # fooling finalize_options
|
||||
|
@ -113,7 +116,7 @@ class BuildExtTestCase(TempdirManager,
|
|||
def test_user_site(self):
|
||||
import site
|
||||
dist = Distribution({'name': 'xx'})
|
||||
cmd = build_ext(dist)
|
||||
cmd = self.build_ext(dist)
|
||||
|
||||
# making sure the user option is there
|
||||
options = [name for name, short, lable in
|
||||
|
@ -144,14 +147,14 @@ class BuildExtTestCase(TempdirManager,
|
|||
# with the optional argument.
|
||||
modules = [Extension('foo', ['xxx'], optional=False)]
|
||||
dist = Distribution({'name': 'xx', 'ext_modules': modules})
|
||||
cmd = build_ext(dist)
|
||||
cmd = self.build_ext(dist)
|
||||
cmd.ensure_finalized()
|
||||
self.assertRaises((UnknownFileError, CompileError),
|
||||
cmd.run) # should raise an error
|
||||
|
||||
modules = [Extension('foo', ['xxx'], optional=True)]
|
||||
dist = Distribution({'name': 'xx', 'ext_modules': modules})
|
||||
cmd = build_ext(dist)
|
||||
cmd = self.build_ext(dist)
|
||||
cmd.ensure_finalized()
|
||||
cmd.run() # should pass
|
||||
|
||||
|
@ -160,7 +163,7 @@ class BuildExtTestCase(TempdirManager,
|
|||
# etc.) are in the include search path.
|
||||
modules = [Extension('foo', ['xxx'], optional=False)]
|
||||
dist = Distribution({'name': 'xx', 'ext_modules': modules})
|
||||
cmd = build_ext(dist)
|
||||
cmd = self.build_ext(dist)
|
||||
cmd.finalize_options()
|
||||
|
||||
from distutils import sysconfig
|
||||
|
@ -172,14 +175,14 @@ class BuildExtTestCase(TempdirManager,
|
|||
|
||||
# make sure cmd.libraries is turned into a list
|
||||
# if it's a string
|
||||
cmd = build_ext(dist)
|
||||
cmd = self.build_ext(dist)
|
||||
cmd.libraries = 'my_lib, other_lib lastlib'
|
||||
cmd.finalize_options()
|
||||
self.assertEqual(cmd.libraries, ['my_lib', 'other_lib', 'lastlib'])
|
||||
|
||||
# make sure cmd.library_dirs is turned into a list
|
||||
# if it's a string
|
||||
cmd = build_ext(dist)
|
||||
cmd = self.build_ext(dist)
|
||||
cmd.library_dirs = 'my_lib_dir%sother_lib_dir' % os.pathsep
|
||||
cmd.finalize_options()
|
||||
self.assertIn('my_lib_dir', cmd.library_dirs)
|
||||
|
@ -187,7 +190,7 @@ class BuildExtTestCase(TempdirManager,
|
|||
|
||||
# make sure rpath is turned into a list
|
||||
# if it's a string
|
||||
cmd = build_ext(dist)
|
||||
cmd = self.build_ext(dist)
|
||||
cmd.rpath = 'one%stwo' % os.pathsep
|
||||
cmd.finalize_options()
|
||||
self.assertEqual(cmd.rpath, ['one', 'two'])
|
||||
|
@ -196,32 +199,32 @@ class BuildExtTestCase(TempdirManager,
|
|||
|
||||
# make sure define is turned into 2-tuples
|
||||
# strings if they are ','-separated strings
|
||||
cmd = build_ext(dist)
|
||||
cmd = self.build_ext(dist)
|
||||
cmd.define = 'one,two'
|
||||
cmd.finalize_options()
|
||||
self.assertEqual(cmd.define, [('one', '1'), ('two', '1')])
|
||||
|
||||
# make sure undef is turned into a list of
|
||||
# strings if they are ','-separated strings
|
||||
cmd = build_ext(dist)
|
||||
cmd = self.build_ext(dist)
|
||||
cmd.undef = 'one,two'
|
||||
cmd.finalize_options()
|
||||
self.assertEqual(cmd.undef, ['one', 'two'])
|
||||
|
||||
# make sure swig_opts is turned into a list
|
||||
cmd = build_ext(dist)
|
||||
cmd = self.build_ext(dist)
|
||||
cmd.swig_opts = None
|
||||
cmd.finalize_options()
|
||||
self.assertEqual(cmd.swig_opts, [])
|
||||
|
||||
cmd = build_ext(dist)
|
||||
cmd = self.build_ext(dist)
|
||||
cmd.swig_opts = '1 2'
|
||||
cmd.finalize_options()
|
||||
self.assertEqual(cmd.swig_opts, ['1', '2'])
|
||||
|
||||
def test_check_extensions_list(self):
|
||||
dist = Distribution()
|
||||
cmd = build_ext(dist)
|
||||
cmd = self.build_ext(dist)
|
||||
cmd.finalize_options()
|
||||
|
||||
#'extensions' option must be a list of Extension instances
|
||||
|
@ -270,7 +273,7 @@ class BuildExtTestCase(TempdirManager,
|
|||
def test_get_source_files(self):
|
||||
modules = [Extension('foo', ['xxx'], optional=False)]
|
||||
dist = Distribution({'name': 'xx', 'ext_modules': modules})
|
||||
cmd = build_ext(dist)
|
||||
cmd = self.build_ext(dist)
|
||||
cmd.ensure_finalized()
|
||||
self.assertEqual(cmd.get_source_files(), ['xxx'])
|
||||
|
||||
|
@ -279,7 +282,7 @@ class BuildExtTestCase(TempdirManager,
|
|||
# should not be overriden by a compiler instance
|
||||
# when the command is run
|
||||
dist = Distribution()
|
||||
cmd = build_ext(dist)
|
||||
cmd = self.build_ext(dist)
|
||||
cmd.compiler = 'unix'
|
||||
cmd.ensure_finalized()
|
||||
cmd.run()
|
||||
|
@ -292,7 +295,7 @@ class BuildExtTestCase(TempdirManager,
|
|||
ext = Extension('foo', [c_file], optional=False)
|
||||
dist = Distribution({'name': 'xx',
|
||||
'ext_modules': [ext]})
|
||||
cmd = build_ext(dist)
|
||||
cmd = self.build_ext(dist)
|
||||
fixup_build_ext(cmd)
|
||||
cmd.ensure_finalized()
|
||||
self.assertEqual(len(cmd.get_outputs()), 1)
|
||||
|
@ -355,7 +358,7 @@ class BuildExtTestCase(TempdirManager,
|
|||
#etree_ext = Extension('lxml.etree', [etree_c])
|
||||
#dist = Distribution({'name': 'lxml', 'ext_modules': [etree_ext]})
|
||||
dist = Distribution()
|
||||
cmd = build_ext(dist)
|
||||
cmd = self.build_ext(dist)
|
||||
cmd.inplace = 1
|
||||
cmd.distribution.package_dir = {'': 'src'}
|
||||
cmd.distribution.packages = ['lxml', 'lxml.html']
|
||||
|
@ -462,7 +465,7 @@ class BuildExtTestCase(TempdirManager,
|
|||
'ext_modules': [deptarget_ext]
|
||||
})
|
||||
dist.package_dir = self.tmp_dir
|
||||
cmd = build_ext(dist)
|
||||
cmd = self.build_ext(dist)
|
||||
cmd.build_lib = self.tmp_dir
|
||||
cmd.build_temp = self.tmp_dir
|
||||
|
||||
|
@ -481,8 +484,19 @@ class BuildExtTestCase(TempdirManager,
|
|||
self.fail("Wrong deployment target during compilation")
|
||||
|
||||
|
||||
class ParallelBuildExtTestCase(BuildExtTestCase):
|
||||
|
||||
def build_ext(self, *args, **kwargs):
|
||||
build_ext = super().build_ext(*args, **kwargs)
|
||||
build_ext.parallel = True
|
||||
return build_ext
|
||||
|
||||
|
||||
def test_suite():
|
||||
return unittest.makeSuite(BuildExtTestCase)
|
||||
suite = unittest.TestSuite()
|
||||
suite.addTest(unittest.makeSuite(BuildExtTestCase))
|
||||
suite.addTest(unittest.makeSuite(ParallelBuildExtTestCase))
|
||||
return suite
|
||||
|
||||
if __name__ == '__main__':
|
||||
support.run_unittest(test_suite())
|
||||
support.run_unittest(__name__)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue