Commit c2fcb01d authored by Jason R. Coombs's avatar Jason R. Coombs

Merge branch 'clean' of https://github.com/pypa/distutils into master

parents 5578b446 51b75e95
...@@ -15,7 +15,9 @@ for older versions in distutils.msvc9compiler and distutils.msvccompiler. ...@@ -15,7 +15,9 @@ for older versions in distutils.msvc9compiler and distutils.msvccompiler.
import os import os
import subprocess import subprocess
import winreg import contextlib
with contextlib.suppress(ImportError):
import winreg
from distutils.errors import DistutilsExecError, DistutilsPlatformError, \ from distutils.errors import DistutilsExecError, DistutilsPlatformError, \
CompileError, LibError, LinkError CompileError, LibError, LinkError
...@@ -501,7 +503,7 @@ class MSVCCompiler(CCompiler) : ...@@ -501,7 +503,7 @@ class MSVCCompiler(CCompiler) :
log.debug("skipping %s (up-to-date)", output_filename) log.debug("skipping %s (up-to-date)", output_filename)
def spawn(self, cmd): def spawn(self, cmd):
env = dict(os.environ, path=self._paths) env = dict(os.environ, PATH=self._paths)
return super().spawn(cmd, env=env) return super().spawn(cmd, env=env)
# -- Miscellaneous methods ----------------------------------------- # -- Miscellaneous methods -----------------------------------------
......
...@@ -906,8 +906,8 @@ int main (int argc, char **argv) { ...@@ -906,8 +906,8 @@ int main (int argc, char **argv) {
def execute(self, func, args, msg=None, level=1): def execute(self, func, args, msg=None, level=1):
execute(func, args, msg, self.dry_run) execute(func, args, msg, self.dry_run)
def spawn(self, cmd): def spawn(self, cmd, **kwargs):
spawn(cmd, dry_run=self.dry_run) spawn(cmd, dry_run=self.dry_run, **kwargs)
def move_file(self, src, dst): def move_file(self, src, dst):
return move_file(src, dst, dry_run=self.dry_run) return move_file(src, dst, dry_run=self.dry_run)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import sys import sys
import unittest import unittest
import os import os
import threading
from distutils.errors import DistutilsPlatformError from distutils.errors import DistutilsPlatformError
from distutils.tests import support from distutils.tests import support
...@@ -74,6 +75,42 @@ class msvccompilerTestCase(support.TempdirManager, ...@@ -74,6 +75,42 @@ class msvccompilerTestCase(support.TempdirManager,
else: else:
raise unittest.SkipTest("VS 2015 is not installed") raise unittest.SkipTest("VS 2015 is not installed")
class CheckThread(threading.Thread):
exc_info = None
def run(self):
try:
super().run()
except Exception:
self.exc_info = sys.exc_info()
def __bool__(self):
return not self.exc_info
class TestSpawn(unittest.TestCase):
def test_concurrent_safe(self):
"""
Concurrent calls to spawn should have consistent results.
"""
import distutils._msvccompiler as _msvccompiler
compiler = _msvccompiler.MSVCCompiler()
compiler._paths = "expected"
inner_cmd = 'import os; assert os.environ["PATH"] == "expected"'
command = ['python', '-c', inner_cmd]
threads = [
CheckThread(target=compiler.spawn, args=[command])
for n in range(100)
]
for thread in threads:
thread.start()
for thread in threads:
thread.join()
assert all(threads)
def test_suite(): def test_suite():
return unittest.makeSuite(msvccompilerTestCase) return unittest.makeSuite(msvccompilerTestCase)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment