Просмотр исходного кода

Upgrade to Relx 4 which is now used as a library

Loïc Hoguin 3 лет назад
Родитель
Сommit
3e83513764
4 измененных файлов с 103 добавлено и 37 удалено
  1. 2 2
      index/relx.mk
  2. 2 0
      plugins/bootstrap.mk
  3. 67 18
      plugins/relx.mk
  4. 32 17
      test/plugin_relx.mk

+ 2 - 2
index/relx.mk

@@ -3,5 +3,5 @@ pkg_relx_name = relx
 pkg_relx_description = Sane, simple release creation for Erlang
 pkg_relx_homepage = https://github.com/erlware/relx
 pkg_relx_fetch = git
-pkg_relx_repo = https://github.com/erlware/relx
-pkg_relx_commit = master
+pkg_relx_repo = https://github.com/essen/relx
+pkg_relx_commit = main

+ 2 - 0
plugins/bootstrap.mk

@@ -93,6 +93,8 @@ endef
 
 define bs_relx_config
 {release, {$p_release, "1"}, [$p, sasl, runtime_tools]}.
+{dev_mode, false}.
+{include_erts, true}.
 {extended_start_script, true}.
 {sys_config, "config/sys.config"}.
 {vm_args, "config/vm.args"}.

+ 67 - 18
plugins/relx.mk

@@ -1,15 +1,16 @@
 # Copyright (c) 2013-2016, Loïc Hoguin <essen@ninenines.eu>
 # This file is part of erlang.mk and subject to the terms of the ISC License.
 
+ifeq ($(filter relx,$(BUILD_DEPS) $(DEPS) $(REL_DEPS)),relx)
 .PHONY: relx-rel relx-relup distclean-relx-rel run
 
 # Configuration.
 
-RELX ?= $(ERLANG_MK_TMP)/relx
+#RELX ?= $(ERLANG_MK_TMP)/relx
 RELX_CONFIG ?= $(CURDIR)/relx.config
 
-RELX_URL ?= https://erlang.mk/res/relx-v3.27.0-22
-RELX_OPTS ?=
+#RELX_URL ?= https://erlang.mk/res/relx-v3.27.0-22
+#RELX_OPTS ?=
 RELX_OUTPUT_DIR ?= _rel
 RELX_REL_EXT ?=
 RELX_TAR ?= 1
@@ -18,11 +19,11 @@ ifdef SFX
 	RELX_TAR = 1
 endif
 
-ifeq ($(firstword $(RELX_OPTS)),-o)
-	RELX_OUTPUT_DIR = $(word 2,$(RELX_OPTS))
-else
-	RELX_OPTS += -o $(RELX_OUTPUT_DIR)
-endif
+#ifeq ($(firstword $(RELX_OPTS)),-o)
+#	RELX_OUTPUT_DIR = $(word 2,$(RELX_OPTS))
+#else
+#	RELX_OPTS += -o $(RELX_OUTPUT_DIR)
+#endif
 
 # Core targets.
 
@@ -38,22 +39,69 @@ distclean:: distclean-relx-rel
 
 # Plugin-specific targets.
 
