Makefile 5.7 KB

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