Makefile 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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-4:1.14.5-25.3.2-2-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.5.0
  18. export EMQX_EE_DASHBOARD_VERSION ?= e1.3.0
  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 --name eunit@127.0.0.1 -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. ./scripts/check_missing_reboot_apps.exs
  83. APPS=$(shell $(SCRIPTS)/find-apps.sh)
  84. .PHONY: $(APPS:%=%-ct)
  85. define gen-app-ct-target
  86. $1-ct: $(REBAR) merge-config clean-test-cluster-config
  87. $(eval SUITES := $(shell $(SCRIPTS)/find-suites.sh $1))
  88. ifneq ($(SUITES),)
  89. ENABLE_COVER_COMPILE=1 $(REBAR) ct -c -v \
  90. --readable=$(CT_READABLE) \
  91. --name $(CT_NODE_NAME) \
  92. --cover_export_name $(CT_COVER_EXPORT_PREFIX)-$(subst /,-,$1) \
  93. --suite $(SUITES)
  94. else
  95. @echo 'No suites found for $1'
  96. endif
  97. endef
  98. $(foreach app,$(APPS),$(eval $(call gen-app-ct-target,$(app))))
  99. ## apps/name-prop targets
  100. .PHONY: $(APPS:%=%-prop)
  101. define gen-app-prop-target
  102. $1-prop:
  103. $(REBAR) proper -d test/props -v -m $(shell $(SCRIPTS)/find-props.sh $1)
  104. endef
  105. $(foreach app,$(APPS),$(eval $(call gen-app-prop-target,$(app))))
  106. .PHONY: ct-suite
  107. ct-suite: $(REBAR) merge-config clean-test-cluster-config
  108. ifneq ($(TESTCASE),)
  109. ifneq ($(GROUP),)
  110. $(REBAR) ct -v --readable=$(CT_READABLE) --name $(CT_NODE_NAME) --suite $(SUITE) --case $(TESTCASE) --group $(GROUP)
  111. else
  112. $(REBAR) ct -v --readable=$(CT_READABLE) --name $(CT_NODE_NAME) --suite $(SUITE) --case $(TESTCASE)
  113. endif
  114. else ifneq ($(GROUP),)
  115. $(REBAR) ct -v --readable=$(CT_READABLE) --name $(CT_NODE_NAME) --suite $(SUITE) --group $(GROUP)
  116. else
  117. $(REBAR) ct -v --readable=$(CT_READABLE) --name $(CT_NODE_NAME) --suite $(SUITE)
  118. endif
  119. .PHONY: cover
  120. cover: $(REBAR)
  121. @ENABLE_COVER_COMPILE=1 $(REBAR) as test cover
  122. .PHONY: coveralls
  123. coveralls: $(REBAR)
  124. @ENABLE_COVER_COMPILE=1 $(REBAR) as test coveralls send
  125. COMMON_DEPS := $(REBAR)
  126. .PHONY: $(REL_PROFILES)
  127. $(REL_PROFILES:%=%): $(COMMON_DEPS)
  128. @$(BUILD) $(@) rel
  129. .PHONY: compile $(PROFILES:%=compile-%)
  130. compile: $(PROFILES:%=compile-%)
  131. $(PROFILES:%=compile-%):
  132. @$(BUILD) $(@:compile-%=%) apps
  133. .PHONY: $(PROFILES:%=compile-%-elixir)
  134. $(PROFILES:%=compile-%-elixir):
  135. @env IS_ELIXIR=yes $(BUILD) $(@:compile-%-elixir=%) apps
  136. ## Not calling rebar3 clean because
  137. ## 1. rebar3 clean relies on rebar3, meaning it reads config, fetches dependencies etc.
  138. ## 2. it's slow
  139. ## NOTE: this does not force rebar3 to fetch new version dependencies
  140. ## make clean-all to delete all fetched dependencies for a fresh start-over
  141. .PHONY: clean $(PROFILES:%=clean-%)
  142. clean: $(PROFILES:%=clean-%)
  143. $(PROFILES:%=clean-%):
  144. @if [ -d _build/$(@:clean-%=%) ]; then \
  145. rm -f rebar.lock; \
  146. rm -rf _build/$(@:clean-%=%)/rel; \
  147. $(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; \
  148. $(FIND) _build/$(@:clean-%=%) -type l -delete; \
  149. fi
  150. .PHONY: clean-all
  151. clean-all:
  152. @rm -f rebar.lock
  153. @rm -rf deps
  154. @rm -rf _build
  155. @rm -f emqx_dialyzer_*_plt
  156. .PHONY: deps-all
  157. deps-all: $(REBAR) $(PROFILES:%=deps-%)
  158. @make clean # ensure clean at the end
  159. ## deps-<profile> is used in CI scripts to download deps and the
  160. ## share downloads between CI steps and/or copied into containers
  161. ## which may not have the right credentials
  162. .PHONY: $(PROFILES:%=deps-%)
  163. $(PROFILES:%=deps-%): $(COMMON_DEPS)
  164. @$(SCRIPTS)/pre-compile.sh $(@:deps-%=%)
  165. @$(REBAR) as $(@:deps-%=%) get-deps
  166. @rm -f rebar.lock
  167. .PHONY: xref
  168. xref: $(REBAR)
  169. @$(REBAR) as check xref
  170. .PHONY: dialyzer
  171. dialyzer: $(REBAR)
  172. @$(REBAR) as check dialyzer
  173. ## rel target is to create release package without relup
  174. .PHONY: $(REL_PROFILES:%=%-rel) $(PKG_PROFILES:%=%-rel)
  175. $(REL_PROFILES:%=%-rel) $(PKG_PROFILES:%=%-rel): $(COMMON_DEPS)
  176. @$(BUILD) $(subst -rel,,$(@)) rel
  177. ## download relup base packages
  178. .PHONY: $(REL_PROFILES:%=%-relup-downloads)
  179. define download-relup-packages
  180. $1-relup-downloads:
  181. @if [ "$${EMQX_RELUP}" = "true" ]; then $(SCRIPTS)/relup-build/download-base-packages.sh $1; fi
  182. endef
  183. ALL_ZIPS = $(REL_PROFILES)
  184. $(foreach zt,$(ALL_ZIPS),$(eval $(call download-relup-packages,$(zt))))
  185. ## relup target is to create relup instructions
  186. .PHONY: $(REL_PROFILES:%=%-relup)
  187. define gen-relup-target
  188. $1-relup: $1-relup-downloads $(COMMON_DEPS)
  189. @$(BUILD) $1 relup
  190. endef
  191. ALL_TGZS = $(REL_PROFILES)
  192. $(foreach zt,$(ALL_TGZS),$(eval $(call gen-relup-target,$(zt))))
  193. ## tgz target is to create a release package .tar.gz with relup
  194. .PHONY: $(REL_PROFILES:%=%-tgz)
  195. define gen-tgz-target
  196. $1-tgz: $1-relup
  197. @$(BUILD) $1 tgz
  198. endef
  199. ALL_TGZS = $(REL_PROFILES)
  200. $(foreach zt,$(ALL_TGZS),$(eval $(call gen-tgz-target,$(zt))))
  201. ## A pkg target depend on a regular release
  202. .PHONY: $(PKG_PROFILES)
  203. define gen-pkg-target
  204. $1: $(COMMON_DEPS)
  205. @$(BUILD) $1 pkg
  206. endef
  207. $(foreach pt,$(PKG_PROFILES),$(eval $(call gen-pkg-target,$(pt))))
  208. .PHONY: run
  209. run: compile-$(PROFILE) quickrun
  210. .PHONY: quickrun
  211. quickrun:
  212. ./dev -p $(PROFILE)
  213. ## Take the currently set PROFILE
  214. docker:
  215. @$(BUILD) $(PROFILE) docker
  216. ## docker target is to create docker instructions
  217. .PHONY: $(REL_PROFILES:%=%-docker) $(REL_PROFILES:%=%-elixir-docker)
  218. define gen-docker-target
  219. $1-docker: $(COMMON_DEPS)
  220. @$(BUILD) $1 docker
  221. endef
  222. ALL_DOCKERS = $(REL_PROFILES) $(REL_PROFILES:%=%-elixir)
  223. $(foreach zt,$(ALL_DOCKERS),$(eval $(call gen-docker-target,$(zt))))
  224. .PHONY:
  225. merge-config:
  226. @$(SCRIPTS)/merge-config.escript
  227. ## elixir target is to create release packages using Elixir's Mix
  228. .PHONY: $(REL_PROFILES:%=%-elixir) $(PKG_PROFILES:%=%-elixir)
  229. $(REL_PROFILES:%=%-elixir) $(PKG_PROFILES:%=%-elixir): $(COMMON_DEPS)
  230. @env IS_ELIXIR=yes $(BUILD) $(subst -elixir,,$(@)) elixir
  231. .PHONY: $(REL_PROFILES:%=%-elixir-pkg)
  232. define gen-elixir-pkg-target
  233. # the Elixir places the tar in a different path than Rebar3
  234. $1-elixir-pkg: $(COMMON_DEPS)
  235. @env TAR_PKG_DIR=_build/$1-pkg \
  236. IS_ELIXIR=yes \
  237. $(BUILD) $1-pkg pkg
  238. endef
  239. $(foreach pt,$(REL_PROFILES),$(eval $(call gen-elixir-pkg-target,$(pt))))
  240. .PHONY: $(REL_PROFILES:%=%-elixir-tgz)
  241. define gen-elixir-tgz-target
  242. $1-elixir-tgz: $(COMMON_DEPS)
  243. @env IS_ELIXIR=yes $(BUILD) $1 tgz
  244. endef
  245. ALL_ELIXIR_TGZS = $(REL_PROFILES)
  246. $(foreach tt,$(ALL_ELIXIR_TGZS),$(eval $(call gen-elixir-tgz-target,$(tt))))
  247. .PHONY: fmt
  248. fmt: $(REBAR)
  249. @$(SCRIPTS)/erlfmt -w '{apps,lib-ee}/*/{src,include,priv,test,integration_test}/**/*.{erl,hrl,app.src,eterm}'
  250. @$(SCRIPTS)/erlfmt -w 'rebar.config.erl'
  251. @mix format
  252. .PHONY: clean-test-cluster-config
  253. clean-test-cluster-config:
  254. @rm -f apps/emqx_conf/data/configs/cluster.hocon || true