-$(RELX): | $(ERLANG_MK_TMP)
-	$(gen_verbose) $(call core_http_get,$(RELX),$(RELX_URL))
-	$(verbose) chmod +x $(RELX)
+#$(RELX): | $(ERLANG_MK_TMP)
+#	$(gen_verbose) $(call core_http_get,$(RELX),$(RELX_URL))
+#	$(verbose) chmod +x $(RELX)
+
+define relx_release.erl
+	{ok, Config} = file:consult("$(call core_native_path,$(RELX_CONFIG))"),
+	{release, {Name, Vsn0}, _} = lists:keyfind(release, 1, Config),
+	Vsn = case Vsn0 of
+		{cmd, Cmd} -> os:cmd(Cmd);
+		semver -> "";
+		{semver, _} -> "";
+		VsnStr -> Vsn0
+	end,
+	{ok, _} = relx:build_release(#{name => Name, vsn => Vsn}, Config),
+	halt(0).
+endef
+
+define relx_tar.erl
+	{ok, Config} = file:consult("$(call core_native_path,$(RELX_CONFIG))"),
+	{release, {Name, Vsn0}, _} = lists:keyfind(release, 1, Config),
+	Vsn = case Vsn0 of
+		{cmd, Cmd} -> os:cmd(Cmd);
+		semver -> "";
+		{semver, _} -> "";
+		VsnStr -> Vsn0
+	end,
+	{ok, _} = relx:build_tar(#{name => Name, vsn => Vsn}, Config),
+	halt(0).
+endef
+
+define relx_relup.erl
+	{ok, Config} = file:consult("$(call core_native_path,$(RELX_CONFIG))"),
+	{release, {Name, Vsn0}, _} = lists:keyfind(release, 1, Config),
+	Vsn = case Vsn0 of
+		{cmd, Cmd} -> os:cmd(Cmd);
+		semver -> "";
+		{semver, _} -> "";
+		VsnStr -> Vsn0
+	end,
+	io:format("~p~n~n", [Vsn]),
+	{ok, _} = relx:build_relup(Name, Vsn, undefined, Config ++ [{output_dir, "$(RELX_OUTPUT_DIR)"}]),
+	halt(0).
+endef
 
-relx-rel: $(RELX) rel-deps app
-	$(verbose) $(RELX) $(if $(filter 1,$V),-V 3) -c $(RELX_CONFIG) $(RELX_OPTS) release
+relx-rel: rel-deps app
+#	$(verbose) $(RELX) $(if $(filter 1,$V),-V 3) -c $(RELX_CONFIG) $(RELX_OPTS) release
+	$(call erlang,$(call relx_release.erl),-pa ebin/)
 	$(verbose) $(MAKE) relx-post-rel
 ifeq ($(RELX_TAR),1)
-	$(verbose) touch $(RELX_OUTPUT_DIR)/$(PROJECT)_release/releases/RELEASES
-	$(verbose) $(RELX) $(if $(filter 1,$V),-V 3) -c $(RELX_CONFIG) $(RELX_OPTS) tar
+#	$(verbose) touch $(RELX_OUTPUT_DIR)/$(PROJECT)_release/releases/RELEASES
+#	$(verbose) $(RELX) $(if $(filter 1,$V),-V 3) -c $(RELX_CONFIG) $(RELX_OPTS) tar
+	$(call erlang,$(call relx_tar.erl),-pa ebin/)
 endif
 
-relx-relup: $(RELX) rel-deps app
-	$(verbose) $(RELX) $(if $(filter 1,$V),-V 3) -c $(RELX_CONFIG) $(RELX_OPTS) release
+relx-relup: rel-deps app
+#	$(verbose) $(RELX) $(if $(filter 1,$V),-V 3) -c $(RELX_CONFIG) $(RELX_OPTS) release
+	$(call erlang,$(call relx_release.erl),-pa ebin/)
 	$(MAKE) relx-post-rel
-	$(verbose) $(RELX) $(if $(filter 1,$V),-V 3) -c $(RELX_CONFIG) $(RELX_OPTS) relup $(if $(filter 1,$(RELX_TAR)),tar)
+#	$(verbose) $(RELX) $(if $(filter 1,$V),-V 3) -c $(RELX_CONFIG) $(RELX_OPTS) relup $(if $(filter 1,$(RELX_TAR)),tar)
+	$(call erlang,$(call relx_relup.erl),-pa ebin/)
+ifeq ($(RELX_TAR),1)
+	$(call erlang,$(call relx_tar.erl),-pa ebin/)
+endif
 
 distclean-relx-rel:
 	$(gen_verbose) rm -rf $(RELX_OUTPUT_DIR)
@@ -110,3 +158,4 @@ help::
 		"  run         Compile the project, build the release and run it"
 
 endif
+endif

+ 32 - 17
test/plugin_relx.mk

@@ -22,12 +22,12 @@ relx-rel: init
 	$t cp ../erlang.mk $(APP)/
 	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
 
+	$i "Add Relx to the list of release dependencies"
+	$t perl -ni.bak -e 'print;if ($$.==1) {print "REL_DEPS = relx\n"}' $(APP)/Makefile
+
 	$i "Build the release"
 	$t $(MAKE) -C $(APP) $v
 
-	$i "Check that relx was downloaded"
-	$t test -f $(APP)/.erlang.mk/relx
-
 	$i "Check that the release was built"
 	$t test -d $(APP)/_rel
 	$t test -d $(APP)/_rel/$(APP)_release
@@ -60,6 +60,9 @@ relx-apps-with-deps: init
 	$t cp ../erlang.mk $(APP)/
 	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib bootstrap-rel $v
 
+	$i "Add Relx to the list of release dependencies"
+	$t perl -ni.bak -e 'print;if ($$.==1) {print "REL_DEPS = relx\n"}' $(APP)/Makefile
+
 	$i "Create a new application my_app"
 	$t $(MAKE) -C $(APP) new-app in=my_app $v
 
@@ -94,12 +97,12 @@ relx-bare-rel: init
 	$t cp ../erlang.mk $(APP)/
 	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
 
+	$i "Add Relx to the list of release dependencies"
+	$t perl -ni.bak -e 'print;if ($$.==1) {print "REL_DEPS = relx\n"}' $(APP)/Makefile
+
 	$i "Build the release"
 	$t $(MAKE) -C $(APP) rel $v
 
-	$i "Check that relx was downloaded"
-	$t test -f $(APP)/.erlang.mk/relx
-
 	$i "Check that the release was built"
 	$t test -d $(APP)/_rel
 	$t test -d $(APP)/_rel/$(APP)_release
@@ -115,6 +118,9 @@ relx-post-rel: init
 	$t cp ../erlang.mk $(APP)/
 	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
 
+	$i "Add Relx to the list of release dependencies"
+	$t perl -ni.bak -e 'print;if ($$.==1) {print "REL_DEPS = relx\n"}' $(APP)/Makefile
+
 	$i "Add relx-post-rel target to Makefile"
 	$t echo "relx-post-rel::" >> $(APP)/Makefile
 	$t echo "	echo test post rel > _rel/$(APP)_release/test_post_rel" >> $(APP)/Makefile
@@ -122,9 +128,6 @@ relx-post-rel: init
 	$i "Build the release"
 	$t $(MAKE) -C $(APP) $v
 
-	$i "Check that relx was downloaded"
-	$t test -f $(APP)/.erlang.mk/relx
-
 	$i "Check that the release was built"
 	$t test -d $(APP)/_rel
 	$t test -d $(APP)/_rel/$(APP)_release
@@ -165,6 +168,9 @@ relx-relup: init
 	$t cp ../erlang.mk $(APP)/
 	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
 
+	$i "Add Relx to the list of release dependencies"
+	$t perl -ni.bak -e 'print;if ($$.==1) {print "REL_DEPS = relx\n"}' $(APP)/Makefile
+
 	$i "Set the initial application version"
 ifeq ($(LEGACY),1)
 	$t sed -i.bak s/"{vsn, \"0.1.0\"}"/"{vsn, \"1\"}"/ $(APP)/src/$(APP).app.src
@@ -218,11 +224,11 @@ ifeq ($(PLATFORM),msys2)
 else
 	$i "Start initial release and confirm it runs the old code"
 endif
-	$t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) start
+	$t $(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) daemon
 	$t sleep 1
 ifneq ($(PLATFORM),msys2)
-# On Windows the script does not have the commands rpcterms and versions.
-	$t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpcterms test test` = old
+# On Windows the script does not have the commands rpc and versions.
+	$t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpc test test` = old
 
 	$i "Check that it's 1 available version"
 	$t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) versions | wc -l` = "2"
@@ -246,8 +252,8 @@ else
 endif
 	$t sleep 1
 ifneq ($(PLATFORM),msys2)
-# On Windows the script does not have the commands rpcterms and versions.
-	$t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpcterms test test` = new
+# On Windows the script does not have the commands rpc and versions.
+	$t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpc test test` = new
 
 	$i "Check that it's 2 available versions"
 	$t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) versions | wc -l` = "3"
