Add a SCons tool for nanopb protos.
This tool script is useful both for building the tests and also for use in other applications.
This commit is contained in:
@@ -11,42 +11,6 @@ except ImportError:
|
||||
|
||||
def add_nanopb_builders(env):
|
||||
'''Add the necessary builder commands for nanopb tests.'''
|
||||
|
||||
# Build command for building .pb from .proto using protoc
|
||||
def proto_actions(source, target, env, for_signature):
|
||||
esc = env['ESCAPE']
|
||||
dirs = ' '.join(['-I' + esc(env.GetBuildPath(d)) for d in env['PROTOCPATH']])
|
||||
return '$PROTOC $PROTOCFLAGS %s -o%s %s' % (dirs, esc(str(target[0])), esc(str(source[0])))
|
||||
|
||||
proto_file_builder = Builder(generator = proto_actions,
|
||||
suffix = '.pb',
|
||||
src_suffix = '.proto')
|
||||
env.Append(BUILDERS = {'Proto': proto_file_builder})
|
||||
env.SetDefault(PROTOC = 'protoc')
|
||||
env.SetDefault(PROTOCPATH = ['.'])
|
||||
|
||||
# Build command for running nanopb generator
|
||||
import os.path
|
||||
def nanopb_targets(target, source, env):
|
||||
basename = os.path.splitext(str(source[0]))[0]
|
||||
target.append(basename + '.pb.h')
|
||||
return target, source
|
||||
|
||||
nanopb_file_builder = Builder(action = '$NANOPB_GENERATOR $NANOPB_FLAGS $SOURCE',
|
||||
suffix = '.pb.c',
|
||||
src_suffix = '.pb',
|
||||
emitter = nanopb_targets)
|
||||
env.Append(BUILDERS = {'Nanopb': nanopb_file_builder})
|
||||
gen_path = env['ESCAPE'](env.GetBuildPath("#../generator/nanopb_generator.py"))
|
||||
env.SetDefault(NANOPB_GENERATOR = 'python ' + gen_path)
|
||||
env.SetDefault(NANOPB_FLAGS = '-q')
|
||||
|
||||
# Combined method to run both protoc and nanopb generator
|
||||
def run_protoc_and_nanopb(env, source):
|
||||
b1 = env.Proto(source)
|
||||
b2 = env.Nanopb(source)
|
||||
return b1 + b2
|
||||
env.AddMethod(run_protoc_and_nanopb, "NanopbProto")
|
||||
|
||||
# Build command that runs a test program and saves the output
|
||||
def run_test(target, source, env):
|
||||
|
||||
Reference in New Issue
Block a user