Makefile 9.4 KB

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