aboutsummaryrefslogtreecommitdiffstats
path: root/test/plugin_protobuffs.mk
blob: f5814e8d36d39ca50b67368d09a9bac5a1d3b6ba (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# 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: init

	$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: init

	$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-dont-compile: init

	$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 "Do not add gpb/protobuffs to the list of dependencies"

	$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 the proto files were ignored"
	$t test ! -e $(APP)/src/empty_pb.erl
	$t test ! -e $(APP)/src/simple_pb.erl
	$t test ! -e $(APP)/include/empty_pb.hrl
	$t test ! -e $(APP)/include/simple_pb.hrl
	$t test ! -e $(APP)/ebin/empty_pb.beam
	$t test ! -e $(APP)/ebin/simple_pb.beam

	$i "Check that the application itself was otherwise compiled properly"
	$t $(ERL) -pa $(APP)/ebin/ -eval " \
		ok = application:load($(APP)), \
		{ok, []} = application:get_key($(APP), modules), \
		halt()"

protobuffs-makefile-change: init

	$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