Skip to content

Commit bc242e3

Browse files
committed
Makefile: support being driven by an external build system
There are a couple of problems this fixes: - assuming that the thrift compiler comes from this build. This is not true in Nix: we are going to build each package separately. - assuming that folly-clib versions need to be fiddled with. This is not necessary for Nix as we are provisioning an entirely-external folly. This mirrors the same changes as facebookincubator/Glean#617.
1 parent ed75458 commit bc242e3

2 files changed

Lines changed: 61 additions & 38 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ folly-clib/folly
99
folly-clib/folly-clib.cabal
1010
folly-clib/fast_float*
1111
folly-clib/v*.tar.gz
12+
compiler/tests/if/

Makefile

Lines changed: 60 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# These are a few rules to help build the open-source hsthrift. This
22
# file will hopefully go away in due course.
33
#
4+
# If you are integrating this Makefile into another build system like Nix,
5+
# consider setting the environment/Make variables:
6+
# - THRIFT_COMPILE: location of a built hsthrift compiler binary
7+
# - EXTERNAL_FOLLY_CLIB: when set, assumes folly-clib is already provided in the environment
48

59
CABAL_BIN := cabal
610

@@ -26,93 +30,103 @@ thrift-http::
2630

2731
thrift:: thrift-cpp thrift-hs
2832

