SConscript 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Check that alltypes test case works also when the .proto file defines
  2. # a package name using the (nanopb_fileopt).package option.
  3. Import("env")
  4. def set_pkgname(src, dst, pkgname):
  5. data = open(str(src)).read()
  6. placeholder = '// package name placeholder'
  7. assert placeholder in data
  8. data = data.replace(placeholder, 'package foopkg;\n' +
  9. 'import "nanopb.proto";\n' +
  10. 'option (nanopb_fileopt).package="%s";' % pkgname)
  11. open(str(dst), 'w').write(data)
  12. # Build a modified alltypes.proto
  13. env.Command("alltypes.proto", "#alltypes/alltypes.proto",
  14. lambda target, source, env: set_pkgname(source[0], target[0], 'test.package'))
  15. env.Command("alltypes.options", "#alltypes/alltypes.options", Copy("$TARGET", "$SOURCE"))
  16. env.NanopbProto(["alltypes", "alltypes.options"])
  17. # Build a modified encode_alltypes.c
  18. def modify_c(target, source, env):
  19. '''Add package name to type names in .c file.'''
  20. data = open(str(source[0]), 'r').read()
  21. type_names = ['AllTypes', 'MyEnum', 'HugeEnum', 'NonZeroBasedEnum']
  22. for name in type_names:
  23. data = data.replace(name, 'test_package_' + name)
  24. open(str(target[0]), 'w').write(data)
  25. return 0
  26. env.Command("encode_alltypes.c", "#alltypes/encode_alltypes.c", modify_c)
  27. # Encode and compare results to original alltypes testcase
  28. enc = env.Program(["encode_alltypes.c", "alltypes.pb.c", "$COMMON/pb_encode.o", "$COMMON/pb_common.o"])
  29. refdec = "$BUILD/alltypes/decode_alltypes$PROGSUFFIX"
  30. env.RunTest(enc)
  31. env.Compare(["encode_alltypes.output", "$BUILD/alltypes/encode_alltypes.output"])