@@ -27,6 +27,21 @@ AddOption('--minimal',
2727 default = (not TICI and not release ),
2828 help = 'the minimum build to run openpilot. no tests, tools, etc.' )
2929
30+ submodule_python_paths = [
31+ Dir ("#" ).abspath ,
32+ Dir ("#msgq_repo" ).abspath ,
33+ Dir ("#opendbc_repo" ).abspath ,
34+ Dir ("#rednose_repo" ).abspath ,
35+ Dir ("#teleoprtc_repo" ).abspath ,
36+ Dir ("#tinygrad_repo" ).abspath ,
37+ ]
38+ for p in reversed (submodule_python_paths ):
39+ if p not in sys .path :
40+ sys .path .insert (0 , p )
41+
42+ if external_pythonpath := os .environ .get ("PYTHONPATH" ):
43+ submodule_python_paths += [p for p in external_pythonpath .split (os .pathsep ) if p and p not in submodule_python_paths ]
44+
3045# Detect platform
3146arch = subprocess .check_output (["uname" , "-m" ], encoding = 'utf8' ).rstrip ()
3247if platform .system () == "Darwin" :
@@ -40,9 +55,24 @@ assert arch in [
4055 "Darwin" , # macOS arm64 (x86 not supported)
4156]
4257
43- pkg_names = ['acados' , 'bzip2' , 'capnproto' , 'catch2' , 'eigen' , ' ffmpeg' , 'json11' , 'libjpeg' , 'libyuv ' , 'ncurses' , 'zeromq' , 'zstd' ]
58+ pkg_names = ['acados' , 'bzip2' , 'capnproto' , 'catch2' , 'ffmpeg' , 'json11' , 'ncurses' , 'zeromq' , 'zstd' ]
4459pkgs = [importlib .import_module (name ) for name in pkg_names ]
4560acados = pkgs [pkg_names .index ('acados' )]
61+ ffmpeg = pkgs [pkg_names .index ('ffmpeg' )]
62+ # Shared package ships .so/.dylib; older device venvs still have static .a only.
63+ # Keep static link deps (x264/z/va/drm) when the installed package is static so
64+ # TICI CI works without upgrading the device venv yet.
65+ # TODO: drop the static fallback once device venvs have comma-deps-ffmpeg>=7.1.0.post94
66+ _ffmpeg_lib_names = os .listdir (ffmpeg .LIB_DIR ) if os .path .isdir (ffmpeg .LIB_DIR ) else []
67+ ffmpeg_shared = any (
68+ n .startswith ('libavcodec.so' ) or (n .startswith ('libavcodec' ) and n .endswith ('.dylib' ))
69+ for n in _ffmpeg_lib_names
70+ )
71+ ffmpeg_libs = ['avformat' , 'avcodec' , 'swresample' , 'avutil' ]
72+ if not ffmpeg_shared :
73+ ffmpeg_libs += ['x264' , 'z' ]
74+ if arch != "Darwin" :
75+ ffmpeg_libs += ['va' , 'va-drm' , 'drm' ]
4676acados_include_dirs = [
4777 acados .INCLUDE_DIR ,
4878 os .path .join (acados .INCLUDE_DIR , "blasfeo" , "include" ),
@@ -91,7 +121,7 @@ def _libflags(target, source, env, for_signature):
91121env = Environment (
92122 ENV = {
93123 "PATH" : os .environ ['PATH' ],
94- "PYTHONPATH" : Dir ( "#" ). abspath ,
124+ "PYTHONPATH" : os . pathsep . join ( submodule_python_paths ) ,
95125 "ACADOS_SOURCE_DIR" : acados .DIR ,
96126 "ACADOS_PYTHON_INTERFACE_PATH" : acados .TEMPLATE_DIR ,
97127 "TERA_PATH" : acados .TERA_PATH
@@ -113,7 +143,10 @@ env = Environment(
113143 CXXFLAGS = ["-std=c++1z" ],
114144 CPPPATH = [
115145 "#openpilot" ,
116- "#msgq" ,
146+ "#msgq_repo" , # #include "msgq/..."
147+ "#opendbc_repo" , # #include "opendbc/..."
148+ "#rednose_repo" , # #include "rednose/..."
149+ "#rednose_repo/rednose" , # #include "logger/..." (rednose package root)
117150 "#openpilot/cereal/gen/cpp" ,
118151 acados_include_dirs ,
119152 [x .INCLUDE_DIR for x in pkgs ],
@@ -123,16 +156,21 @@ env = Environment(
123156 "#openpilot/common" ,
124157 "#msgq_repo" ,
125158 "#openpilot/selfdrive/pandad" ,
126- "#rednose/helpers" ,
159+ "#rednose_repo/ rednose/helpers" ,
127160 [x .LIB_DIR for x in pkgs ],
128161 ],
129- RPATH = [],
162+ RPATH = [ffmpeg . LIB_DIR ] if ffmpeg_shared else [ ],
130163 CYTHONCFILESUFFIX = ".cpp" ,
131164 COMPILATIONDB_USE_ABSPATH = True ,
132- REDNOSE_ROOT = "#" ,
165+ REDNOSE_ROOT = "#rednose_repo " ,
133166 tools = ["default" , "cython" , "compilation_db" , "rednose_filter" ],
134167 toolpath = ["#site_scons/site_tools" , "#rednose_repo/site_scons/site_tools" ],
135168)
169+ # SCons' Darwin linker tool doesn't define the variables used to expand RPATH.
170+ if arch == "Darwin" :
171+ env ["RPATHPREFIX" ] = "-Wl,-rpath,"
172+ env ["RPATHSUFFIX" ] = ""
173+ env ["_RPATH" ] = "${_concat(RPATHPREFIX, RPATH, RPATHSUFFIX, __env__)}"
136174if arch != "larch64" :
137175 env ['_LIBFLAGS' ] = _libflags
138176
@@ -192,7 +230,7 @@ else:
192230np_version = SCons .Script .Value (np .__version__ )
193231Export ('envCython' , 'np_version' )
194232
195- Export ('env' , 'arch' , 'acados' )
233+ Export ('env' , 'arch' , 'acados' , 'ffmpeg_libs' )
196234
197235# Setup cache dir
198236cache_dir = '/data/scons_cache' if arch == "larch64" else '/tmp/scons_cache'
@@ -234,7 +272,7 @@ Export('messaging')
234272SConscript (['panda/SConscript' ])
235273
236274# Build rednose library
237- SConscript (['rednose/SConscript' ])
275+ SConscript (['rednose_repo/ rednose/SConscript' ])
238276
239277# Build system services
240278SConscript ([
0 commit comments