AP_Scripting: auto-build the bindings

This commit is contained in:
Andrew Tridgell 2020-05-10 19:37:10 +10:00
parent 5c8e4a4d7b
commit 2c6fd13899
6 changed files with 52 additions and 10 deletions

3
libraries/AP_Scripting/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
lua_generated_bindings.cpp
lua_generated_bindings.h

View File

@ -68,8 +68,8 @@ FILE *description;
FILE *header; FILE *header;
FILE *source; FILE *source;
static struct generator_state state = {}; static struct generator_state state;
static struct header * headers = NULL; static struct header * headers;
enum trace_level { enum trace_level {
TRACE_TOKENS = (1 << 0), TRACE_TOKENS = (1 << 0),
@ -321,8 +321,8 @@ struct userdata {
int flags; // flags from the userdata_flags enum int flags; // flags from the userdata_flags enum
}; };
static struct userdata *parsed_userdata = NULL; static struct userdata *parsed_userdata;
static struct userdata *parsed_ap_objects = NULL; static struct userdata *parsed_ap_objects;
struct dependency { struct dependency {
@ -332,7 +332,7 @@ struct dependency {
char *error_msg; // message if the check fails char *error_msg; // message if the check fails
}; };
static struct dependency *parsed_dependencies = NULL; static struct dependency *parsed_dependencies;
// lazy helper that allocates a storage buffer and does strcpy for us // lazy helper that allocates a storage buffer and does strcpy for us
void string_copy(char **dest, const char * src) { void string_copy(char **dest, const char * src) {
@ -1928,7 +1928,7 @@ int main(int argc, char **argv) {
sanity_check_userdata(); sanity_check_userdata();
fprintf(source, "#include \"lua_generated_bindings.h\"\n"); fprintf(source, "#include \"lua_generated_bindings.h\"\n");
fprintf(source, "#include \"lua_boxed_numerics.h\"\n"); fprintf(source, "#include <AP_Scripting/lua_boxed_numerics.h>\n");
trace(TRACE_GENERAL, "Starting emission"); trace(TRACE_GENERAL, "Starting emission");
@ -1980,7 +1980,7 @@ int main(int argc, char **argv) {
fprintf(header, "#pragma once\n"); fprintf(header, "#pragma once\n");
fprintf(header, "// auto generated bindings, don't manually edit. See README.md for details.\n"); fprintf(header, "// auto generated bindings, don't manually edit. See README.md for details.\n");
emit_headers(header); emit_headers(header);
fprintf(header, "#include \"lua/src/lua.hpp\"\n"); fprintf(header, "#include <AP_Scripting/lua/src/lua.hpp>\n");
fprintf(header, "#include <new>\n\n"); fprintf(header, "#include <new>\n\n");
emit_dependencies(header); emit_dependencies(header);
fprintf(header, "\n\n"); fprintf(header, "\n\n");

View File

@ -5,7 +5,7 @@
#include "lua_bindings.h" #include "lua_bindings.h"
#include "lua_boxed_numerics.h" #include "lua_boxed_numerics.h"
#include "lua_generated_bindings.h" #include <AP_Scripting/lua_generated_bindings.h>
extern const AP_HAL::HAL& hal; extern const AP_HAL::HAL& hal;

View File

@ -4,7 +4,7 @@
#include "lua_scripts.h" #include "lua_scripts.h"
#include "lua_generated_bindings.h" #include <AP_Scripting/lua_generated_bindings.h>
#include "lua/src/lua.h" #include "lua/src/lua.h"
#include "lua/src/lauxlib.h" #include "lua/src/lauxlib.h"

View File

@ -18,7 +18,7 @@
#include <GCS_MAVLink/GCS.h> #include <GCS_MAVLink/GCS.h>
#include "AP_Scripting.h" #include "AP_Scripting.h"
#include "lua_generated_bindings.h" #include <AP_Scripting/lua_generated_bindings.h>
#ifndef SCRIPTING_DIRECTORY #ifndef SCRIPTING_DIRECTORY
#if HAL_OS_FATFS_IO #if HAL_OS_FATFS_IO

View File

@ -0,0 +1,39 @@
#!/usr/bin/env python
# encoding: utf-8
'''
build generated bindings from bindings.desc for AP_Scripting
'''
from waflib.TaskGen import after_method, before_method, feature
CFLAGS="-std=c99 -Wno-error=missing-field-initializers -Wall -Werror -Wextra"
CC="gcc"
def configure(cfg):
cfg.env.AP_LIB_EXTRA_SOURCES['AP_Scripting'] = ['lua_generated_bindings.cpp']
def build(bld):
main_c = bld.srcnode.make_node('libraries/AP_Scripting/generator/src/main.c')
gen_bindings = bld.bldnode.find_or_declare('gen-bindings')
bld(
# build gen-bindings compiler
source=main_c,
target=[gen_bindings],
# we should have configure tests for finding the native compiler
rule="%s %s -o %s %s" % (CC, CFLAGS, gen_bindings.abspath(), main_c.abspath()),
group='dynamic_sources',
)
bindings = bld.srcnode.make_node('libraries/AP_Scripting/generator/description/bindings.desc')
gen_bindings = bld.bldnode.find_or_declare('gen-bindings')
generated_cpp = bld.bldnode.find_or_declare('libraries/AP_Scripting/lua_generated_bindings.cpp')
generated_h = bld.bldnode.find_or_declare('libraries/AP_Scripting/lua_generated_bindings.h')
bld(
# build the bindings
source=[bindings, gen_bindings],
rule="./gen-bindings -o libraries/AP_Scripting/lua_generated_bindings -i %s" % (bindings.abspath()),
target=[generated_cpp, generated_h],
group='dynamic_sources',
)