plugin_protobuffs.mk 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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-compile-imports: 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 "Add protobuffs to the list of dependencies"
  37. $t perl -ni.bak -e 'print;if ($$.==1) {print "BUILD_DEPS = gpb\n"}' $(APP)/Makefile
  38. $i "Download two proto files with an import"
  39. $t mkdir $(APP)/src/proto/
  40. $t curl -s -o $(APP)/src/proto/exports.proto $(PROTOBUFFS_URL)/proto/exports.proto
  41. $t curl -s -o $(APP)/src/proto/imports.proto $(PROTOBUFFS_URL)/proto/imports.proto
  42. $i "Build the application"
  43. $t $(MAKE) -C $(APP) $v
  44. $i "Check that an Erlang module was generated and compiled"
  45. $t test -f $(APP)/src/exports_pb.erl
  46. $t test -f $(APP)/src/imports_pb.erl
  47. $t test -f $(APP)/include/exports_pb.hrl
  48. $t test -f $(APP)/include/imports_pb.hrl
  49. $t test -f $(APP)/ebin/exports_pb.beam
  50. $t test -f $(APP)/ebin/imports_pb.beam
  51. $i "Check that the generated modules are included in .app file"
  52. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  53. ok = application:load($(APP)), \
  54. {ok, [exports_pb, imports_pb]} = application:get_key($(APP), modules), \
  55. halt()"
  56. protobuffs-dont-compile: init
  57. $i "Bootstrap a new OTP library named $(APP)"
  58. $t mkdir $(APP)/
  59. $t cp ../erlang.mk $(APP)/
  60. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  61. $i "Do not add gpb/protobuffs to the list of dependencies"
  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 "Check that the proto files were ignored"
  69. $t test ! -e $(APP)/src/empty_pb.erl
  70. $t test ! -e $(APP)/src/simple_pb.erl
  71. $t test ! -e $(APP)/include/empty_pb.hrl
  72. $t test ! -e $(APP)/include/simple_pb.hrl
  73. $t test ! -e $(APP)/ebin/empty_pb.beam
  74. $t test ! -e $(APP)/ebin/simple_pb.beam
  75. $i "Check that the application itself was otherwise compiled properly"
  76. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  77. ok = application:load($(APP)), \
  78. {ok, []} = application:get_key($(APP), modules), \
  79. halt()"
  80. protobuffs-makefile-change: init
  81. $i "Bootstrap a new OTP library named $(APP)"
  82. $t mkdir $(APP)/
  83. $t cp ../erlang.mk $(APP)/
  84. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  85. $i "Add protobuffs to the list of dependencies"
  86. $t perl -ni.bak -e 'print;if ($$.==1) {print "BUILD_DEPS = gpb\n"}' $(APP)/Makefile
  87. $i "Download two proto files"
  88. $t mkdir $(APP)/src/proto/
  89. $t curl -s -o $(APP)/src/proto/empty.proto $(PROTOBUFFS_URL)/proto/empty.proto
  90. $t curl -s -o $(APP)/src/proto/simple.proto $(PROTOBUFFS_URL)/proto/simple.proto
  91. $i "Build the application"
  92. $t $(MAKE) -C $(APP) $v
  93. $i "Touch the Makefile; check that all files get rebuilt"
  94. $t printf "%s\n" \
  95. $(APP)/ebin/empty_pb.beam \
  96. $(APP)/ebin/simple_pb.beam \
  97. $(APP)/ebin/$(APP).app \
  98. $(APP)/include/empty_pb.hrl \
  99. $(APP)/include/simple_pb.hrl \
  100. $(APP)/src/empty_pb.erl \
  101. $(APP)/src/proto/simple.proto \
  102. $(APP)/src/proto/empty.proto \
  103. $(APP)/src/simple_pb.erl \
  104. $(APP)/$(APP).d | sort > $(APP)/EXPECT
  105. $t $(SLEEP)
  106. $t touch $(APP)/Makefile
  107. $t $(SLEEP)
  108. $t $(MAKE) -C $(APP) $v
  109. $t find $(APP) -type f -newer $(APP)/Makefile -not -path "$(APP)/.erlang.mk/*" | sort | diff $(APP)/EXPECT -
  110. $t rm $(APP)/EXPECT