29-
thrift-hs:: compiler
33+
.PHONY: thrift-compiler
34+
# Allow injecting a prebuilt thrift compiler by setting THRIFT_COMPILE in
35+
# environment (e.g. with Nix).
36+
ifndef THRIFT_COMPILE
37+
thrift-compiler:: compiler
38+
$(eval THRIFT_COMPILE := $$(shell $$(CABAL) -v0 list-bin exe:thrift-compiler))
39+
else
40+
thrift-compiler::
41+
# no-op
42+
endif
43+
44+
thrift-hs:: thrift-compiler
3045
( \
31-
THRIFT_COMPILE=$$($(CABAL) -v0 list-bin exe:thrift-compiler); \
32-
(cd lib && $${THRIFT_COMPILE} --hs \
46+
(cd lib && $(THRIFT_COMPILE) --hs \
3347
if/RpcOptions.thrift); \
34-
(cd lib && $${THRIFT_COMPILE} --hs \
48+
(cd lib && $(THRIFT_COMPILE) --hs \
3549
if/ApplicationException.thrift); \
36-
(cd lib && $${THRIFT_COMPILE} --hs --use-int \
50+
(cd lib && $(THRIFT_COMPILE) --hs --use-int \
3751
test/if/math.thrift \
3852
-o test); \
3953
mkdir -p cpp-channel/test/if; \
40-
(cd lib && $${THRIFT_COMPILE} --hs --use-int \
54+
(cd lib && $(THRIFT_COMPILE) --hs --use-int \
4155
test/if/math.thrift \
4256
-o ../cpp-channel/test/if); \
43-
(cd lib && $${THRIFT_COMPILE} --hs --use-int \
57+
(cd lib && $(THRIFT_COMPILE) --hs --use-int \
4458
test/if/math.thrift \
4559
-o ../server/test); \
46-
(cd lib && $${THRIFT_COMPILE} --hs --use-int \
60+
(cd lib && $(THRIFT_COMPILE) --hs --use-int \
4761
test/if/math.thrift \
4862
-o ../http/test); \
49-
(cd lib && $${THRIFT_COMPILE} --hs --use-int \
63+
(cd lib && $(THRIFT_COMPILE) --hs --use-int \
5064
test/if/echoer.thrift \
5165
-o test); \
52-
(cd lib && $${THRIFT_COMPILE} --hs --use-int \
66+
(cd lib && $(THRIFT_COMPILE) --hs --use-int \
5367
test/if/echoer.thrift \
5468
-o ../server/test); \
55-
(cd lib && $${THRIFT_COMPILE} --hs --use-int \
69+
(cd lib && $(THRIFT_COMPILE) --hs --use-int \
5670
test/if/echoer.thrift \
5771
-o ../http/test); \
58-
(cd server && $${THRIFT_COMPILE} --hs \
72+
(cd server && $(THRIFT_COMPILE) --hs \
5973
test/if/hash_map.thrift \
6074
-o test); \
61-
(cd tests && $${THRIFT_COMPILE} --hs \
75+
(cd tests && $(THRIFT_COMPILE) --hs \
6276
if/hs_prefix.thrift); \
63-
(cd tests && $${THRIFT_COMPILE} --hs \
77+
(cd tests && $(THRIFT_COMPILE) --hs \
6478
if/foo.thrift); \
65-
(cd tests && $${THRIFT_COMPILE} --hs \
79+
(cd tests && $(THRIFT_COMPILE) --hs \
6680
if/constants.thrift); \
67-
(cd tests && $${THRIFT_COMPILE} --hs \
81+
(cd tests && $(THRIFT_COMPILE) --hs \
6882
--duplicate-names \
6983
if/duplicate.thrift); \
70-
(cd tests && $${THRIFT_COMPILE} --hs \
84+
(cd tests && $(THRIFT_COMPILE) --hs \
7185
if/EnumConst.thrift); \
72-
(cd tests && $${THRIFT_COMPILE} --hs \
86+
(cd tests && $(THRIFT_COMPILE) --hs \
7387
if/enum.thrift); \
74-
(cd tests && $${THRIFT_COMPILE} --hs \
88+
(cd tests && $(THRIFT_COMPILE) --hs \
7589
if/exception.thrift); \
76-
(cd tests && $${THRIFT_COMPILE} --hs \
90+
(cd tests && $(THRIFT_COMPILE) --hs \
7791
--use-int --use-hash-map --use-hash-set \
7892
if/flags.thrift); \
79-
(cd tests && $${THRIFT_COMPILE} --hs \
93+
(cd tests && $(THRIFT_COMPILE) --hs \
8094
--extra-hasfields \
8195
if/hasfield.thrift); \
82-
(cd tests && $${THRIFT_COMPILE} --hs \
96+
(cd tests && $(THRIFT_COMPILE) --hs \
8397
if/A.thrift); \
84-
(cd tests && $${THRIFT_COMPILE} --hs \
98+
(cd tests && $(THRIFT_COMPILE) --hs \
8599
if/B.thrift); \
86-
(cd tests && $${THRIFT_COMPILE} --hs \
100+
(cd tests && $(THRIFT_COMPILE) --hs \
87101
if/C.thrift); \
88-
(cd tests && $${THRIFT_COMPILE} --hs \
102+
(cd tests && $(THRIFT_COMPILE) --hs \
89103
if/D.thrift); \
90-
(cd tests && $${THRIFT_COMPILE} --hs \
104+
(cd tests && $(THRIFT_COMPILE) --hs \
91105
if/E.thrift); \
92-
(cd tests && $${THRIFT_COMPILE} --hs \
106+
(cd tests && $(THRIFT_COMPILE) --hs \
93107
if/versions.thrift); \
94-
(cd tests && $${THRIFT_COMPILE} --hs \
108+
(cd tests && $(THRIFT_COMPILE) --hs \
95109
if/monoid.thrift); \
96-
(cd tests && $${THRIFT_COMPILE} --hs \
110+
(cd tests && $(THRIFT_COMPILE) --hs \
97111
if/hs_test.thrift); \
98-
(cd tests && $${THRIFT_COMPILE} --hs \
112+
(cd tests && $(THRIFT_COMPILE) --hs \
99113
if/hs_test.thrift -o ../lib/test); \
100-
(cd tests && $${THRIFT_COMPILE} --hs \
114+
(cd tests && $(THRIFT_COMPILE) --hs \
101115
if/map.thrift); \
102-
(cd tests && $${THRIFT_COMPILE} --hs \
116+
(cd tests && $(THRIFT_COMPILE) --hs \
103117
if/messed_up_case.thrift); \
104-
(cd tests && $${THRIFT_COMPILE} --hs \
118+
(cd tests && $(THRIFT_COMPILE) --hs \
105119
if/namespace.thrift); \
106-
(cd tests && $${THRIFT_COMPILE} --hs \
120+
(cd tests && $(THRIFT_COMPILE) --hs \
107121
if/namespace_included.thrift); \
108-
(cd tests && $${THRIFT_COMPILE} --hs \
122+
(cd tests && $(THRIFT_COMPILE) --hs \
109123
if/parens.thrift); \
110-
(cd tests && $${THRIFT_COMPILE} --hs \
124+
(cd tests && $(THRIFT_COMPILE) --hs \
111125
--required-symbols "A,B,C,X,weNeedThis" \
112126
if/huge.thrift); \
113-
(cd tests && $${THRIFT_COMPILE} --hs \
127+
(cd tests && $(THRIFT_COMPILE) --hs \
114128
if/scoped_enums.thrift); \
115-
(cd tests && $${THRIFT_COMPILE} --hs \
129+
(cd tests && $(THRIFT_COMPILE) --hs \
116130
if/service.thrift); \
117131
)
118132
# those files are required for thrift-compiler's tests
@@ -147,6 +161,7 @@ install::
147161
# Unpack the correct revisions of folly and fast_float under hsthrift/folly,
148162
# and run cmake to generate folly-config.h.
149163
.PHONY: setup-folly
164+
ifndef EXTERNAL_FOLLY_CLIB
150165
setup-folly::
151166
rm -rf folly-clib/folly folly-clib/fast_float* folly-clib/v*.tar.gz
152167
(cd folly-clib && \
@@ -191,5 +206,12 @@ setup-folly-0::
191206
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
192207
sed -i "s/^version:\(\s*\).*$$/version:\10.0/" folly-clib/folly-clib.cabal
193208

209+
else
210+
setup-folly::
211+
.PHONY: setup-folly-version setup-folly-0
212+
setup-folly-version::
213+
setup-folly-0::
214+
endif
215+
194216
setup-meta::
195217
ln -s cabal-meta.project cabal.project

0 commit comments

Comments
 (0)