critical bugfix for pymod (db plugins failed to import)

Cause: dbInit.cc:133 hardcodes the macos extension for shared libraries ('.dylib'), but setuptools builds it with '.so'.

Current solution: Since the main build's qmake respects the dylib standard, I've adapted setuptools to use '.dylib'.
This commit is contained in:
Thomas Ferreira de Lima 2018-10-09 00:35:28 -04:00
parent 7852634ffa
commit e7ebd88b2c
No known key found for this signature in database
GPG Key ID: 43E98870EAA0A86E
3 changed files with 39 additions and 3 deletions

View File

@ -232,6 +232,7 @@ script:
python setup.py build;
python setup.py bdist_wheel;
python setup.py install;
python test-klayout-db-plugins.py;
mkdir -p deploy/dist-pymod;
cp -a dist/* deploy/dist-pymod/;
python -c 'import klayout.db as db; print(dir(db))';

View File

@ -60,10 +60,10 @@ import os
import platform
import distutils.sysconfig as sysconfig
from distutils.errors import CompileError
import distutils.command.build_ext
import multiprocessing
N_cores = multiprocessing.cpu_count()
# monkey-patch for parallel compilation
# from https://stackoverflow.com/questions/11013851/speeding-up-build-process-with-distutils
def parallelCCompile(self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None, depends=None):
@ -103,6 +103,24 @@ if sys.version_info[0] * 10 + sys.version_info[1] > 26:
import distutils.ccompiler
distutils.ccompiler.CCompiler.compile = parallelCCompile
from distutils.command.build_ext import build_ext
_old_get_ext_filename = build_ext.get_ext_filename
def patched_get_ext_filename(self, ext_name):
r"""Convert the name of an extension (eg. "foo.bar") into the name
of the file from which it will be loaded (eg. "foo/bar.so", or
"foo\bar.pyd").
"""
filename = _old_get_ext_filename(self, ext_name)
# Making sure this matches qmake's default extension .dylib, instead of .so
if platform.system() == "Darwin" and '_dbpi' in ext_name:
filename = filename.replace('.so', '.dylib')
return filename
distutils.command.build_ext.build_ext.get_ext_filename = patched_get_ext_filename
# ----------------------------------------------------------------------------------------
@ -121,6 +139,7 @@ class Config(object):
self.build_platlib = build_cmd.build_platlib
self.ext_suffix = sysconfig.get_config_var("EXT_SUFFIX")
if self.ext_suffix is None:
self.ext_suffix = ".so"
@ -131,7 +150,10 @@ class Config(object):
Returns the library name for a given module
The library name is usually decorated (i.e. "tl" -> "tl.cpython-35m-x86_64-linux-gnu.so").
"""
return mod + self.ext_suffix
ext_suffix = self.ext_suffix
if platform.system() == "Darwin" and '_dbpi' in mod:
ext_suffix = ext_suffix.replace('.so', '.dylib')
return mod + ext_suffix
def path_of(self, mod):
"""
@ -191,7 +213,7 @@ class Config(object):
"""
Gets the version string
"""
return "0.26.0.dev2"
return "0.26.0.dev4"
config = Config()

View File

@ -0,0 +1,13 @@
import klayout.db as kdb
layout = kdb.Layout()
layer1 = layout.layer(kdb.LayerInfo('1/0'))
TOP = layout.create_cell("TOP")
box = kdb.DBox(kdb.DPoint(-4500, -4500), kdb.DPoint(4500, 4500))
TOP.shapes(layer1).insert(box)
layout.write('test.gds')