1 env = DefaultEnvironment()
3 env.Append(CPPPATH = ["#../", "#common"])
5 # Build command for building .pb from .proto using protoc
6 def proto_actions(source, target, env, for_signature):
7 dirs = ' '.join(['-I' + env.GetBuildPath(d) for d in env['PROTOCPATH']])
8 return '$PROTOC $PROTOCFLAGS %s -o%s %s' % (dirs, target[0], source[0])
10 proto_file_builder = Builder(generator = proto_actions,
12 src_suffix = '.proto')
13 env.Append(BUILDERS = {'Proto': proto_file_builder})
14 env.SetDefault(PROTOC = 'protoc')
16 # Define the include path to find nanopb.proto
17 env.Append(PROTOCPATH = ['#../generator', '/usr/include', '.'])
19 # Build command for running nanopb generator
21 def nanopb_targets(target, source, env):
22 basename = os.path.splitext(str(source[0]))[0]
23 target.append(basename + '.pb.h')
26 nanopb_file_builder = Builder(action = '$NANOPB_GENERATOR $NANOPB_FLAGS $SOURCE',
29 emitter = nanopb_targets)
30 env.Append(BUILDERS = {'Nanopb': nanopb_file_builder})
31 env.SetDefault(NANOPB_GENERATOR = 'python ' + env.GetBuildPath("#../generator/nanopb_generator.py"))
33 # Combined method to run both protoc and nanopb generator
34 def run_protoc_and_nanopb(env, source):
35 b1 = env.Proto(source)
36 b2 = env.Nanopb(source)
38 env.AddMethod(run_protoc_and_nanopb, "NanopbProto")
40 # Build command that runs a test program and saves the output
41 def run_test_actions(source, target, env, for_signature):
42 cmd = str(source[0]) # Name of binary
44 cmd += ' <' + str(source[1]) # Input file
45 cmd += ' >' + str(target[0])
48 run_test_builder = Builder(generator = run_test_actions,
50 env.Append(BUILDERS = {'RunTest': run_test_builder})
52 # Build command that decodes a message using protoc
53 def decode_actions(source, target, env, for_signature):
54 dirs = ' '.join(['-I' + env.GetBuildPath(d) for d in env['PROTOCPATH']])
55 return '$PROTOC $PROTOCFLAGS %s --decode=%s %s <%s >%s' % (dirs, env['MESSAGE'], source[1], source[0], target[0])
57 decode_builder = Builder(generator = decode_actions,
59 env.Append(BUILDERS = {'Decode': decode_builder})
61 # Build command that asserts that two files be equal
62 def compare_files(target, source, env):
63 data1 = open(str(source[0]), 'rb').read()
64 data2 = open(str(source[1]), 'rb').read()
66 # open(str(target[0]), 'w').write('OK')
69 return "Test failed: %s and %s differ!" % (source[0], source[1])
71 compare_builder = Builder(action = compare_files,
73 env.Append(BUILDERS = {'Compare': compare_builder})
75 # Now include the SConscript files from all subdirectories
76 SConscript(Glob('*/SConscript'), exports = 'env')