nopenpilot/SConstruct

433 lines
11 KiB
Python
Raw Normal View History

2019-12-13 14:03:08 -07:00
import os
2020-07-14 15:26:01 -06:00
import shutil
2019-12-13 14:03:08 -07:00
import subprocess
import sys
2020-12-18 03:57:05 -07:00
import sysconfig
2020-02-06 14:51:42 -07:00
import platform
2020-11-24 14:53:25 -07:00
import numpy as np
2019-12-13 14:03:08 -07:00
2020-10-01 19:45:44 -06:00
TICI = os.path.isfile('/TICI')
2020-10-21 07:33:00 -06:00
Decider('MD5-timestamp')
2020-10-01 19:45:44 -06:00
2019-12-13 14:03:08 -07:00
AddOption('--test',
action='store_true',
help='build test files')
2021-07-14 18:34:36 -06:00
AddOption('--setup',
action='store_true',
help='build setup and installer files')
2021-05-14 19:20:48 -06:00
AddOption('--kaitai',
action='store_true',
help='Regenerate kaitai struct parsers')
2019-12-13 14:03:08 -07:00
AddOption('--asan',
action='store_true',
help='turn on ASAN')
2021-02-23 17:46:22 -07:00
AddOption('--ubsan',
action='store_true',
help='turn on UBSan')
AddOption('--clazy',
action='store_true',
help='build with clazy')
AddOption('--compile_db',
action='store_true',
help='build clang compilation database')
AddOption('--mpc-generate',
action='store_true',
help='regenerates the mpc sources')
2021-06-07 16:13:57 -06:00
AddOption('--snpe',
action='store_true',
help='use SNPE on PC')
2021-02-23 17:46:22 -07:00
AddOption('--external-sconscript',
action='store',
metavar='FILE',
dest='external_sconscript',
help='add an external SConscript to the build')
2021-07-14 18:34:36 -06:00
AddOption('--no-thneed',
action='store_true',
dest='no_thneed',
help='avoid using thneed')
2020-10-01 19:45:44 -06:00
real_arch = arch = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip()
2020-02-06 14:51:42 -07:00
if platform.system() == "Darwin":
arch = "Darwin"
2020-10-01 19:45:44 -06:00
if arch == "aarch64" and TICI:
2020-05-09 14:01:35 -06:00
arch = "larch64"
2019-12-13 14:03:08 -07:00
2020-10-21 07:33:00 -06:00
USE_WEBCAM = os.getenv("USE_WEBCAM") is not None
2020-05-09 14:01:35 -06:00
2021-02-23 17:46:22 -07:00
lenv = {
"PATH": os.environ['PATH'],
}
2020-05-09 14:01:35 -06:00
if arch == "aarch64" or arch == "larch64":
2021-02-23 17:46:22 -07:00
lenv["LD_LIBRARY_PATH"] = '/data/data/com.termux/files/usr/lib'
2019-12-13 14:03:08 -07:00
2020-05-09 14:01:35 -06:00
if arch == "aarch64":
# android
lenv["ANDROID_DATA"] = os.environ['ANDROID_DATA']
lenv["ANDROID_ROOT"] = os.environ['ANDROID_ROOT']
2019-12-13 14:03:08 -07:00
cpppath = [
"#phonelibs/opencl/include",
]
2020-05-09 14:01:35 -06:00
2019-12-13 14:03:08 -07:00
libpath = [
2021-02-23 17:46:22 -07:00
"/usr/local/lib",
2019-12-13 14:03:08 -07:00
"/usr/lib",
"/system/vendor/lib64",
"/system/comma/usr/lib",
"#phonelibs/nanovg",
]
2020-05-09 14:01:35 -06:00
if arch == "larch64":
2020-07-14 15:26:01 -06:00
libpath += [
"#phonelibs/snpe/larch64",
"#phonelibs/libyuv/larch64/lib",
"/usr/lib/aarch64-linux-gnu"
]
2021-05-14 19:20:48 -06:00
cpppath += [
"#selfdrive/camerad/include",
]
2020-05-09 14:01:35 -06:00
cflags = ["-DQCOM2", "-mcpu=cortex-a57"]
cxxflags = ["-DQCOM2", "-mcpu=cortex-a57"]
rpath = ["/usr/local/lib"]
else:
2020-07-14 15:26:01 -06:00
libpath += [
"#phonelibs/snpe/aarch64",
2020-10-01 19:45:44 -06:00
"#phonelibs/libyuv/lib",
"/system/vendor/lib64"
2020-07-14 15:26:01 -06:00
]
2021-07-14 18:34:36 -06:00
cflags = ["-DQCOM", "-D_USING_LIBCXX", "-mcpu=cortex-a57"]
cxxflags = ["-DQCOM", "-D_USING_LIBCXX", "-mcpu=cortex-a57"]
2020-10-01 19:45:44 -06:00
rpath = []
2019-12-13 14:03:08 -07:00
else:
2020-07-14 15:26:01 -06:00
cflags = []
cxxflags = []
2021-02-23 17:46:22 -07:00
cpppath = []
2020-02-06 14:51:42 -07:00
if arch == "Darwin":
2021-05-14 19:20:48 -06:00
yuv_dir = "mac" if real_arch != "arm64" else "mac_arm64"
2020-02-06 14:51:42 -07:00
libpath = [
2021-05-14 19:20:48 -06:00
f"#phonelibs/libyuv/{yuv_dir}/lib",
2020-02-06 14:51:42 -07:00
"/usr/local/lib",
2021-05-14 19:20:48 -06:00
"/opt/homebrew/lib",
2021-02-23 17:46:22 -07:00
"/usr/local/opt/openssl/lib",
2021-05-14 19:20:48 -06:00
"/opt/homebrew/opt/openssl/lib",
2020-02-06 14:51:42 -07:00
"/System/Library/Frameworks/OpenGL.framework/Libraries",
]
2020-07-14 15:26:01 -06:00
cflags += ["-DGL_SILENCE_DEPRECATION"]
cxxflags += ["-DGL_SILENCE_DEPRECATION"]
2021-05-14 19:20:48 -06:00
cpppath += [
"/opt/homebrew/include",
"/usr/local/opt/openssl/include",
"/opt/homebrew/opt/openssl/include"
]
2020-02-06 14:51:42 -07:00
else:
libpath = [
"#phonelibs/snpe/x86_64-linux-clang",
"#phonelibs/libyuv/x64/lib",
2021-06-07 16:13:57 -06:00
"#phonelibs/mapbox-gl-native-qt/x86_64",
2020-02-06 14:51:42 -07:00
"#cereal",
"#selfdrive/common",
"/usr/lib",
"/usr/local/lib",
]
2019-12-13 14:03:08 -07:00
2020-05-31 14:22:49 -06:00
rpath = [
2020-10-21 07:33:00 -06:00
"phonelibs/snpe/x86_64-linux-clang",
2020-07-14 15:26:01 -06:00
"cereal",
"selfdrive/common"
]
2019-12-13 14:03:08 -07:00
# allows shared libraries to work globally
rpath = [os.path.join(os.getcwd(), x) for x in rpath]
2020-07-14 15:26:01 -06:00
if GetOption('asan'):
2021-02-23 17:46:22 -07:00
ccflags = ["-fsanitize=address", "-fno-omit-frame-pointer"]
ldflags = ["-fsanitize=address"]
elif GetOption('ubsan'):
ccflags = ["-fsanitize=undefined"]
ldflags = ["-fsanitize=undefined"]
2020-07-14 15:26:01 -06:00
else:
2021-02-23 17:46:22 -07:00
ccflags = []
ldflags = []
2019-12-13 14:03:08 -07:00
2021-05-14 19:20:48 -06:00
# no --as-needed on mac linker
if arch != "Darwin":
ldflags += ["-Wl,--as-needed"]
2021-08-22 23:13:11 -06:00
# Enable swaglog include in submodules
cflags += ["-DSWAGLOG"]
cxxflags += ["-DSWAGLOG"]
2019-12-13 14:03:08 -07:00
# change pythonpath to this
lenv["PYTHONPATH"] = Dir("#").path
env = Environment(
ENV=lenv,
CCFLAGS=[
"-g",
"-fPIC",
"-O2",
2020-07-14 15:26:01 -06:00
"-Wunused",
2020-05-31 14:22:49 -06:00
"-Werror",
2020-10-01 19:45:44 -06:00
"-Wno-unknown-warning-option",
2020-05-31 14:22:49 -06:00
"-Wno-deprecated-register",
2020-10-21 07:33:00 -06:00
"-Wno-register",
2020-05-31 14:22:49 -06:00
"-Wno-inconsistent-missing-override",
2020-10-01 19:45:44 -06:00
"-Wno-c99-designator",
"-Wno-reorder-init-list",
2021-02-23 17:46:22 -07:00
] + cflags + ccflags,
2019-12-13 14:03:08 -07:00
CPPPATH=cpppath + [
"#",
2021-02-23 17:46:22 -07:00
"#phonelibs/catch2/include",
2019-12-13 14:03:08 -07:00
"#phonelibs/bzip2",
"#phonelibs/libyuv/include",
"#phonelibs/openmax/include",
"#phonelibs/json11",
"#phonelibs/curl/include",
"#phonelibs/libgralloc/include",
"#phonelibs/android_frameworks_native/include",
"#phonelibs/android_hardware_libhardware/include",
"#phonelibs/android_system_core/include",
"#phonelibs/linux/include",
"#phonelibs/snpe/include",
2021-06-07 16:13:57 -06:00
"#phonelibs/mapbox-gl-native-qt/include",
2019-12-13 14:03:08 -07:00
"#phonelibs/nanovg",
2021-02-23 17:46:22 -07:00
"#phonelibs/qrcode",
2021-05-14 19:20:48 -06:00
"#phonelibs",
2019-12-13 14:03:08 -07:00
"#cereal",
"#opendbc/can",
],
CC='clang',
CXX='clang++',
2021-02-23 17:46:22 -07:00
LINKFLAGS=ldflags,
2019-12-13 14:03:08 -07:00
RPATH=rpath,
CFLAGS=["-std=gnu11"] + cflags,
2020-10-21 07:33:00 -06:00
CXXFLAGS=["-std=c++1z"] + cxxflags,
2020-07-14 15:26:01 -06:00
LIBPATH=libpath + [
2019-12-13 14:03:08 -07:00
"#cereal",
2020-12-18 03:57:05 -07:00
"#phonelibs",
"#opendbc/can",
2020-11-24 14:53:25 -07:00
"#selfdrive/boardd",
2019-12-13 14:03:08 -07:00
"#selfdrive/common",
2020-11-24 14:53:25 -07:00
],
CYTHONCFILESUFFIX=".cpp",
2020-12-18 03:57:05 -07:00
COMPILATIONDB_USE_ABSPATH=True,
tools=["default", "cython", "compilation_db"],
2019-12-13 14:03:08 -07:00
)
2021-02-23 17:46:22 -07:00
if GetOption('compile_db'):
2020-12-18 03:57:05 -07:00
env.CompilationDatabase('compile_commands.json')
2021-06-07 16:13:57 -06:00
# Setup cache dir
cache_dir = '/data/scons_cache' if TICI else '/tmp/scons_cache'
CacheDir(cache_dir)
Clean(["."], cache_dir)
2019-12-13 14:03:08 -07:00
node_interval = 5
node_count = 0
def progress_function(node):
global node_count
node_count += node_interval
sys.stderr.write("progress: %d\n" % node_count)
if os.environ.get('SCONS_PROGRESS'):
Progress(progress_function, interval=node_interval)
SHARED = False
def abspath(x):
if arch == 'aarch64':
pth = os.path.join("/data/pythonpath", x[0].path)
env.Depends(pth, x)
return File(pth)
else:
# rpath works elsewhere
return x[0].path.rsplit("/", 1)[1][:-3]
2020-12-18 03:57:05 -07:00
# Cython build enviroment
py_include = sysconfig.get_paths()['include']
2020-11-24 14:53:25 -07:00
envCython = env.Clone()
2020-12-18 03:57:05 -07:00
envCython["CPPPATH"] += [py_include, np.get_include()]
2020-11-24 14:53:25 -07:00
envCython["CCFLAGS"] += ["-Wno-#warnings", "-Wno-deprecated-declarations"]
2020-12-18 03:57:05 -07:00
envCython["LIBS"] = []
2020-11-24 14:53:25 -07:00
if arch == "Darwin":
2020-12-18 03:57:05 -07:00
envCython["LINKFLAGS"] = ["-bundle", "-undefined", "dynamic_lookup"]
2020-11-24 14:53:25 -07:00
elif arch == "aarch64":
2020-12-18 03:57:05 -07:00
envCython["LINKFLAGS"] = ["-shared"]
envCython["LIBS"] = [os.path.basename(py_include)]
2020-11-24 14:53:25 -07:00
else:
2020-12-18 03:57:05 -07:00
envCython["LINKFLAGS"] = ["-pthread", "-shared"]
2020-11-24 14:53:25 -07:00
Export('envCython')
2021-02-23 17:46:22 -07:00
# Qt build environment
2021-03-29 17:54:22 -06:00
qt_env = env.Clone()
2021-06-07 16:13:57 -06:00
qt_modules = ["Widgets", "Gui", "Core", "Network", "Concurrent", "Multimedia", "Quick", "Qml", "QuickWidgets", "Location", "Positioning"]
2021-03-29 17:54:22 -06:00
if arch != "aarch64":
qt_modules += ["DBus"]
2021-02-23 17:46:22 -07:00
2021-03-29 17:54:22 -06:00
qt_libs = []
if arch == "Darwin":
2021-05-14 19:20:48 -06:00
if real_arch == "arm64":
qt_env['QTDIR'] = "/opt/homebrew/opt/qt@5"
else:
qt_env['QTDIR'] = "/usr/local/opt/qt@5"
2021-03-29 17:54:22 -06:00
qt_dirs = [
os.path.join(qt_env['QTDIR'], "include"),
]
qt_dirs += [f"{qt_env['QTDIR']}/include/Qt{m}" for m in qt_modules]
qt_env["LINKFLAGS"] += ["-F" + os.path.join(qt_env['QTDIR'], "lib")]
qt_env["FRAMEWORKS"] += [f"Qt{m}" for m in qt_modules] + ["OpenGL"]
elif arch == "aarch64":
qt_env['QTDIR'] = "/system/comma/usr"
qt_dirs = [
f"/system/comma/usr/include/qt",
]
qt_dirs += [f"/system/comma/usr/include/qt/Qt{m}" for m in qt_modules]
2021-02-23 17:46:22 -07:00
2021-03-29 17:54:22 -06:00
qt_libs = [f"Qt5{m}" for m in qt_modules]
qt_libs += ['EGL', 'GLESv3', 'c++_shared']
else:
qt_env['QTDIR'] = "/usr"
qt_dirs = [
f"/usr/include/{real_arch}-linux-gnu/qt5",
f"/usr/include/{real_arch}-linux-gnu/qt5/QtGui/5.12.8/QtGui",
2021-02-23 17:46:22 -07:00
]
2021-03-29 17:54:22 -06:00
qt_dirs += [f"/usr/include/{real_arch}-linux-gnu/qt5/Qt{m}" for m in qt_modules]
qt_libs = [f"Qt5{m}" for m in qt_modules]
if arch == "larch64":
qt_libs += ["GLESv2", "wayland-client"]
elif arch != "Darwin":
qt_libs += ["GL"]
qt_env.Tool('qt')
qt_env['CPPPATH'] += qt_dirs + ["#selfdrive/ui/qt/"]
qt_flags = [
"-D_REENTRANT",
"-DQT_NO_DEBUG",
"-DQT_WIDGETS_LIB",
"-DQT_GUI_LIB",
"-DQT_QUICK_LIB",
"-DQT_QUICKWIDGETS_LIB",
"-DQT_QML_LIB",
2021-07-14 18:34:36 -06:00
"-DQT_CORE_LIB",
"-DQT_MESSAGELOGCONTEXT",
2021-03-29 17:54:22 -06:00
]
qt_env['CXXFLAGS'] += qt_flags
qt_env['LIBPATH'] += ['#selfdrive/ui']
qt_env['LIBS'] = qt_libs
if GetOption("clazy"):
checks = [
"level0",
"level1",
"no-range-loop",
"no-non-pod-global-static",
]
qt_env['CXX'] = 'clazy'
qt_env['ENV']['CLAZY_IGNORE_DIRS'] = qt_dirs[0]
qt_env['ENV']['CLAZY_CHECKS'] = ','.join(checks)
2021-02-23 17:46:22 -07:00
2021-06-07 16:13:57 -06:00
Export('env', 'qt_env', 'arch', 'real_arch', 'SHARED', 'USE_WEBCAM')
2019-12-13 14:03:08 -07:00
2021-08-22 23:13:11 -06:00
SConscript(['selfdrive/common/SConscript'])
Import('_common', '_gpucommon', '_gpu_libs')
if SHARED:
common, gpucommon = abspath(common), abspath(gpucommon)
else:
common = [_common, 'json11']
gpucommon = [_gpucommon] + _gpu_libs
Export('common', 'gpucommon')
2019-12-13 14:03:08 -07:00
# cereal and messaging are shared with the system
SConscript(['cereal/SConscript'])
if SHARED:
cereal = abspath([File('cereal/libcereal_shared.so')])
messaging = abspath([File('cereal/libmessaging_shared.so')])
else:
cereal = [File('#cereal/libcereal.a')]
messaging = [File('#cereal/libmessaging.a')]
2021-02-23 17:46:22 -07:00
visionipc = [File('#cereal/libvisionipc.a')]
2021-08-22 23:13:11 -06:00
Export('cereal', 'messaging', 'visionipc')
2021-02-23 17:46:22 -07:00
2021-05-14 19:20:48 -06:00
# Build rednose library and ekf models
rednose_config = {
'generated_folder': '#selfdrive/locationd/models/generated',
'to_build': {
'live': ('#selfdrive/locationd/models/live_kf.py', True, ['live_kf_constants.h']),
'car': ('#selfdrive/locationd/models/car_kf.py', True, []),
},
}
if arch != "aarch64":
rednose_config['to_build'].update({
'gnss': ('#selfdrive/locationd/models/gnss_kf.py', True, []),
'loc_4': ('#selfdrive/locationd/models/loc_kf.py', True, []),
'pos_computer_4': ('#rednose/helpers/lst_sq_computer.py', False, []),
'pos_computer_5': ('#rednose/helpers/lst_sq_computer.py', False, []),
'feature_handler_5': ('#rednose/helpers/feature_handler.py', False, []),
'lane': ('#xx/pipeline/lib/ekf/lane_kf.py', True, []),
})
Export('rednose_config')
SConscript(['rednose/SConscript'])
2021-02-23 17:46:22 -07:00
# Build openpilot
2019-12-13 14:03:08 -07:00
2021-02-23 17:46:22 -07:00
SConscript(['cereal/SConscript'])
2021-03-29 17:54:22 -06:00
SConscript(['panda/board/SConscript'])
2019-12-13 14:03:08 -07:00
SConscript(['opendbc/can/SConscript'])
2021-02-23 17:46:22 -07:00
SConscript(['phonelibs/SConscript'])
2019-12-13 14:03:08 -07:00
SConscript(['common/SConscript'])
SConscript(['common/kalman/SConscript'])
2020-07-14 15:26:01 -06:00
SConscript(['common/transformations/SConscript'])
2019-12-13 14:03:08 -07:00
2020-07-14 15:26:01 -06:00
SConscript(['selfdrive/camerad/SConscript'])
SConscript(['selfdrive/modeld/SConscript'])
2020-02-06 14:51:42 -07:00
2019-12-13 14:03:08 -07:00
SConscript(['selfdrive/controls/lib/cluster/SConscript'])
SConscript(['selfdrive/controls/lib/lateral_mpc/SConscript'])
2021-07-14 18:34:36 -06:00
SConscript(['selfdrive/controls/lib/lead_mpc_lib/SConscript'])
SConscript(['selfdrive/controls/lib/longitudinal_mpc_lib/SConscript'])
2019-12-13 14:03:08 -07:00
SConscript(['selfdrive/boardd/SConscript'])
SConscript(['selfdrive/proclogd/SConscript'])
2020-10-01 19:45:44 -06:00
SConscript(['selfdrive/clocksd/SConscript'])
2019-12-13 14:03:08 -07:00
2020-01-15 15:05:04 -07:00
SConscript(['selfdrive/loggerd/SConscript'])
2020-05-31 14:22:49 -06:00
SConscript(['selfdrive/locationd/SConscript'])
2020-10-01 19:45:44 -06:00
SConscript(['selfdrive/sensord/SConscript'])
SConscript(['selfdrive/ui/SConscript'])
2020-05-31 14:22:49 -06:00
2020-10-01 19:45:44 -06:00
if arch != "Darwin":
2019-12-13 14:03:08 -07:00
SConscript(['selfdrive/logcatd/SConscript'])
2020-10-01 19:45:44 -06:00
2021-02-23 17:46:22 -07:00
external_sconscript = GetOption('external_sconscript')
if external_sconscript:
SConscript([external_sconscript])