aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-11-28 14:10:37 +0100
committerLoïc Hoguin <[email protected]>2018-11-28 14:10:37 +0100
commitbe9ab3da2417057ca311ce44304c04739ac6475e (patch)
tree736c0ca7d478ec74fa949faaf7616504db46e5ef
parent7a514c6a372219fee528e0bc2ed0b2f2ba9c758d (diff)
downloaderlang.mk-be9ab3da2417057ca311ce44304c04739ac6475e.tar.gz
erlang.mk-be9ab3da2417057ca311ce44304c04739ac6475e.tar.bz2
erlang.mk-be9ab3da2417057ca311ce44304c04739ac6475e.zip
Add built-in support for gpb for building proto files
When gpb is found in DEPS or BUILD_DEPS then it is used instead of erlang_protobuffs.
-rw-r--r--plugins/protobuffs.mk19
-rw-r--r--test/plugin_protobuffs.mk32
2 files changed, 48 insertions, 3 deletions
diff --git a/plugins/protobuffs.mk b/plugins/protobuffs.mk
index 8eac4d8..2719c01 100644
--- a/plugins/protobuffs.mk
+++ b/plugins/protobuffs.mk
@@ -28,14 +28,27 @@ $(ERLANG_MK_TMP)/last-makefile-change-protobuffs: $(filter-out $(PROJECT).d,$(MA
$(PROJECT).d:: $(ERLANG_MK_TMP)/last-makefile-change-protobuffs
endif
+ifeq ($(filter gpb,$(BUILD_DEPS) $(DEPS)),)
define compile_proto.erl
[begin
- protobuffs_compile:generate_source(F,
- [{output_include_dir, "./include"},
- {output_src_dir, "./src"}])
+ protobuffs_compile:generate_source(F, [
+ {output_include_dir, "./include"},
+ {output_src_dir, "./src"}])
end || F <- string:tokens("$1", " ")],
halt().
endef
+else
+define compile_proto.erl
+ [begin
+ gpb_compile:file(F, [
+ {include_as_lib, true},
+ {module_name_suffix, "_pb"},
+ {o_hrl, "./include"},
+ {o_erl, "./src"}])
+ end || F <- string:tokens("$1", " ")],
+ halt().
+endef
+endif
$(PROJECT).d:: $(PROTO_FILES)
$(verbose) mkdir -p ebin/ include/
diff --git a/test/plugin_protobuffs.mk b/test/plugin_protobuffs.mk
index e3aad9f..5a23cf4 100644
--- a/test/plugin_protobuffs.mk
+++ b/test/plugin_protobuffs.mk
@@ -40,6 +40,38 @@ protobuffs-compile: build clean
{ok, [empty_pb, simple_pb]} = application:get_key($(APP), modules), \
halt()"
+protobuffs-compile-with-gpb: build clean
+
+ $i "Bootstrap a new OTP library named $(APP)"
+ $t mkdir $(APP)/
+ $t cp ../erlang.mk $(APP)/
+ $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
+
+ $i "Add gpb to the list of dependencies"
+ $t perl -ni.bak -e 'print;if ($$.==1) {print "BUILD_DEPS = gpb\n"}' $(APP)/Makefile
+
+ $i "Download two proto files"
+ $t mkdir $(APP)/src/proto/
+ $t curl -s -o $(APP)/src/proto/empty.proto $(PROTOBUFFS_URL)/proto/empty.proto
+ $t curl -s -o $(APP)/src/proto/simple.proto $(PROTOBUFFS_URL)/proto/simple.proto
+
+ $i "Build the application"
+ $t $(MAKE) -C $(APP) $v
+
+ $i "Check that an Erlang module was generated and compiled"
+ $t test -f $(APP)/src/empty_pb.erl
+ $t test -f $(APP)/src/simple_pb.erl
+ $t test -f $(APP)/include/empty_pb.hrl
+ $t test -f $(APP)/include/simple_pb.hrl
+ $t test -f $(APP)/ebin/empty_pb.beam
+ $t test -f $(APP)/ebin/simple_pb.beam
+
+ $i "Check that the generated modules are included in .app file"
+ $t $(ERL) -pa $(APP)/ebin/ -eval " \
+ ok = application:load($(APP)), \
+ {ok, [empty_pb, simple_pb]} = application:get_key($(APP), modules), \
+ halt()"
+
protobuffs-makefile-change: build clean
$i "Bootstrap a new OTP library named $(APP)"