-
Notifications
You must be signed in to change notification settings - Fork 33
/
Makefile.test
109 lines (88 loc) · 2.9 KB
/
Makefile.test
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
ifndef CXX
CXX = g++
endif
export CXX
ifndef CPPFLAGS
CPPFLAGS =
endif
CPPFLAGS+=-Wno-deprecated -std=c++17
export CPPFLAGS
LDFLAGS+=-Wl,--copy-dt-needed-entries
export LDFLAGS
#
# Unit tests
# ----------
.PHONY: tests dune-all
# unit test of the ocaml-protoc internals
tests:
$(DUNE) build @runtest
#
# Integration tests
# -----------------
# Integration tests with Google protoc (C++ target) to ensure that
# the generated OCaml code can encode/decode message compatible with Google
# implementation
# location of where the Google protoc compiler is installed
PB_INSTALL ?= /usr/
PB_HINC = $(PB_INSTALL)/include
PB_LINC = $(PB_INSTALL)/lib
PROTOC = $(PB_INSTALL)/bin/protoc
export LD_LIBRARY_PATH=$(PB_LINC)
$(OCAMLOPTIONS_HINC)/ocamloptions.pb.cc: $(OCAMLOPTIONS_HINC)/ocamloptions.proto
cd $(OCAMLOPTIONS_HINC) && \
$(PROTOC) --cpp_out ./ -I ./ -I $(abspath $(PB_HINC)) ocamloptions.proto
%_cpp.tsk: %_cpp.cpp %.pb.cc $(OCAMLOPTIONS_HINC)/ocamloptions.pb.cc
$(CXX) $(CPPFLAGS) $(LDFLAGS) \
-I ./ -I $(INTEGRATION_TESTS_DIR) -I $(OCAMLOPTIONS_HINC) -I $(PB_HINC) \
-L $(PB_LINC) -l protobuf \
$? \
-o $@
$(INTEGRATION_TESTS_DIR)/test10_cpp.tsk: \
$(INTEGRATION_TESTS_DIR)/test10_cpp.cpp \
$(INTEGRATION_TESTS_DIR)/test10.pb.cc \
$(INTEGRATION_TESTS_DIR)/test09.pb.cc
$(CXX) $(CPPFLAGS) $(LDFLAGS) \
-I ./ -I $(INTEGRATION_TESTS_DIR) -I $(PB_HINC) \
-L $(PB_LINC) -l protobuf \
$? \
-o $@
.SECONDARY:
%.pb.cc: %.proto
$(PROTOC) \
--cpp_out $(INTEGRATION_TESTS_DIR) \
-I $(PB_HINC) -I $(OCAMLOPTIONS_HINC) -I $(INTEGRATION_TESTS_DIR) \
$<
test%: $(INTEGRATION_TESTS_DIR)/test%_cpp.tsk
INCLUDE=$(PB_HINC)/ $(DUNE) build $(INTEGRATION_TESTS_DIR)/test$*_ml.exe
$(INTEGRATION_TESTS_DIR)/test$*_cpp.tsk encode
./_build/default/$(INTEGRATION_TESTS_DIR)/test$*_ml.exe decode
./_build/default/$(INTEGRATION_TESTS_DIR)/test$*_ml.exe encode
$(INTEGRATION_TESTS_DIR)/test$*_cpp.tsk decode
.PHONY: integration
integration: test01 test02 test05 test06 test07 test08 test09 test10 \
test11 test12 test13 test14 test15 test16 test17 test18 \
test19 test20 test21 test22 test23 test24 test26
#
# Yojson
# ------
YOJSON_DIR=src/tests/yojson
OCB_YOJSON=-pkgs yojson,ocaml-protoc-yojson
yojson:
./ocaml-protoc -yojson -ml_out $(YOJSON_DIR) $(YOJSON_DIR)/yojson_unittest.proto
$(PROTOC) \
--cpp_out $(YOJSON_DIR) \
-I $(PB_HINC) -I $(OCAMLOPTIONS_HINC) -I $(YOJSON_DIR) \
$(YOJSON_DIR)/yojson_unittest.proto
$(OCB) $(OCB_YOJSON) -I $(YOJSON_DIR) yojson_unittest_ml.byte
$(CXX) \
$(CPPFLAGS) $(LDFLAGS) \
-I ./ -I $(INTEGRATION_TESTS_DIR) -I $(OCAMLOPTIONS_HINC) -I $(PB_HINC) \
$(YOJSON_DIR)/yojson_unittest_cpp.cpp $(YOJSON_DIR)/yojson_unittest.pb.cc \
-L $(PB_LINC) \
-l protobuf \
-o $@
@# Rename cpp executable to something clearer (ie yojson-cpp)
./yojson
export OCAMLRUNPARAM="b" && ./yojson_unittest_ml.byte
.PHONY: all-tests
all-tests: tests yojson integration