forked from hstreamdb/hstream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
140 lines (120 loc) · 5.41 KB
/
Makefile
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
CABAL ?= cabal
CABAL_BUILD_PARALLEL ?= $(shell nproc)
GHC_MAJOR_VERSION := $(shell ghc --numeric-version | cut -d'.' -f1)
ifeq ($(GHC_MAJOR_VERSION), 8)
CABAL_PROJECT_FILE ?= cabal.project.ghc810
all:: thrift grpc sql generate-version
else
CABAL_PROJECT_FILE ?= cabal.project
all:: grpc sql generate-version
endif
HSTREAM_VERSION_FILE = "common/hstream/HStream/Version.hs"
HSTREAM_VERSION ?= $(or $(shell git describe --tag --abbrev=0 2>/dev/null), unknown)
HSTREAM_VERSION_COMMIT ?= $(or $(shell git rev-parse HEAD 2>/dev/null), unknown)
ENGINE_VERSION ?= v1
SQL_ENABLE_SCHEMA ?= false
ifeq ($(strip $(SQL_ENABLE_SCHEMA)), true)
CABAL_BUILD_FLAGS += +hstream_enable_schema
else
CABAL_BUILD_FLAGS += -hstream_enable_schema
endif
BNFC = bnfc
PROTO_COMPILE = protoc
PROTO_COMPILE_HS = ~/.cabal/bin/compile-proto-file_hstream
PROTO_CPP_PLUGIN ?= /usr/local/bin/grpc_cpp_plugin
THRIFT_COMPILE = thrift-compiler
thrift::
(cd external/hsthrift && THRIFT_COMPILE=$(THRIFT_COMPILE) make thrift)
(cd hstream-admin/store/if && $(THRIFT_COMPILE) logdevice/admin/if/admin.thrift --hs -r -o ..)
grpc:: grpc-cpp grpc-hs
grpc-hs-deps::
# 1. Always install proto-lens-protoc to avoid inconsistency
# 2. Change to a temporary dir to avoid create hstream dists.
(cd $(shell mktemp -d) && \
cabal install -j$(CABAL_BUILD_PARALLEL) \
--overwrite-policy=always proto-lens-protoc \
--constraint 'proto-lens-protoc ^>= 0.8.0.0' \
)
($(CABAL) build -j$(CABAL_BUILD_PARALLEL) --project-file $(CABAL_PROJECT_FILE) proto3-suite && \
mkdir -p ~/.cabal/bin && \
$(CABAL) exec --project-file $(CABAL_PROJECT_FILE) \
which compile-proto-file_hstream | tail -1 | xargs -I{} cp {} $(PROTO_COMPILE_HS)\
)
grpc-hs: grpc-hs-deps
($(PROTO_COMPILE_HS) \
--includeDir /usr/local/include \
--proto google/protobuf/struct.proto \
--out common/api/gen-hs)
($(PROTO_COMPILE_HS) \
--includeDir /usr/local/include \
--proto google/protobuf/empty.proto \
--out common/api/gen-hs)
(cd common/api/protos && $(PROTO_COMPILE_HS) \
--includeDir /usr/local/include \
--includeDir . \
--proto HStream/Server/HStreamApi.proto \
--out ../gen-hs)
(cd common/api/protos && $(PROTO_COMPILE_HS) \
--includeDir /usr/local/include \
--includeDir . \
--proto HStream/Server/HStreamInternal.proto \
--out ../gen-hs)
(cd common/api/protos && $(PROTO_COMPILE_HS) \
--includeDir . \
--proto HStream/Gossip/HStreamGossip.proto \
--out ../gen-hs)
(cd common/api/protos && $(PROTO_COMPILE_HS) \
--includeDir /usr/local/include \
--includeDir . \
--proto HStream/Common/ProtoTypes.proto \
--out ../gen-hs)
grpc-cpp:
(cd common/api && mkdir -p cpp/gen && \
$(PROTO_COMPILE) --cpp_out cpp/gen --grpc_out cpp/gen -I protos --plugin=protoc-gen-grpc=$(PROTO_CPP_PLUGIN) \
protos/HStream/Server/HStreamApi.proto \
)
sql:: sql-deps
(cd hstream-sql/etc && if [ $(ENGINE_VERSION) = v2 ]; then cp SQL-v2.cf SQL.cf; else cp SQL-v1.cf SQL.cf; fi)
(cd hstream-sql/etc && $(BNFC) --haskell --functor --text-token -p HStream -m -d SQL.cf -o ../gen-sql)
(awk -v RS= -v ORS='\n\n' '/\neitherResIdent/{system("cat hstream-sql/etc/replace/eitherResIdent");next } {print}' \
hstream-sql/gen-sql/HStream/SQL/Lex.x > hstream-sql/gen-sql/HStream/SQL/Lex.x.new)
(diff hstream-sql/gen-sql/HStream/SQL/Lex.x hstream-sql/gen-sql/HStream/SQL/Lex.x.new || true)
(cd hstream-sql/gen-sql && mv HStream/SQL/Lex.x.new HStream/SQL/Lex.x && make)
sql-deps::
# Change to a temporary dir to avoid create hstream dists.
(cd $(shell mktemp -d) && command -v bnfc || cabal install BNFC --constraint 'BNFC ^>= 2.9')
(cd $(shell mktemp -d) && command -v alex || cabal install alex --constraint 'alex ^>= 3.2.7.1')
(cd $(shell mktemp -d) && command -v happy || cabal install happy)
generate-version: $(HSTREAM_VERSION_FILE)
$(HSTREAM_VERSION_FILE):
echo "Generating HStream Version file with version: $(HSTREAM_VERSION), commit: $(HSTREAM_VERSION_COMMIT)"; \
echo "module HStream.Version where" > $@; \
echo "" >> $@; \
echo "hstreamVersion :: String" >> $@; \
echo "hstreamVersion = \"$(HSTREAM_VERSION)\"" >> $@; \
echo "" >> $@; \
echo "hstreamCommit :: String" >> $@; \
echo "hstreamCommit = \"$(HSTREAM_VERSION_COMMIT)\"" >> $@
clean:
find ./common -maxdepth 10 -type d \
-name "gen" \
-o -name "gen-hs2" \
-o -name "gen-hs" \
-o -name "gen-cpp" \
-o -name "gen-go" \
-o -name "gen-sql" \
-o -name "gen-src" \
| xargs rm -rf
rm -rf $(PROTO_COMPILE_HS)
rm -rf $(HSTREAM_VERSION_FILE)
.PHONY: syntax-test-gen syntax-test-run plan-test-gen plan-test-run
syntax-test-gen:
($(CABAL) run --flags $(CABAL_BUILD_FLAGS) hstream-sql:syntax-test-runner -- -i gen ./hstream-sql/etc/syntax-test-cases.yaml)
(sed -i '1s/^/# This file is automatically @generated by `hstream-sql:syntax-test-runner`.\n# Please run `make syntax-test-gen` to regenerate or update.\n\n/' ./hstream-sql/etc/syntax-test-cases.yaml)
syntax-test-run:
($(CABAL) run --flags $(CABAL_BUILD_FLAGS) hstream-sql:syntax-test-runner -- run ./hstream-sql/etc/syntax-test-cases.yaml)
plan-test-gen:
($(CABAL) run --flags $(CABAL_BUILD_FLAGS) hstream-sql:plan-test-runner -- -i gen ./hstream-sql/etc/plan-test-cases.yaml)
(sed -i '1s/^/# This file is automatically @generated by `hstream-sql:plan-test-runner`.\n# Please run `make plan-test-gen` to regenerate or update.\n\n/' ./hstream-sql/etc/plan-test-cases.yaml)
plan-test-run:
($(CABAL) run --flags $(CABAL_BUILD_FLAGS) hstream-sql:plan-test-runner -- run ./hstream-sql/etc/plan-test-cases.yaml)