]> granicus.if.org Git - python/commitdiff
bpo-31955: Fix distutils CCompiler.set_executable() for Unicode (GH-4316)
authorMazay0 <mazay0@gmail.com>
Wed, 8 Nov 2017 15:48:48 +0000 (22:48 +0700)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 8 Nov 2017 15:48:48 +0000 (07:48 -0800)
Fix CCompiler.set_executable() of distutils to handle properly Unicode strings.

Lib/distutils/ccompiler.py
Lib/distutils/tests/test_ccompiler.py
Misc/NEWS.d/next/Library/2017-11-07-19-12-25.bpo-31955.1DWu-S.rst [new file with mode: 0644]

index 62506a6e6ff8246d1a9a0146af0c953db51015f5..88a910c6810ffd5817bfa93136a81febcef486ee 100644 (file)
@@ -160,7 +160,7 @@ class CCompiler:
             self.set_executable(key, args[key])
 
     def set_executable(self, key, value):
-        if isinstance(value, str):
+        if isinstance(value, basestring):
             setattr(self, key, split_quoted(value))
         else:
             setattr(self, key, value)
index 446eac2cda4e2078a9415552e8ec609c5196628e..4976098b8d8027332149f4b449f6ec46d03e4bb5 100644 (file)
@@ -24,6 +24,30 @@ class FakeCompiler(object):
 
 class CCompilerTestCase(support.EnvironGuard, unittest.TestCase):
 
+    def test_set_executables(self):
+        class MyCCompiler(CCompiler):
+            executables = {'compiler': '', 'compiler_cxx': '', 'linker': ''}
+
+        compiler = MyCCompiler()
+
+        # set executable as list
+        compiler.set_executables(compiler=['env', 'OMPI_MPICC=clang', 'mpicc'])
+        self.assertEqual(compiler.compiler, ['env',
+                                             'OMPI_MPICC=clang',
+                                             'mpicc'])
+
+        # set executable as string
+        compiler.set_executables(compiler_cxx='env OMPI_MPICXX=clang++ mpicxx')
+        self.assertEqual(compiler.compiler_cxx, ['env',
+                                                 'OMPI_MPICXX=clang++',
+                                                 'mpicxx'])
+
+        # set executable as unicode string
+        compiler.set_executables(linker=u'env OMPI_MPICXX=clang++ mpiCC')
+        self.assertEqual(compiler.linker, [u'env',
+                                           u'OMPI_MPICXX=clang++',
+                                           u'mpiCC'])
+
     def test_gen_lib_options(self):
         compiler = FakeCompiler()
         libdirs = ['lib1', 'lib2']
diff --git a/Misc/NEWS.d/next/Library/2017-11-07-19-12-25.bpo-31955.1DWu-S.rst b/Misc/NEWS.d/next/Library/2017-11-07-19-12-25.bpo-31955.1DWu-S.rst
new file mode 100644 (file)
index 0000000..62f2449
--- /dev/null
@@ -0,0 +1 @@
+Fix CCompiler.set_executable() of distutils to handle properly Unicode strings.