| 1 |
# Test mangle_names option in various configurations. |
| 2 |
# Each sub testcase makes a modified copy of the files in the build directory. |
| 3 |
|
| 4 |
Import('env') |
| 5 |
|
| 6 |
def 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 |
|
| 14 |
def 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 |
| 18 |
env.Command("strip_package.options", "with_package.options", set_mangling("M_STRIP_PACKAGE")) |
| 19 |
env.Command("strip_package.proto", "with_package.proto", Copy("$TARGET", "$SOURCE")) |
| 20 |
env.NanopbProto(["strip_package", "strip_package.options"]) |
| 21 |
env.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 |
| 24 |
env.Command("strip_package_a.options", "with_package.options", set_mangling("M_STRIP_PACKAGE")) |
| 25 |
env.Command("strip_package_b.options", "with_package.options", set_mangling("M_STRIP_PACKAGE")) |
| 26 |
env.Command("strip_package_a.proto", "with_package_a.proto", Copy("$TARGET", "$SOURCE")) |
| 27 |
env.Command("strip_package_b.proto", "with_package_b.proto", Copy("$TARGET", "$SOURCE")) |
| 28 |
env.NanopbProto(["strip_package_a", "strip_package_a.options"]) |
| 29 |
env.NanopbProto(["strip_package_b", "strip_package_b.options"]) |
| 30 |
env.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 |
| 33 |
env.Command("replace_package_b.options", "with_package.options", set_options("package", '"ReplacedName"')) |
| 34 |
env.Command("replace_package_b.proto", "with_package_b.proto", Copy("$TARGET", "$SOURCE")) |
| 35 |
env.NanopbProto(["replace_package_b", "replace_package_b.options", "strip_package_a.proto"]) |
| 36 |
env.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 |
| 39 |
env.Command("flatten.options", "with_package.options", set_mangling("M_FLATTEN")) |
| 40 |
env.Command("flatten.proto", "with_package.proto", Copy("$TARGET", "$SOURCE")) |
| 41 |
env.NanopbProto(["flatten", "flatten.options"]) |
| 42 |
env.Program(["test_flatten.c", "flatten.pb.c", '$COMMON/pb_common.o']) |
| 43 |
|
| 44 |
# Test M_PACKAGE_INITIALS with a single file |
| 45 |
env.Command("package_initials.options", "with_package.options", set_mangling("M_PACKAGE_INITIALS")) |
| 46 |
env.Command("package_initials.proto", "with_package.proto", Copy("$TARGET", "$SOURCE")) |
| 47 |
env.NanopbProto(["package_initials", "package_initials.options"]) |
| 48 |
env.Program(["test_package_initials.c", "package_initials.pb.c", '$COMMON/pb_common.o']) |