2019-12-03 08:43:05 -08:00
|
|
|
import os
|
|
|
|
import subprocess
|
2020-07-08 14:05:16 -07:00
|
|
|
import sysconfig
|
2019-12-14 19:31:38 -08:00
|
|
|
import platform
|
2019-11-22 21:46:33 -08:00
|
|
|
from distutils.core import Extension, setup # pylint: disable=import-error,no-name-in-module
|
|
|
|
|
|
|
|
from Cython.Build import cythonize
|
2019-12-03 10:45:33 -08:00
|
|
|
from Cython.Distutils import build_ext
|
|
|
|
|
2020-07-08 14:05:16 -07:00
|
|
|
|
|
|
|
ANNOTATE = os.getenv('ANNOTATE') is not None
|
2019-12-03 10:45:33 -08:00
|
|
|
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)
|
2019-11-22 21:46:33 -08:00
|
|
|
|
|
|
|
|
2020-09-09 08:40:14 -07:00
|
|
|
extra_compile_args = ["-std=c++14", "-Wno-nullability-completeness"]
|
2019-12-03 08:43:05 -08:00
|
|
|
ARCH = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip() # pylint: disable=unexpected-keyword-arg
|
|
|
|
if ARCH == "aarch64":
|
|
|
|
extra_compile_args += ["-Wno-deprecated-register"]
|
|
|
|
|
2019-12-14 19:48:56 -08:00
|
|
|
if platform.system() == "Darwin":
|
|
|
|
libdbc = "libdbc.dylib"
|
|
|
|
else:
|
|
|
|
libdbc = "libdbc.so"
|
2019-12-03 08:43:05 -08:00
|
|
|
|
2020-07-08 14:05:16 -07:00
|
|
|
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,
|
|
|
|
),
|
2020-08-02 13:01:37 -07:00
|
|
|
nthreads=4,
|
2020-07-08 14:05:16 -07:00
|
|
|
annotate=ANNOTATE
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2019-12-03 08:43:05 -08:00
|
|
|
setup(name='CAN packer',
|
2019-11-22 21:46:33 -08:00
|
|
|
cmdclass={'build_ext': BuildExtWithoutPlatformSuffix},
|
2019-12-03 08:43:05 -08:00
|
|
|
ext_modules=cythonize(
|
|
|
|
Extension(
|
|
|
|
"packer_pyx",
|
|
|
|
language="c++",
|
2020-07-08 14:05:16 -07:00
|
|
|
sources=['packer_pyx.pyx'],
|
2019-12-03 08:43:05 -08:00
|
|
|
extra_compile_args=extra_compile_args,
|
2020-07-08 14:05:16 -07:00
|
|
|
include_dirs=include_dirs,
|
|
|
|
extra_link_args=extra_link_args,
|
|
|
|
),
|
2020-08-02 13:01:37 -07:00
|
|
|
nthreads=4,
|
2020-07-08 14:05:16 -07:00
|
|
|
annotate=ANNOTATE
|
2019-12-03 08:43:05 -08:00
|
|
|
),
|
|
|
|
)
|
2019-12-14 19:31:38 -08:00
|
|
|
|
|
|
|
if platform.system() == "Darwin":
|
2020-06-01 02:03:03 -07:00
|
|
|
os.system("install_name_tool -change opendbc/can/libdbc.dylib " + BASEDIR + "/opendbc/can/libdbc.dylib packer_pyx.so")
|