1# Test mangle_names option in various configurations. 2# Each sub testcase makes a modified copy of the files in the build directory. 3 4Import('env') 5 6def set_options(setting, value): 7 '''Create options file that sets a nanopb generator option''' 8 def command(target, source, env): 9 with open(str(source[0])) as src, open(str(target[0]), "w") as dst: 10 dst.write("* {}:{}\n".format(setting, value)) 11 dst.write(src.read()) 12 return command 13 14def set_mangling(type): 15 return set_options('mangle_names', type) 16 17# Test type names when M_STRIP_PACKAGE option is used in a single file 18env.Command("strip_package.options", "with_package.options", set_mangling("M_STRIP_PACKAGE")) 19env.Command("strip_package.proto", "with_package.proto", Copy("$TARGET", "$SOURCE")) 20env.NanopbProto(["strip_package", "strip_package.options"]) 21env.Program(["test_strip_package.c", "strip_package.pb.c", '$COMMON/pb_common.o']) 22 23# Test type names with M_STRIP_PACKAGE used in both files 24env.Command("strip_package_a.options", "with_package.options", set_mangling("M_STRIP_PACKAGE")) 25env.Command("strip_package_b.options", "with_package.options", set_mangling("M_STRIP_PACKAGE")) 26env.Command("strip_package_a.proto", "with_package_a.proto", Copy("$TARGET", "$SOURCE")) 27env.Command("strip_package_b.proto", "with_package_b.proto", Copy("$TARGET", "$SOURCE")) 28env.NanopbProto(["strip_package_a", "strip_package_a.options"]) 29env.NanopbProto(["strip_package_b", "strip_package_b.options"]) 30env.Program(["test_strip_package_dependencies.c", "strip_package_a.pb.c", "strip_package_b.pb.c", '$COMMON/pb_common.o']) 31 32# Test type names with M_STRIP_PACKAGE used in file A and (nanopb).package overrides package name in B 33env.Command("replace_package_b.options", "with_package.options", set_options("package", '"ReplacedName"')) 34env.Command("replace_package_b.proto", "with_package_b.proto", Copy("$TARGET", "$SOURCE")) 35env.NanopbProto(["replace_package_b", "replace_package_b.options", "strip_package_a.proto"]) 36env.Program(["test_replace_package.c", "strip_package_a.pb.c", "replace_package_b.pb.c", '$COMMON/pb_common.o']) 37 38# Test M_FLATTEN with a single file 39env.Command("flatten.options", "with_package.options", set_mangling("M_FLATTEN")) 40env.Command("flatten.proto", "with_package.proto", Copy("$TARGET", "$SOURCE")) 41env.NanopbProto(["flatten", "flatten.options"]) 42env.Program(["test_flatten.c", "flatten.pb.c", '$COMMON/pb_common.o']) 43 44# Test M_PACKAGE_INITIALS with a single file 45env.Command("package_initials.options", "with_package.options", set_mangling("M_PACKAGE_INITIALS")) 46env.Command("package_initials.proto", "with_package.proto", Copy("$TARGET", "$SOURCE")) 47env.NanopbProto(["package_initials", "package_initials.options"]) 48env.Program(["test_package_initials.c", "package_initials.pb.c", '$COMMON/pb_common.o']) 49