Makefile 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. ifeq ($(DEBUG),1)
  2. DEBUG_INFO = $(info $1)
  3. else
  4. DEBUG_INFO = @:
  5. endif
  6. REBAR = $(CURDIR)/rebar3
  7. BUILD = $(CURDIR)/build
  8. SCRIPTS = $(CURDIR)/scripts
  9. include env.sh
  10. # Dashboard version
  11. # from https://github.com/emqx/emqx-dashboard5
  12. export EMQX_DASHBOARD_VERSION ?= v1.9.1
  13. export EMQX_EE_DASHBOARD_VERSION ?= e1.7.1
  14. export EMQX_RELUP ?= true
  15. export EMQX_REL_FORM ?= tgz
  16. -include default-profile.mk
  17. PROFILE ?= emqx
  18. REL_PROFILES := emqx emqx-enterprise
  19. PKG_PROFILES := emqx-pkg emqx-enterprise-pkg
  20. PROFILES := $(REL_PROFILES) $(PKG_PROFILES) default
  21. CT_NODE_NAME ?= 'test@127.0.0.1'
  22. CT_READABLE ?= true
  23. CT_COVER_EXPORT_PREFIX ?= $(PROFILE)
  24. export REBAR_GIT_CLONE_OPTIONS += --depth=1
  25. .PHONY: default
  26. default: $(REBAR) $(PROFILE)
  27. .prepare:
  28. @$(SCRIPTS)/git-hooks-init.sh # this is no longer needed since 5.0 but we keep it anyway
  29. @$(SCRIPTS)/prepare-build-deps.sh
  30. @touch .prepare
  31. .PHONY: all
  32. all: $(REBAR) $(PROFILES)
  33. .PHONY: ensure-rebar3
  34. ensure-rebar3:
  35. @$(SCRIPTS)/ensure-rebar3.sh
  36. $(REBAR): .prepare ensure-rebar3
  37. .PHONY: ensure-hex
  38. ensure-hex:
  39. # @mix local.hex --if-missing --force
  40. @mix local.hex 2.0.6 --if-missing --force
  41. .PHONY: ensure-mix-rebar3
  42. ensure-mix-rebar3: $(REBAR)
  43. @mix local.rebar rebar3 $(CURDIR)/rebar3 --if-missing --force
  44. .PHONY: ensure-mix-rebar
  45. ensure-mix-rebar: $(REBAR)
  46. @mix local.rebar --if-missing --force
  47. .PHONY: mix-deps-get
  48. mix-deps-get: $(ELIXIR_COMMON_DEPS)
  49. @mix deps.get
  50. .PHONY: eunit
  51. eunit: $(REBAR) ${ELIXIR_COMMON_DEPS} merge-config
  52. # @$(REBAR) eunit --name eunit@127.0.0.1 -c -v --cover_export_name $(CT_COVER_EXPORT_PREFIX)-eunit
  53. # TODO: cover compile
  54. mix eunit
  55. .PHONY: proper
  56. proper: $(REBAR)
  57. @$(REBAR) proper -d test/props -c
  58. .PHONY: test-compile
  59. test-compile: $(REBAR) merge-config
  60. $(REBAR) as test compile
  61. .PHONY: $(REL_PROFILES:%=%-compile)
  62. $(REL_PROFILES:%=%-compile): $(REBAR) merge-config
  63. $(REBAR) as $(@:%-compile=%) compile
  64. .PHONY: ct
  65. ct: $(REBAR) merge-config
  66. @$(REBAR) ct --name $(CT_NODE_NAME) -c -v --cover_export_name $(CT_COVER_EXPORT_PREFIX)-ct
  67. ## only check bpapi for enterprise profile because it's a super-set.
  68. .PHONY: static_checks
  69. static_checks:
  70. @$(REBAR) as check do xref, dialyzer
  71. @if [ "$${PROFILE}" = 'emqx-enterprise' ]; then $(REBAR) ct --suite apps/emqx/test/emqx_static_checks --readable $(CT_READABLE); fi
  72. ./scripts/check-i18n-style.sh
  73. ./scripts/check_missing_reboot_apps.exs
  74. # Allow user-set CASES environment variable
  75. ifneq ($(CASES),)
  76. CASES_ARG := --case $(CASES)
  77. endif
  78. # Allow user-set GROUPS environment variable
  79. ifneq ($(GROUPS),)
  80. GROUPS_ARG := --group $(GROUPS)
  81. endif
  82. ifeq ($(ENABLE_COVER_COMPILE),1)
  83. cover_args = --cover --cover_export_name $(CT_COVER_EXPORT_PREFIX)-$(subst /,-,$1)
  84. else
  85. cover_args =
  86. endif
  87. ## example:
  88. ## env SUITES=apps/appname/test/test_SUITE.erl CASES=t_foo make apps/appname-ct
  89. define gen-app-ct-target
  90. $1-ct: $(REBAR) merge-config clean-test-cluster-config
  91. $(eval SUITES := $(shell $(SCRIPTS)/find-suites.sh $1))
  92. ifneq ($(SUITES),)
  93. $(REBAR) ct -v \
  94. --readable=$(CT_READABLE) \
  95. --name $(CT_NODE_NAME) \
  96. $(call cover_args,$1) \
  97. --suite $(SUITES) \
  98. $(GROUPS_ARG) \
  99. $(CASES_ARG)
  100. else
  101. @echo 'No suites found for $1'
  102. endif
  103. endef
  104. ifneq ($(filter %-ct,$(MAKECMDGOALS)),)
  105. app_to_test := $(patsubst %-ct,%,$(filter %-ct,$(MAKECMDGOALS)))
  106. $(call DEBUG_INFO,app_to_test $(app_to_test))
  107. $(eval $(call gen-app-ct-target,$(app_to_test)))
  108. endif
  109. ## apps/name-prop targets
  110. define gen-app-prop-target
  111. $1-prop:
  112. $(REBAR) proper -d test/props -v -m $(shell $(SCRIPTS)/find-props.sh $1)
  113. endef
  114. ifneq ($(filter %-prop,$(MAKECMDGOALS)),)
  115. app_to_test := $(patsubst %-prop,%,$(filter %-prop,$(MAKECMDGOALS)))
  116. $(call DEBUG_INFO,app_to_test $(app_to_test))
  117. $(eval $(call gen-app-prop-target,$(app_to_test)))
  118. endif
  119. .PHONY: ct-suite
  120. ct-suite: $(REBAR) merge-config clean-test-cluster-config
  121. ifneq ($(TESTCASE),)
  122. ifneq ($(GROUP),)
  123. $(REBAR) ct -v --readable=$(CT_READABLE) --name $(CT_NODE_NAME) --suite $(SUITE) --case $(TESTCASE) --group $(GROUP)
  124. else
  125. $(REBAR) ct -v --readable=$(CT_READABLE) --name $(CT_NODE_NAME) --suite $(SUITE) --case $(TESTCASE)
  126. endif
  127. else ifneq ($(GROUP),)
  128. $(REBAR) ct -v --readable=$(CT_READABLE) --name $(CT_NODE_NAME) --suite $(SUITE) --group $(GROUP)
  129. else
  130. $(REBAR) ct -v --readable=$(CT_READABLE) --name $(CT_NODE_NAME) --suite $(SUITE)
  131. endif
  132. .PHONY: cover
  133. cover: $(REBAR)
  134. @ENABLE_COVER_COMPILE=1 $(REBAR) as test cover
  135. .PHONY: coveralls
  136. coveralls: $(REBAR)
  137. @ENABLE_COVER_COMPILE=1 $(REBAR) as test coveralls send
  138. COMMON_DEPS := $(REBAR)
  139. .PHONY: $(REL_PROFILES)
  140. $(REL_PROFILES:%=%): $(COMMON_DEPS)
  141. @$(BUILD) $(@) rel
  142. .PHONY: compile $(PROFILES:%=compile-%)
  143. compile: $(PROFILES:%=compile-%)
  144. $(PROFILES:%=compile-%):
  145. @$(BUILD) $(@:compile-%=%) apps
  146. .PHONY: $(PROFILES:%=compile-%-elixir)
  147. $(PROFILES:%=compile-%-elixir):
  148. @env IS_ELIXIR=yes $(BUILD) $(@:compile-%-elixir=%) apps
  149. ## Not calling rebar3 clean because
  150. ## 1. rebar3 clean relies on rebar3, meaning it reads config, fetches dependencies etc.
  151. ## 2. it's slow
  152. ## NOTE: this does not force rebar3 to fetch new version dependencies
  153. ## make clean-all to delete all fetched dependencies for a fresh start-over
  154. .PHONY: clean $(PROFILES:%=clean-%)
  155. clean: $(PROFILES:%=clean-%)
  156. $(PROFILES:%=clean-%):
  157. @if [ -d _build/$(@:clean-%=%) ]; then \
  158. rm -f rebar.lock; \
  159. rm -rf _build/$(@:clean-%=%)/rel; \
  160. find _build/$(@:clean-%=%) -name '*.beam' -o -name '*.so' -o -name '*.app' -o -name '*.appup' -o -name '*.o' -o -name '*.d' -type f | xargs rm -f; \
  161. find _build/$(@:clean-%=%) -type l -delete; \
  162. fi
  163. .PHONY: clean-all
  164. clean-all:
  165. @rm -f rebar.lock
  166. @rm -rf deps
  167. @rm -rf _build
  168. @rm -f emqx_dialyzer_*_plt
  169. .PHONY: deps-all
  170. deps-all: $(REBAR) $(PROFILES:%=deps-%)
  171. @make clean # ensure clean at the end
  172. ## deps-<profile> is used in CI scripts to download deps and the
  173. ## share downloads between CI steps and/or copied into containers
  174. ## which may not have the right credentials
  175. .PHONY: $(PROFILES:%=deps-%)
  176. $(PROFILES:%=deps-%): $(COMMON_DEPS)
  177. @$(SCRIPTS)/pre-compile.sh $(@:deps-%=%)
  178. @$(REBAR) as $(@:deps-%=%) get-deps
  179. @rm -f rebar.lock
  180. .PHONY: xref
  181. xref: $(REBAR)
  182. @$(REBAR) as check xref
  183. .PHONY: dialyzer
  184. dialyzer: $(REBAR)
  185. @$(REBAR) as check dialyzer
  186. ## rel target is to create release package without relup
  187. .PHONY: $(REL_PROFILES:%=%-rel) $(PKG_PROFILES:%=%-rel)
  188. $(REL_PROFILES:%=%-rel) $(PKG_PROFILES:%=%-rel): $(COMMON_DEPS)
  189. @$(BUILD) $(subst -rel,,$(@)) rel
  190. ## download relup base packages
  191. .PHONY: $(REL_PROFILES:%=%-relup-downloads)
  192. define download-relup-packages
  193. $1-relup-downloads:
  194. @if [ "$${EMQX_RELUP}" = "true" ]; then $(SCRIPTS)/relup-build/download-base-packages.sh $1; fi
  195. endef
  196. ALL_ZIPS = $(REL_PROFILES)
  197. $(foreach zt,$(ALL_ZIPS),$(eval $(call download-relup-packages,$(zt))))
  198. ## relup target is to create relup instructions
  199. .PHONY: $(REL_PROFILES:%=%-relup)
  200. define gen-relup-target
  201. $1-relup: $1-relup-downloads $(COMMON_DEPS)
  202. @$(BUILD) $1 relup
  203. endef
  204. ALL_TGZS = $(REL_PROFILES)
  205. $(foreach zt,$(ALL_TGZS),$(eval $(call gen-relup-target,$(zt))))
  206. ## tgz target is to create a release package .tar.gz with relup
  207. .PHONY: $(REL_PROFILES:%=%-tgz)
  208. define gen-tgz-target
  209. $1-tgz: $1-relup
  210. @$(BUILD) $1 tgz
  211. endef
  212. ALL_TGZS = $(REL_PROFILES)
  213. $(foreach zt,$(ALL_TGZS),$(eval $(call gen-tgz-target,$(zt))))
  214. ## A pkg target depend on a regular release
  215. .PHONY: $(PKG_PROFILES)
  216. define gen-pkg-target
  217. $1: $(COMMON_DEPS)
  218. @$(BUILD) $1 pkg
  219. endef
  220. $(foreach pt,$(PKG_PROFILES),$(eval $(call gen-pkg-target,$(pt))))
  221. .PHONY: run
  222. run: compile-$(PROFILE) quickrun
  223. .PHONY: quickrun
  224. quickrun:
  225. ./dev -p $(PROFILE)
  226. ## Take the currently set PROFILE
  227. docker:
  228. @$(BUILD) $(PROFILE) docker
  229. ## docker target is to create docker instructions
  230. .PHONY: $(REL_PROFILES:%=%-docker) $(REL_PROFILES:%=%-elixir-docker)
  231. define gen-docker-target
  232. $1-docker: $(COMMON_DEPS)
  233. @$(BUILD) $1 docker
  234. endef
  235. ALL_DOCKERS = $(REL_PROFILES) $(REL_PROFILES:%=%-elixir)
  236. $(foreach zt,$(ALL_DOCKERS),$(eval $(call gen-docker-target,$(zt))))
  237. .PHONY:
  238. merge-config:
  239. @$(SCRIPTS)/merge-config.escript
  240. ## elixir target is to create release packages using Elixir's Mix
  241. .PHONY: $(REL_PROFILES:%=%-elixir) $(PKG_PROFILES:%=%-elixir)
  242. $(REL_PROFILES:%=%-elixir) $(PKG_PROFILES:%=%-elixir): $(COMMON_DEPS)
  243. @env IS_ELIXIR=yes $(BUILD) $(subst -elixir,,$(@)) elixir
  244. .PHONY: $(REL_PROFILES:%=%-elixir-pkg)
  245. define gen-elixir-pkg-target
  246. # the Elixir places the tar in a different path than Rebar3
  247. $1-elixir-pkg: $(COMMON_DEPS)
  248. @env TAR_PKG_DIR=_build/$1-pkg \
  249. IS_ELIXIR=yes \
  250. $(BUILD) $1-pkg pkg
  251. endef
  252. $(foreach pt,$(REL_PROFILES),$(eval $(call gen-elixir-pkg-target,$(pt))))
  253. .PHONY: $(REL_PROFILES:%=%-elixir-tgz)
  254. define gen-elixir-tgz-target
  255. $1-elixir-tgz: $(COMMON_DEPS)
  256. @env IS_ELIXIR=yes $(BUILD) $1 tgz
  257. endef
  258. ALL_ELIXIR_TGZS = $(REL_PROFILES)
  259. $(foreach tt,$(ALL_ELIXIR_TGZS),$(eval $(call gen-elixir-tgz-target,$(tt))))
  260. .PHONY: fmt
  261. fmt: $(REBAR)
  262. @$(SCRIPTS)/erlfmt -w 'apps/*/{src,include,priv,test,integration_test}/**/*.{erl,hrl,app.src,eterm}'
  263. @$(SCRIPTS)/erlfmt -w 'apps/*/rebar.config' 'apps/emqx/rebar.config.script' '.ci/fvt_tests/http_server/rebar.config'
  264. @$(SCRIPTS)/erlfmt -w 'rebar.config' 'rebar.config.erl'
  265. @$(SCRIPTS)/erlfmt -w 'scripts/*.escript' 'bin/*.escript' 'bin/nodetool'
  266. @mix format
  267. .PHONY: clean-test-cluster-config
  268. clean-test-cluster-config:
  269. @rm -f apps/emqx_conf/data/configs/cluster.hocon || true
  270. .PHONY: spellcheck
  271. spellcheck:
  272. ./scripts/spellcheck/spellcheck.sh _build/docgen/$(PROFILE)/schema-en.json
  273. .PHONY: nothing
  274. nothing:
  275. @: