summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2022-09-10 17:37:28 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2022-09-10 20:01:27 +0200
commit51c91e98efc5a6ae1ee59f3fff44971a60c7f94d (patch)
tree19adf0f05e084082f9e65eadcf247879f020a3bf
parent4185927983fa5cd4b39887d62628af0056ce2d0b (diff)
build: Add protonium builder.
-rw-r--r--build/env.py1
-rw-r--r--build/scons_tools/tool_protonium.py56
2 files changed, 57 insertions, 0 deletions
diff --git a/build/env.py b/build/env.py
index 082195d..46d069c 100644
--- a/build/env.py
+++ b/build/env.py
@@ -11,6 +11,7 @@ env = Environment(
'tool_firmware',
'tool_jinja2',
'tool_platform_spec',
+ 'tool_protonium',
],
)
diff --git a/build/scons_tools/tool_protonium.py b/build/scons_tools/tool_protonium.py
new file mode 100644
index 0000000..9a6e472
--- /dev/null
+++ b/build/scons_tools/tool_protonium.py
@@ -0,0 +1,56 @@
+from re import sub
+from SCons.Script import *
+
+import pathlib
+import subprocess
+
+def path_translate(env, source):
+ protopath = [pathlib.Path(p) for p in env['PROTOPATH']]
+
+ for p in protopath:
+ f = p / f'{source}.proto'
+
+ if not f.exists():
+ continue
+
+ return str(p / source)
+
+ return source
+
+def Protonium(env, target_dir, sources):
+ return [env.ProtoniumBuild(f'{target_dir}/{source}', path_translate(env, source), PROTOC_OUT_DIR = target_dir) for source in sources]
+ #return [env.ProtoniumBuild(f'{target_dir}/{source}', path_translate(env, source)) for source in sources]
+
+def protonium_builder_actions(source, target, env, for_signature):
+ #target_dir = target[0].Dir('.')
+ target_dir = env['PROTOC_OUT_DIR']
+
+ protoc_path = ' '.join(f'-I{path}' for path in env['PROTOPATH'])
+
+ return f'protoc {protoc_path} $SOURCES --protonium_out={target_dir} --python_out={target_dir} --protonium_python_out={target_dir}'
+
+protonium_builder = Builder(
+ generator = protonium_builder_actions,
+ #action = 'protoc $SOURCES --protonium_out=$TARGET',
+ suffix = '_pb.h',
+ src_suffix = '.proto',
+)
+
+def exists():
+ return subprocess.call('protonium', shell = True, stdout = subprocess.DEVNULL, stderr = subprocess.DEVNULL) == 0
+
+def generate(env):
+ if not exists():
+ return
+
+ protopath = [arg[2:] for arg in subprocess.check_output('pkg-config protobuf --cflags-only-I', shell = True, encoding = 'utf-8').split() if arg.startswith('-I')]
+ protopath += [arg[2:] for arg in subprocess.check_output('protonium --cflags', shell = True, encoding = 'utf-8').split() if arg.startswith('-I')]
+
+ env.Append(
+ BUILDERS = {'ProtoniumBuild': protonium_builder},
+ PROTOPATH = ['.', *protopath],
+ )
+
+ env.ParseConfig('protonium --cflags')
+
+ env.AddMethod(Protonium)