plugin_protobuffs.mk 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # Protocol buffers plugin.
  2. PROTOBUFFS_TARGETS = $(call list_targets,protobuffs)
  3. .PHONY: protobuffs $(PROTOBUFFS_TARGETS)
  4. protobuffs: $(PROTOBUFFS_TARGETS)
  5. PROTOBUFFS_URL = https://raw.githubusercontent.com/basho/erlang_protobuffs/master/test/erlang_protobuffs_SUITE_data
  6. protobuffs-compile: init
  7. $i "Bootstrap a new OTP library named $(APP)"
  8. $t mkdir $(APP)/
  9. $t cp ../erlang.mk $(APP)/
  10. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  11. $i "Add gpb to the list of dependencies"
  12. $t perl -ni.bak -e 'print;if ($$.==1) {print "BUILD_DEPS = gpb\n"}' $(APP)/Makefile
  13. $i "Download two proto files"
  14. $t mkdir $(APP)/src/proto/
  15. $t curl -s -o $(APP)/src/proto/empty.proto $(PROTOBUFFS_URL)/proto/empty.proto
  16. $t curl -s -o $(APP)/src/proto/simple.proto $(PROTOBUFFS_URL)/proto/simple.proto
  17. $i "Build the application"
  18. $t $(MAKE) -C $(APP) $v
  19. $i "Check that an Erlang module was generated and compiled"
  20. $t test -f $(APP)/src/empty_pb.erl
  21. $t test -f $(APP)/src/simple_pb.erl
  22. $t test -f $(APP)/include/empty_pb.hrl
  23. $t test -f $(APP)/include/simple_pb.hrl
  24. $t test -f $(APP)/ebin/empty_pb.beam
  25. $t test -f $(APP)/ebin/simple_pb.beam
  26. $i "Check that the generated modules are included in .app file"
  27. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  28. ok = application:load($(APP)), \
  29. {ok, [empty_pb, simple_pb]} = application:get_key($(APP), modules), \
  30. halt()"
  31. protobuffs-dont-compile: init
  32. $i "Bootstrap a new OTP library named $(APP)"
  33. $t mkdir $(APP)/
  34. $t cp ../erlang.mk $(APP)/
  35. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  36. $i "Do not add gpb/protobuffs to the list of dependencies"
  37. $i "Download two proto files"
  38. $t mkdir $(APP)/src/proto/
  39. $t curl -s -o $(APP)/src/proto/empty.proto $(PROTOBUFFS_URL)/proto/empty.proto
  40. $t curl -s -o $(APP)/src/proto/simple.proto $(PROTOBUFFS_URL)/proto/simple.proto
  41. $i "Build the application"
  42. $t $(MAKE) -C $(APP) $v
  43. $i "Check that the proto files were ignored"
  44. $t test ! -e $(APP)/src/empty_pb.erl
  45. $t test ! -e $(APP)/src/simple_pb.erl
  46. $t test ! -e $(APP)/include/empty_pb.hrl
  47. $t test ! -e $(APP)/include/simple_pb.hrl
  48. $t test ! -e $(APP)/ebin/empty_pb.beam
  49. $t test ! -e $(APP)/ebin/simple_pb.beam
  50. $i "Check that the application itself was otherwise compiled properly"
  51. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  52. ok = application:load($(APP)), \
  53. {ok, []} = application:get_key($(APP), modules), \
  54. halt()"
  55. protobuffs-makefile-change: init
  56. $i "Bootstrap a new OTP library named $(APP)"
  57. $t mkdir $(APP)/
  58. $t cp ../erlang.mk $(APP)/
  59. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  60. $i "Add protobuffs to the list of dependencies"
  61. $t perl -ni.bak -e 'print;if ($$.==1) {print "BUILD_DEPS = gpb\n"}' $(APP)/Makefile
  62. $i "Download two proto files"
  63. $t mkdir $(APP)/src/proto/
  64. $t curl -s -o $(APP)/src/proto/empty.proto $(PROTOBUFFS_URL)/proto/empty.proto
  65. $t curl -s -o $(APP)/src/proto/simple.proto $(PROTOBUFFS_URL)/proto/simple.proto
  66. $i "Build the application"
  67. $t $(MAKE) -C $(APP) $v
  68. $i "Touch the Makefile; check that all files get rebuilt"
  69. $t printf "%s\n" \
  70. $(APP)/ebin/empty_pb.beam \
  71. $(APP)/ebin/simple_pb.beam \
  72. $(APP)/ebin/$(APP).app \
  73. $(APP)/include/empty_pb.hrl \
  74. $(APP)/include/simple_pb.hrl \
  75. $(APP)/src/empty_pb.erl \
  76. $(APP)/src/proto/simple.proto \
  77. $(APP)/src/proto/empty.proto \
  78. $(APP)/src/simple_pb.erl \
  79. $(APP)/$(APP).d | sort > $(APP)/EXPECT
  80. $t $(SLEEP)
  81. $t touch $(APP)/Makefile
  82. $t $(SLEEP)
  83. $t $(MAKE) -C $(APP) $v
  84. $t find $(APP) -type f -newer $(APP)/Makefile -not -path "$(APP)/.erlang.mk/*" | sort | diff $(APP)/EXPECT -
  85. $t rm $(APP)/EXPECT