@@ -266,8 +272,8 @@ else
 endif
 	$t sleep 1
 ifneq ($(PLATFORM),msys2)
-# On Windows the script does not have the commands rpcterms and versions.
-	$t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpcterms test test` = old
+# On Windows the script does not have the commands rpc and versions.
+	$t test `$(APP)/tmp/bin/$(APP)_release$(RELX_REL_EXT) rpc test test` = old
 endif
 
 	$i "Stop the release"
@@ -287,6 +293,9 @@ relx-start-stop: init
 	$t cp ../erlang.mk $(APP)/
 	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
 
+	$i "Add Relx to the list of release dependencies"
+	$t perl -ni.bak -e 'print;if ($$.==1) {print "REL_DEPS = relx\n"}' $(APP)/Makefile
+
 	$i "Build the release"
 	$t $(MAKE) -C $(APP) $v
 
@@ -300,7 +309,7 @@ endif
 ifeq ($(PLATFORM),msys2)
 	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) install
 endif
-	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) start
+	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) daemon
 
 	$i "Ping the release"
 	$t $(call wait_for_success,$(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) ping)
@@ -329,6 +338,9 @@ relx-tar: init
 	$t cp ../erlang.mk $(APP)/
 	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
 
+	$i "Add Relx to the list of release dependencies"
+	$t perl -ni.bak -e 'print;if ($$.==1) {print "REL_DEPS = relx\n"}' $(APP)/Makefile
+
 	$i "Build the release without a tarball"
 	$t $(MAKE) -C $(APP) RELX_TAR=0 $v
 
@@ -348,6 +360,9 @@ relx-vsn: init
 	$t cp ../erlang.mk $(APP)/
 	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
 
+	$i "Add Relx to the list of release dependencies"
+	$t perl -ni.bak -e 'print;if ($$.==1) {print "REL_DEPS = relx\n"}' $(APP)/Makefile
+
 	$i "Replace the vsn"
 	$t sed -i.bak s/"\"1\""/"{cmd, \"printf 2\"}"/ $(APP)/relx.config