-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathMakefile
More file actions
248 lines (228 loc) · 8.7 KB
/
Copy pathMakefile
File metadata and controls
248 lines (228 loc) · 8.7 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# These are a few rules to help build the open-source hsthrift. This
# file will hopefully go away in due course.
#
CABAL_BIN := cabal
THRIFT1 := thrift1
CABAL := $(CABAL_BIN) $(CABAL_CONFIG_FLAGS) $(GETDEPS_CABAL_FLAGS)
# Include path for fbthrift annotation files (installed by new_install_deps.sh)
HSTHRIFT_PREFIX ?= $(HOME)/.hsthrift
THRIFT_INCLUDE := -I $(HSTHRIFT_PREFIX)/include
# Targets in this file invoke Cabal and hence can't be built in parallel
.NOTPARALLEL:
all:: compiler thrift-hs thrift-cpp server thrift-http
# Cabal packages can't reference files outside their own directory, and the
# annotation files are resolved by the literal path "thrift/annotation/...",
# so the name has to be exactly this. Generated rather than committed because
# lib/ and compiler/ also contain a Thrift/, and fbsource rejects paths
# differing only in case.
.PHONY: symlinks
symlinks::
ln -sfn ../thrift lib/thrift
ln -sfn ../thrift compiler/thrift
compiler:: symlinks
$(CABAL) build exe:thrift-compiler
server::
$(CABAL) build thrift-server
util::
$(CABAL) build fb-util
thrift-http::
$(CABAL) build thrift-http
thrift:: thrift-cpp thrift-hs
thrift-hs:: compiler symlinks
( \
THRIFT_COMPILE=$$($(CABAL) -v0 list-bin exe:thrift-compiler); \
(cd lib && $${THRIFT_COMPILE} --hs \
if/RpcOptions.thrift); \
(cd lib && $${THRIFT_COMPILE} --hs \
if/ApplicationException.thrift); \
(cd lib && $${THRIFT_COMPILE} --hs \
thrift/annotation/thrift.thrift \
-o test); \
(cd lib && $${THRIFT_COMPILE} --hs \
thrift/annotation/scope.thrift \
-o test); \
(cd lib && $${THRIFT_COMPILE} --hs --use-int \
test/if/math.thrift \
-o test); \
mkdir -p cpp-channel/test/if; \
(cd lib && $${THRIFT_COMPILE} --hs \
thrift/annotation/thrift.thrift \
-o ../cpp-channel/test); \
(cd lib && $${THRIFT_COMPILE} --hs \
thrift/annotation/scope.thrift \
-o ../cpp-channel/test); \
(cd lib && $${THRIFT_COMPILE} --hs --use-int \
test/if/math.thrift \
-o ../cpp-channel/test/if); \
(cd lib && $${THRIFT_COMPILE} --hs \
thrift/annotation/thrift.thrift \
-o ../server/test); \
(cd lib && $${THRIFT_COMPILE} --hs \
thrift/annotation/scope.thrift \
-o ../server/test); \
(cd lib && $${THRIFT_COMPILE} --hs --use-int \
test/if/math.thrift \
-o ../server/test); \
(cd lib && $${THRIFT_COMPILE} --hs \
thrift/annotation/thrift.thrift \
-o ../http/test); \
(cd lib && $${THRIFT_COMPILE} --hs \
thrift/annotation/scope.thrift \
-o ../http/test); \
(cd lib && $${THRIFT_COMPILE} --hs --use-int \
test/if/math.thrift \
-o ../http/test); \
(cd lib && $${THRIFT_COMPILE} --hs --use-int \
test/if/echoer.thrift \
-o test); \
(cd lib && $${THRIFT_COMPILE} --hs --use-int \
test/if/echoer.thrift \
-o ../server/test); \
(cd lib && $${THRIFT_COMPILE} --hs --use-int \
test/if/echoer.thrift \
-o ../http/test); \
(cd server && $${THRIFT_COMPILE} --hs \
test/if/hash_map.thrift \
-o test); \
(cd tests && $${THRIFT_COMPILE} --hs \
thrift/annotation/thrift.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
thrift/annotation/scope.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/hs_prefix.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/foo.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/constants.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
--duplicate-names \
if/duplicate.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/EnumConst.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/enum.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/exception.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
--use-int --use-hash-map --use-hash-set \
if/flags.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
--extra-hasfields \
if/hasfield.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/A.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/B.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/C.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/D.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/E.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/versions.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/monoid.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/hs_test.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/hs_test.thrift -o ../lib/test); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/map.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/messed_up_case.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/namespace.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/namespace_included.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/parens.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
--required-symbols "A,B,C,X,weNeedThis" \
if/huge.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/scoped_enums.thrift); \
(cd tests && $${THRIFT_COMPILE} --hs \
if/service.thrift); \
)
# those files are required for thrift-compiler's tests
mkdir -p compiler/tests/if
cp tests/if/*.thrift compiler/tests/if/
cp tests/if/*.hs compiler/tests/if/
mkdir -p compiler/tests/thrift/annotation
cp thrift/annotation/*.thrift compiler/tests/thrift/annotation
thrift-cpp::
mkdir -p cpp-channel/if cpp-channel/test/if
cd lib && $(THRIFT1) $(THRIFT_INCLUDE) -I . --gen mstch_cpp2 \
-o ../cpp-channel/if \
if/RpcOptions.thrift
cd lib/test/if && $(THRIFT1) $(THRIFT_INCLUDE) -I . --gen mstch_cpp2 \
-o ../../../cpp-channel/test/if \
math.thrift
cd tests/if && $(THRIFT1) $(THRIFT_INCLUDE) -I . --gen mstch_cpp2 \
-o . \
hs_test.thrift
test::
$(CABAL) test mangle fb-util thrift-compiler thrift-lib thrift-server thrift-tests --keep-going
.PHONY: cabal-update
cabal-update::
$(CABAL) update
# Dummy install rule to keep getdeps happy. TODO: actually install things
.PHONY: install
install::
mkdir -p $(PREFIX)
# Unpack the correct revisions of folly and fast_float under hsthrift/folly,
# run cmake to generate folly-config.h, and collect the source files from
# cmake to splice into the .cabal file.
.PHONY: setup-folly
setup-folly::
rm -rf folly-clib/folly folly-clib/fast_float* folly-clib/v*.tar.gz
(cd folly-clib && \
mkdir folly && cd folly && \
git init && \
git remote add origin https://github.com/facebook/folly.git && \
git fetch --depth=1 origin $$(sed 's/Subproject commit //' <../../build/deps/github_hashes/facebook/folly-rev.txt) && \
git checkout FETCH_HEAD \
)
-# This is an awful hack and is guaranteed to break from time to time.
-# We inject code into folly's CMake scripts that log the source
-# files, and then grab those from the CMake output and splice them
-# into the .cabal file with some gross sed stuff. Feel free to
-# make this better.
(cd folly-clib/folly && \
sed -i 's|^\(.*Create OBJECT library.*\)$$| list(TRANSFORM _srcs PREPEND $${CMAKE_CURRENT_SOURCE_DIR}/ OUTPUT_VARIABLE _abssrcs)\n message("FILES_CPP: $${_abssrcs}")\n\n\1|' CMake/FollyFunctions.cmake && \
echo 'message("FILES_H:$${hfiles}")' >>CMakeLists.txt && \
mkdir _build && cd _build && \
cmake .. 2>&1 | sed 's/[^m]*m//g' | tee out && \
grep '^FILES_CPP:' out | \
sed 's/FILES_CPP://' | \
sed "s|$$(dirname $$(pwd))/|folly/|g" | \
grep -v folly/test/ | \
sed 's/;/\n /g' | sed 's/$$/ \\/g' | \
sed 's/^ f/ f/' | \
head -c -2 >cppfiles && \
grep '^FILES_H:' out | \
sed 's/FILES_H://' | \
sed "s|$$(dirname $$(pwd))/||g" | \
sed 's/;/ \\\n /g' >hfiles && \
cd ../.. && sed "s|__CPP_FILES__|$$(cat <folly/_build/cppfiles)|;s|__H_FILES__|$$(cat <folly/_build/hfiles)|" <folly-clib.cabal.in >folly-clib.cabal \
)
(cd folly-clib && \
wget $$(grep 'url =' ../build/fbcode_builder/manifests/fast_float | sed 's/^.*= *//'); \
tar xvzf *.tar.gz \
)
# Use the timestamp of the most recent commit as the version number,
# since there are no upstream releases. Careful to generate something
# that respects Cabal's constraints on version numbers: no leading
# zeroes and fields must be <10 digits.
.PHONY: setup-folly-version setup-folly-0
ver:=$(shell cd folly-clib/folly && date -u "--date=@$$(git log -1 --format=%ct)" +%Y%m%d.%-k%M | sed 's/\.0*/\./')
setup-folly-version::
sed -i "s/^version:\(\s*\).*$$/version:\1$(ver)/" folly-clib/folly-clib.cabal
sed -i "s/^\(\s*\)build-depends:\(\s*\)folly-clib\s*$$/\1build-depends: folly-clib==$(ver)/" common/util/fb-util.cabal
# Make version 0.0 of folly-clib, the empty package
setup-folly-0::
sed "s|__CPP_FILES__||;s|__H_FILES__||" <folly-clib/folly-clib.cabal.in | grep -v '^\s*install-includes' | grep -v '\.h$$' >folly-clib/folly-clib.cabal
sed -i "s/^version:\(\s*\).*$$/version:\10.0/" folly-clib/folly-clib.cabal
setup-meta::
ln -s cabal-meta.project cabal.project