]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #27048: Prevents distutils failing on Windows when environment variables contai...
authorSteve Dower <steve.dower@microsoft.com>
Fri, 17 Jun 2016 16:32:38 +0000 (09:32 -0700)
committerSteve Dower <steve.dower@microsoft.com>
Fri, 17 Jun 2016 16:32:38 +0000 (09:32 -0700)
Lib/distutils/_msvccompiler.py
Lib/distutils/tests/test_msvccompiler.py
Misc/NEWS

index d0ba7d6d1efc0061d34e92f9695da6e88e53e463..b120273fe9e37e5a1dddee7aa96777946b96e65d 100644 (file)
@@ -86,11 +86,9 @@ def _get_vc_env(plat_spec):
 
     try:
         out = subprocess.check_output(
-            '"{}" {} && set'.format(vcvarsall, plat_spec),
-            shell=True,
+            'cmd /u /c "{}" {} && set'.format(vcvarsall, plat_spec),
             stderr=subprocess.STDOUT,
-            universal_newlines=True,
-        )
+        ).decode('utf-16le', errors='replace')
     except subprocess.CalledProcessError as exc:
         log.error(exc.output)
         raise DistutilsPlatformError("Error executing {}"
index c4d911ff8380e37a2fd98c27d6715d555b78faac..4dc24886c8291e6c82625b598d8278ebf710e143 100644 (file)
@@ -83,6 +83,24 @@ class msvccompilerTestCase(support.TempdirManager,
         self.assertFalse(os.path.isfile(os.path.join(
             tempdir, os.path.basename(dll))))
 
+    def test_get_vc_env_unicode(self):
+        import distutils._msvccompiler as _msvccompiler
+
+        test_var = 'ṰḖṤṪ┅ṼẨṜ'
+        test_value = '₃⁴₅'
+
+        # Ensure we don't early exit from _get_vc_env
+        old_distutils_use_sdk = os.environ.pop('DISTUTILS_USE_SDK', None)
+        os.environ[test_var] = test_value
+        try:
+            env = _msvccompiler._get_vc_env('x86')
+            self.assertIn(test_var.lower(), env)
+            self.assertEqual(test_value, env[test_var.lower()])
+        finally:
+            os.environ.pop(test_var)
+            if old_distutils_use_sdk:
+                os.environ['DISTUTILS_USE_SDK'] = old_distutils_use_sdk
+
 def test_suite():
     return unittest.makeSuite(msvccompilerTestCase)
 
index 66a95f730889f56f28befa7ed7e621b30be792ff..5dff4dbdf5c70acb99e9fe5c2b2f229c8a242341 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #27048: Prevents distutils failing on Windows when environment
+  variables contain non-ASCII characters
+
 - Issue #27330: Fixed possible leaks in the ctypes module.
 
 - Issue #27238: Got rid of bare excepts in the turtle module.  Original patch