Updated Branches:
  refs/heads/python-bindings-wip1 [created] f4377ad08

Use a different hack to get CC name.

Get the name of the C compiler by hacking into the innards of distutils
and accessing a non-public var, albeit one which hasn't moved in many
years.  This is slightly less awful than extracting a name from
sysconfig.


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/f1f2ca4c
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/f1f2ca4c
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/f1f2ca4c

Branch: refs/heads/python-bindings-wip1
Commit: f1f2ca4c46998551a683bf3f872549ade67bc193
Parents: 2961103
Author: Marvin Humphrey <[email protected]>
Authored: Fri Apr 5 15:46:11 2013 -0700
Committer: Marvin Humphrey <[email protected]>
Committed: Fri Apr 5 15:46:11 2013 -0700

----------------------------------------------------------------------
 clownfish/compiler/python/setup.py |   28 ++++++++++++++++------------
 1 files changed, 16 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/f1f2ca4c/clownfish/compiler/python/setup.py
----------------------------------------------------------------------
diff --git a/clownfish/compiler/python/setup.py 
b/clownfish/compiler/python/setup.py
index 721a0ed..a54b463 100644
--- a/clownfish/compiler/python/setup.py
+++ b/clownfish/compiler/python/setup.py
@@ -11,26 +11,30 @@ import shutil
 import subprocess
 import sysconfig
 
+# Get a compiler object and and strings representing the compiler type and
+# CFLAGS.
+compiler = distutils.ccompiler.new_compiler()
+cflags = sysconfig.get_config_var('CFLAGS')
+compiler_type = distutils.ccompiler.get_default_compiler()
+
+# There's no public way to get a string representing the compiler executable
+# out of distutils, but the member variable has been in the same place for a
+# long time, so violating encapsulation may be ok.
+compiler_name = " ".join(compiler.compiler)
+
 BASE_DIR = os.path.abspath(os.path.join(os.pardir, os.pardir, os.pardir))
 PARENT_DIR      = os.path.abspath(os.pardir)
 CFC_SOURCE_DIR  = os.path.join(PARENT_DIR, 'src')
 CFC_INCLUDE_DIR = os.path.join(PARENT_DIR, 'include')
 COMMON_SOURCE_DIR    = os.path.join(PARENT_DIR, 'common')
 CHARMONIZER_C        = os.path.join(COMMON_SOURCE_DIR, 'charmonizer.c')
-CHARMONIZER_EXE_NAME = 'charmonizer' + sysconfig.get_config_var("EXE")
+CHARMONIZER_EXE_NAME = compiler.executable_filename('charmonizer')
 CHARMONIZER_EXE_PATH = os.path.join(os.curdir, CHARMONIZER_EXE_NAME)
 CHARMONY_H_PATH      = 'charmony.h'
 LEMON_DIR = os.path.join(BASE_DIR, 'lemon')
-LEMON_EXE_NAME = 'lemon' + sysconfig.get_config_var("EXE")
+LEMON_EXE_NAME = compiler.executable_filename('lemon')
 LEMON_EXE_PATH = os.path.join(LEMON_DIR, LEMON_EXE_NAME)
 
-# There's no good way to get a string representing the compiler executable out
-# of distutils, so for now we'll kludge it and assume it's the same as the
-# compiler used to build python.
-python_compiler = sysconfig.get_config_var('CC')
-cflags = sysconfig.get_config_var('CFLAGS')
-compiler_type   = distutils.ccompiler.get_default_compiler()
-
 def _quotify(text):
     text = text.replace('\\', '\\\\')
     text = text.replace('"', '\\"')
@@ -61,7 +65,7 @@ class charmony(_Command):
     def run(self):
         # Compile charmonizer.
         if newer_group([CHARMONIZER_C], CHARMONIZER_EXE_PATH):
-            command = [python_compiler]
+            command = [compiler_name]
             if compiler_type == 'msvc':
                 command.append('/Fe' + CHARMONIZER_EXE_PATH)
             else:
@@ -74,7 +78,7 @@ class charmony(_Command):
         if newer_group([CHARMONIZER_EXE_PATH], CHARMONY_H_PATH):
             command = [
                 CHARMONIZER_EXE_PATH,
-                '--cc=' + _quotify(python_compiler),
+                '--cc=' + _quotify(compiler_name),
                 '--enable-c',
                 '--',
                 cflags
@@ -93,7 +97,7 @@ class lemon(_Command):
         pass
     def run(self):
         if not os.path.exists(LEMON_EXE_PATH):
-            _run_make(['CC=' + python_compiler], directory=LEMON_DIR)
+            _run_make(['CC=' + _quotify(compiler_name)], directory=LEMON_DIR)
 
 class my_clean(_clean):
     paths_to_clean = [

Reply via email to