diff --git a/Tools/ardupilotwaf/boards.py b/Tools/ardupilotwaf/boards.py index 08e1325116..f92feeedd0 100644 --- a/Tools/ardupilotwaf/boards.py +++ b/Tools/ardupilotwaf/boards.py @@ -35,6 +35,7 @@ class Board: def configure(self, cfg): cfg.env.TOOLCHAIN = self.toolchain + cfg.env.ROMFS_FILES = [] cfg.load('toolchain') cfg.load('cxx_checks') @@ -191,7 +192,8 @@ class Board: def pre_build(self, bld): '''pre-build hook that gets called before dynamic sources''' - pass + if bld.env.ROMFS_FILES: + self.embed_ROMFS_files(bld) def build(self, bld): bld.ap_version_append_str('GIT_VERSION', bld.git_head_hash(short=True)) @@ -201,6 +203,13 @@ class Board: bld.ap_version_append_int('BUILD_DATE_MONTH', ltime.tm_mon) bld.ap_version_append_int('BUILD_DATE_DAY', ltime.tm_mday) + def embed_ROMFS_files(self, ctx): + '''embed some files using AP_ROMFS''' + import embed + header = ctx.bldnode.make_node('ap_romfs_embedded.h').abspath() + if not embed.create_embedded_h(header, ctx.env.ROMFS_FILES): + bld.fatal("Failed to created ap_romfs_embedded.h") + Board = BoardMeta('Board', Board.__bases__, dict(Board.__dict__)) def add_dynamic_boards(): @@ -262,10 +271,11 @@ class sitl(Board): 'SITL', ] - if cfg.options.enable_osd: - env.LIB += ['sfml-graphics', 'sfml-window','sfml-system'] + if cfg.options.enable_sfml: + if not cfg.check_SFML(env): + cfg.fatal("Failed to find SFML libraries") env.CXXFLAGS += ['-DWITH_SITL_OSD','-DOSD_ENABLED=ENABLED','-DHAL_HAVE_AP_ROMFS_EMBEDDED_H'] - self.embed_files(cfg, [('osd_font.bin','libraries/AP_OSD/fonts/clarity.bin')]) + env.ROMFS_FILES += [('osd_font.bin','libraries/AP_OSD/fonts/clarity.bin')] if sys.platform == 'cygwin': env.LIB += [ @@ -280,15 +290,6 @@ class sitl(Board): '-fno-slp-vectorize' # compiler bug when trying to use SLP ] - def embed_files(self, cfg, files): - '''embed some files using AP_ROMFS''' - header = cfg.bldnode.make_node('sitl/ap_romfs_embedded.h').abspath() - paths = [] - embed_path = cfg.srcnode.make_node('libraries/AP_HAL_ChibiOS/hwdef/scripts').abspath() - sys.path.append(embed_path) - import embed - embed.create_embedded_h(header, files) - class chibios(Board): toolchain = 'arm-none-eabi' @@ -415,6 +416,7 @@ class chibios(Board): def pre_build(self, bld): '''pre-build hook that gets called before dynamic sources''' + super(chibios, self).pre_build(bld) from waflib.Context import load_tool module = load_tool('chibios', [], with_sys_path=True) fun = getattr(module, 'pre_build', None) diff --git a/Tools/ardupilotwaf/chibios.py b/Tools/ardupilotwaf/chibios.py index 2733adbbba..288ff8993a 100644 --- a/Tools/ardupilotwaf/chibios.py +++ b/Tools/ardupilotwaf/chibios.py @@ -198,6 +198,9 @@ def load_env_vars(env): e = pickle.load(open(env_py, 'rb')) for k in e.keys(): v = e[k] + if k == 'ROMFS_FILES': + env.ROMFS_FILES += v + continue if k in env: if isinstance(env[k], dict): a = v.split('=') diff --git a/Tools/ardupilotwaf/cxx_checks.py b/Tools/ardupilotwaf/cxx_checks.py index 7444896880..274a8a7346 100644 --- a/Tools/ardupilotwaf/cxx_checks.py +++ b/Tools/ardupilotwaf/cxx_checks.py @@ -223,3 +223,25 @@ def check_libdl(cfg, env): if ret: env.LIB += cfg.env['LIB_DL'] return ret + +@conf +def check_SFML(cfg, env): + if not cfg.options.enable_sfml: + cfg.msg("Checking for SFML graphics:", 'disabled', color='YELLOW') + return False + libs = ['sfml-graphics', 'sfml-window','sfml-system'] + for lib in libs: + if not cfg.check(compiler='cxx', lib=lib, mandatory=False, + global_define=True): + return False + + # see if we need Graphics.hpp or Graphics.h + if not cfg.check(compiler='cxx', + fragment='''#include \nint main() {}''', define_name="HAVE_SFML_GRAPHICS_HPP", + msg="Checking for Graphics.hpp", mandatory=False): + if not cfg.check(compiler='cxx', fragment='''#include \nint main() {}''', define_name="HAVE_SFML_GRAPHICS_H", + msg="Checking for Graphics.h", mandatory=False): + return False + env.LIB += libs + return True + diff --git a/libraries/AP_HAL_ChibiOS/hwdef/scripts/embed.py b/Tools/ardupilotwaf/embed.py similarity index 78% rename from libraries/AP_HAL_ChibiOS/hwdef/scripts/embed.py rename to Tools/ardupilotwaf/embed.py index 04cc5b04a4..7ac200dde0 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/scripts/embed.py +++ b/Tools/ardupilotwaf/embed.py @@ -1,39 +1,41 @@ #!/usr/bin/env python ''' -script to create embedded.c from a set of static files +script to create ap_romfs_embedded.h from a set of static files Andrew Tridgell May 2017 ''' -import os +import os, sys def write_encode(out, s): out.write(s.encode()) def embed_file(out, f, idx): '''embed one file''' - contents = open(f,'rb').read() + try: + contents = open(f,'rb').read() + except Exception: + print("Failed to embed %s" % f) + return False write_encode(out, 'static const uint8_t ap_romfs_%u[] = {' % idx) for c in bytearray(contents): write_encode(out, '%u,' % c) write_encode(out, '};\n\n'); + return True def create_embedded_h(filename, files): '''create a ap_romfs_embedded.h file''' - this_dir = os.path.realpath(__file__) - rootdir = os.path.relpath(os.path.join(this_dir, "../../../../..")) - out = open(filename, "wb") write_encode(out, '''// generated embedded files for AP_ROMFS\n\n''') for i in range(len(files)): (name, filename) = files[i] - filename = os.path.join(rootdir, filename) - embed_file(out, filename, i) + if not embed_file(out, filename, i): + return False write_encode(out, '''const AP_ROMFS::embedded_file AP_ROMFS::files[] = {\n''') @@ -43,6 +45,7 @@ def create_embedded_h(filename, files): write_encode(out, '{ "%s", sizeof(ap_romfs_%u), ap_romfs_%u },\n' % (name, i, i)) write_encode(out, '};\n') out.close() + return True if __name__ == '__main__': import sys