aboutsummaryrefslogtreecommitdiffstats
path: root/test/plugin_protobuffs.mk
blob: 5a23cf4483e115a48519d4f4ae57dc8c31ed752d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Protocol buffers plugin.

PROTOBUFFS_TARGETS = $(call list_targets,protobuffs)

.PHONY: protobuffs $(PROTOBUFFS_TARGETS)

protobuffs: $(PROTOBUFFS_TARGETS)

PROTOBUFFS_URL = https://raw.githubusercontent.com/basho/erlang_protobuffs/master/test/erlang_protobuffs_SUITE_data

protobuffs-compile: 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 protobuffs to the list of dependencies"
	$t perl -ni.bak -e 'print;if ($$.==1) {print "BUILD_DEPS = protobuffs\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-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)"
	$t mkdir $(APP)/
	$t cp ../erlang.mk $(APP)/
	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v

	$i "Add protobuffs to the list of dependencies"
	$t perl -ni.bak -e 'print;if ($$.==1) {print "BUILD_DEPS = protobuffs\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 "Touch the Makefile; check that all files get rebuilt"
	$t printf "%s\n" \
		$(APP)/ebin/empty_pb.beam \
		$(APP)/ebin/simple_pb.beam \
		$(APP)/ebin/$(APP).app \
		$(APP)/include/empty_pb.hrl \
		$(APP)/include/simple_pb.hrl \
		$(APP)/src/empty_pb.erl \
		$(APP)/src/proto/simple.proto \
		$(APP)/src/proto/empty.proto \
		$(APP)/src/simple_pb.erl \
		$(APP)/$(APP).d | sort > $(APP)/EXPECT
	$t $(SLEEP)
	$t touch $(APP)/Makefile
	$t $(SLEEP)
	$t $(MAKE) -C $(APP) $v
	$t find $(APP) -type f -newer $(APP)/Makefile -not -path "$(APP)/.erlang.mk/*" | sort | diff $(APP)/EXPECT -
	$t rm $(APP)/EXPECT