diff --git a/.gitignore b/.gitignore index 2bfd566b..1d65c548 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,6 @@ can/build/ can/obj/ can/packer_pyx.cpp can/parser_pyx.cpp +can/packer_pyx.html +can/parser_pyx.html can/packer_impl.cpp diff --git a/can/SConscript b/can/SConscript index 94a45ea1..8fb0fc8a 100644 --- a/can/SConscript +++ b/can/SConscript @@ -16,12 +16,8 @@ for x in sorted(os.listdir('../')): libdbc = env.SharedLibrary('libdbc', ["dbc.cc", "parser.cc", "packer.cc", "common.cc"]+dbcs, LIBS=["capnp", "kj"]) -# packer -env.Command(['packer_pyx.so'], - [libdbc, 'packer_pyx.pyx', 'packer_pyx_setup.py'], - "cd opendbc/can && python3 packer_pyx_setup.py build_ext --inplace") +# Build packer and parser -# parser -env.Command(['parser_pyx.so'], - [libdbc, cereal, 'parser_pyx_setup.py', 'parser_pyx.pyx', 'common.pxd'], - "cd opendbc/can && python3 parser_pyx_setup.py build_ext --inplace") +env.Command(['packer_pyx.so', 'parser_pyx.so'], + [libdbc, cereal, 'common_pyx_setup.py', 'packer_pyx.pyx', 'parser_pyx.pyx', 'common.pxd'], + "cd opendbc/can && python3 common_pyx_setup.py build_ext --inplace") diff --git a/can/packer_pyx_setup.py b/can/common_pyx_setup.py similarity index 62% rename from can/packer_pyx_setup.py rename to can/common_pyx_setup.py index 1e8c70cd..b071dc36 100644 --- a/can/packer_pyx_setup.py +++ b/can/common_pyx_setup.py @@ -1,12 +1,14 @@ import os -import sysconfig import subprocess +import sysconfig import platform from distutils.core import Extension, setup # pylint: disable=import-error,no-name-in-module from Cython.Build import cythonize from Cython.Distutils import build_ext + +ANNOTATE = os.getenv('ANNOTATE') is not None BASEDIR = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../")) @@ -32,10 +34,8 @@ class BuildExtWithoutPlatformSuffix(build_ext): return get_ext_filename_without_platform_suffix(filename) -sourcefiles = ['packer_pyx.pyx'] extra_compile_args = ["-std=c++14"] ARCH = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip() # pylint: disable=unexpected-keyword-arg - if ARCH == "aarch64": extra_compile_args += ["-Wno-deprecated-register"] @@ -44,22 +44,48 @@ if platform.system() == "Darwin": else: libdbc = "libdbc.so" +extra_link_args = [os.path.join(BASEDIR, 'opendbc', 'can', libdbc)] +include_dirs = [ + BASEDIR, + os.path.join(BASEDIR, 'phonelibs'), +] + +# Build CAN Parser + +setup(name='CAN parser', + cmdclass={'build_ext': BuildExtWithoutPlatformSuffix}, + ext_modules=cythonize( + Extension( + "parser_pyx", + language="c++", + sources=['parser_pyx.pyx'], + extra_compile_args=extra_compile_args, + include_dirs=include_dirs, + extra_link_args=extra_link_args, + ), + annotate=ANNOTATE + ), + nthreads=4, +) + +if platform.system() == "Darwin": + os.system("install_name_tool -change opendbc/can/libdbc.dylib " + BASEDIR + "/opendbc/can/libdbc.dylib parser_pyx.so") + + +# Build CAN Packer + setup(name='CAN packer', cmdclass={'build_ext': BuildExtWithoutPlatformSuffix}, ext_modules=cythonize( Extension( "packer_pyx", language="c++", - sources=sourcefiles, + sources=['packer_pyx.pyx'], extra_compile_args=extra_compile_args, - include_dirs=[ - BASEDIR, - os.path.join(BASEDIR, 'phonelibs'), - ], - extra_link_args=[ - os.path.join(BASEDIR, 'opendbc', 'can', libdbc), - ], - ) + include_dirs=include_dirs, + extra_link_args=extra_link_args, + ), + annotate=ANNOTATE ), nthreads=4, ) diff --git a/can/parser_pyx_setup.py b/can/parser_pyx_setup.py deleted file mode 100644 index 6e4cbd51..00000000 --- a/can/parser_pyx_setup.py +++ /dev/null @@ -1,68 +0,0 @@ -import os -import subprocess -import sysconfig -import platform -from distutils.core import Extension, setup # pylint: disable=import-error,no-name-in-module - -from Cython.Build import cythonize -from Cython.Distutils import build_ext - -BASEDIR = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../")) - - -def get_ext_filename_without_platform_suffix(filename): - name, ext = os.path.splitext(filename) - ext_suffix = sysconfig.get_config_var('EXT_SUFFIX') - - if ext_suffix == ext: - return filename - - ext_suffix = ext_suffix.replace(ext, '') - idx = name.find(ext_suffix) - - if idx == -1: - return filename - else: - return name[:idx] + ext - - -class BuildExtWithoutPlatformSuffix(build_ext): - def get_ext_filename(self, ext_name): - filename = super().get_ext_filename(ext_name) - return get_ext_filename_without_platform_suffix(filename) - - -sourcefiles = ['parser_pyx.pyx'] -extra_compile_args = ["-std=c++14"] -ARCH = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip() # pylint: disable=unexpected-keyword-arg - -if ARCH == "aarch64": - extra_compile_args += ["-Wno-deprecated-register"] - -if platform.system() == "Darwin": - libdbc = "libdbc.dylib" -else: - libdbc = "libdbc.so" - -setup(name='CAN parser', - cmdclass={'build_ext': BuildExtWithoutPlatformSuffix}, - ext_modules=cythonize( - Extension( - "parser_pyx", - language="c++", - sources=sourcefiles, - extra_compile_args=extra_compile_args, - include_dirs=[ - BASEDIR, - os.path.join(BASEDIR, 'phonelibs'), - ], - extra_link_args=[ - os.path.join(BASEDIR, 'opendbc', 'can', libdbc), - ], - ) - ), - nthreads=4, -) - -if platform.system() == "Darwin": - os.system("install_name_tool -change opendbc/can/libdbc.dylib " + BASEDIR + "/opendbc/can/libdbc.dylib parser_pyx.so")