Makefile 8.8 KB

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