Makefile 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. $(shell $(CURDIR)/scripts/git-hooks-init.sh)
  2. REBAR_VERSION = 3.16.1-emqx-1
  3. REBAR = $(CURDIR)/rebar3
  4. BUILD = $(CURDIR)/build
  5. SCRIPTS = $(CURDIR)/scripts
  6. export EMQX_DEFAULT_BUILDER = ghcr.io/emqx/emqx-builder/4.4-2:23.3.4.9-3-alpine3.14
  7. export EMQX_DEFAULT_RUNNER = alpine:3.14
  8. export OTP_VSN ?= $(shell $(CURDIR)/scripts/get-otp-vsn.sh)
  9. export PKG_VSN ?= $(shell $(CURDIR)/pkg-vsn.sh)
  10. export EMQX_DASHBOARD_VERSION ?= v0.18.0
  11. export DOCKERFILE := deploy/docker/Dockerfile
  12. export DOCKERFILE_TESTING := deploy/docker/Dockerfile.testing
  13. ifeq ($(OS),Windows_NT)
  14. export REBAR_COLOR=none
  15. FIND=/usr/bin/find
  16. else
  17. FIND=find
  18. endif
  19. PROFILE ?= emqx
  20. REL_PROFILES := emqx emqx-edge emqx-enterprise
  21. PKG_PROFILES := emqx-pkg emqx-edge-pkg emqx-enterprise-pkg
  22. PROFILES := $(REL_PROFILES) $(PKG_PROFILES) default
  23. CT_NODE_NAME ?= 'test@127.0.0.1'
  24. export REBAR_GIT_CLONE_OPTIONS += --depth=1
  25. .PHONY: default
  26. default: $(REBAR) $(PROFILE)
  27. .PHONY: all
  28. all: $(REBAR) $(PROFILES)
  29. .PHONY: ensure-rebar3
  30. ensure-rebar3:
  31. @$(SCRIPTS)/fail-on-old-otp-version.escript
  32. @$(SCRIPTS)/ensure-rebar3.sh $(REBAR_VERSION)
  33. $(REBAR): ensure-rebar3
  34. .PHONY: get-dashboard
  35. get-dashboard:
  36. @$(SCRIPTS)/get-dashboard.sh
  37. .PHONY: eunit
  38. eunit: $(REBAR)
  39. @ENABLE_COVER_COMPILE=1 $(REBAR) eunit -v -c
  40. .PHONY: proper
  41. proper: $(REBAR)
  42. @ENABLE_COVER_COMPILE=1 $(REBAR) proper -d test/props -c
  43. .PHONY: ct
  44. ct: $(REBAR) conf-segs
  45. @ENABLE_COVER_COMPILE=1 $(REBAR) ct --name $(CT_NODE_NAME) -c -v
  46. .PHONY: static_checks
  47. static_checks:
  48. @$(REBAR) as check do xref, dialyzer, ct --suite apps/emqx/test/emqx_bpapi_suite --readable false
  49. APPS=$(shell $(CURDIR)/scripts/find-apps.sh)
  50. ## app/name-ct targets are intended for local tests hence cover is not enabled
  51. .PHONY: $(APPS:%=%-ct)
  52. define gen-app-ct-target
  53. $1-ct: conf-segs
  54. $(REBAR) ct --name $(CT_NODE_NAME) -v --suite $(shell $(CURDIR)/scripts/find-suites.sh $1)
  55. endef
  56. $(foreach app,$(APPS),$(eval $(call gen-app-ct-target,$(app))))
  57. ## apps/name-prop targets
  58. .PHONY: $(APPS:%=%-prop)
  59. define gen-app-prop-target
  60. $1-prop:
  61. $(REBAR) proper -d test/props -v -m $(shell $(CURDIR)/scripts/find-props.sh $1)
  62. endef
  63. $(foreach app,$(APPS),$(eval $(call gen-app-prop-target,$(app))))
  64. .PHONY: ct-suite
  65. ct-suite: $(REBAR)
  66. ifneq ($(TESTCASE),)
  67. $(REBAR) ct -v --readable=false --name $(CT_NODE_NAME) --suite $(SUITE) --case $(TESTCASE)
  68. else ifneq ($(GROUP),)
  69. $(REBAR) ct -v --readable=false --name $(CT_NODE_NAME) --suite $(SUITE) --group $(GROUP)
  70. else
  71. $(REBAR) ct -v --readable=false --name $(CT_NODE_NAME) --suite $(SUITE)
  72. endif
  73. .PHONY: cover
  74. cover: $(REBAR)
  75. @ENABLE_COVER_COMPILE=1 $(REBAR) cover
  76. .PHONY: coveralls
  77. coveralls: $(REBAR)
  78. @ENABLE_COVER_COMPILE=1 $(REBAR) as test coveralls send
  79. .PHONY: $(REL_PROFILES)
  80. $(REL_PROFILES:%=%): $(REBAR) get-dashboard conf-segs
  81. @$(REBAR) as $(@) do release
  82. ## Not calling rebar3 clean because
  83. ## 1. rebar3 clean relies on rebar3, meaning it reads config, fetches dependencies etc.
  84. ## 2. it's slow
  85. ## NOTE: this does not force rebar3 to fetch new version dependencies
  86. ## make clean-all to delete all fetched dependencies for a fresh start-over
  87. .PHONY: clean $(PROFILES:%=clean-%)
  88. clean: $(PROFILES:%=clean-%)
  89. $(PROFILES:%=clean-%):
  90. @if [ -d _build/$(@:clean-%=%) ]; then \
  91. rm rebar.lock \
  92. rm -rf _build/$(@:clean-%=%)/rel; \
  93. $(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; \
  94. $(FIND) _build/$(@:clean-%=%) -type l -delete; \
  95. fi
  96. .PHONY: clean-all
  97. clean-all:
  98. @rm -f rebar.lock
  99. @rm -rf _build
  100. .PHONY: deps-all
  101. deps-all: $(REBAR) $(PROFILES:%=deps-%)
  102. @make clean # ensure clean at the end
  103. ## deps-<profile> is used in CI scripts to download deps and the
  104. ## share downloads between CI steps and/or copied into containers
  105. ## which may not have the right credentials
  106. .PHONY: $(PROFILES:%=deps-%)
  107. $(PROFILES:%=deps-%): $(REBAR) get-dashboard
  108. @$(REBAR) as $(@:deps-%=%) get-deps
  109. @rm -f rebar.lock
  110. .PHONY: xref
  111. xref: $(REBAR)
  112. @$(REBAR) as check xref
  113. .PHONY: dialyzer
  114. dialyzer: $(REBAR)
  115. @$(REBAR) as check dialyzer
  116. COMMON_DEPS := $(REBAR) get-dashboard conf-segs
  117. ## rel target is to create release package without relup
  118. .PHONY: $(REL_PROFILES:%=%-rel) $(PKG_PROFILES:%=%-rel)
  119. $(REL_PROFILES:%=%-rel) $(PKG_PROFILES:%=%-rel): $(COMMON_DEPS)
  120. @$(BUILD) $(subst -rel,,$(@)) rel
  121. ## relup target is to create relup instructions
  122. .PHONY: $(REL_PROFILES:%=%-relup)
  123. define gen-relup-target
  124. $1-relup: $(COMMON_DEPS)
  125. @$(BUILD) $1 relup
  126. endef
  127. ALL_TGZS = $(REL_PROFILES)
  128. $(foreach zt,$(ALL_TGZS),$(eval $(call gen-relup-target,$(zt))))
  129. ## tgz target is to create a release package .tar.gz with relup
  130. .PHONY: $(REL_PROFILES:%=%-tgz)
  131. define gen-tgz-target
  132. $1-tgz: $1-relup
  133. @$(BUILD) $1 tgz
  134. endef
  135. ALL_TGZS = $(REL_PROFILES)
  136. $(foreach zt,$(ALL_TGZS),$(eval $(call gen-tgz-target,$(zt))))
  137. ## A pkg target depend on a regular release
  138. .PHONY: $(PKG_PROFILES)
  139. define gen-pkg-target
  140. $1: $1-rel
  141. @$(BUILD) $1 pkg
  142. endef
  143. $(foreach pt,$(PKG_PROFILES),$(eval $(call gen-pkg-target,$(pt))))
  144. .PHONY: run
  145. run: $(PROFILE) quickrun
  146. .PHONY: quickrun
  147. quickrun:
  148. ./_build/$(PROFILE)/rel/emqx/bin/emqx console
  149. ## docker target is to create docker instructions
  150. .PHONY: $(REL_PROFILES:%=%-docker)
  151. define gen-docker-target
  152. $1-docker: $(COMMON_DEPS)
  153. @$(BUILD) $1 docker
  154. endef
  155. ALL_TGZS = $(REL_PROFILES)
  156. $(foreach zt,$(ALL_TGZS),$(eval $(call gen-docker-target,$(zt))))
  157. ## emqx-docker-testing
  158. ## emqx-enterprise-docker-testing
  159. ## is to directly copy a extracted tgz-package to a
  160. ## base image such as ubuntu20.04. Mostly for testing
  161. .PHONY: $(REL_PROFILES:%=%-docker-testing)
  162. define gen-docker-target-testing
  163. $1-docker-testing: $(COMMON_DEPS)
  164. @$(BUILD) $1 docker-testing
  165. endef
  166. ALL_TGZS = $(REL_PROFILES)
  167. $(foreach zt,$(ALL_TGZS),$(eval $(call gen-docker-target-testing,$(zt))))
  168. conf-segs:
  169. @scripts/merge-config.escript