diff options
author | Tyler Hughes <[email protected]> | 2022-08-20 17:11:46 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2023-05-12 15:26:52 +0200 |
commit | 4cdab1076b9917ba431fcc1cf0a444e00407b056 (patch) | |
tree | b6c83ad8701086beca91195d4829bcef24ddbc5c | |
parent | d72f07d1270badb3dd8b2267597f5416e9462780 (diff) | |
download | erlang.mk-4cdab1076b9917ba431fcc1cf0a444e00407b056.tar.gz erlang.mk-4cdab1076b9917ba431fcc1cf0a444e00407b056.tar.bz2 erlang.mk-4cdab1076b9917ba431fcc1cf0a444e00407b056.zip |
Add support for relx.config.script back
It was removed accidentally when switching to Relx v4.
-rw-r--r-- | plugins/relx.mk | 33 | ||||
-rw-r--r-- | test/plugin_relx.mk | 93 |
2 files changed, 120 insertions, 6 deletions
diff --git a/plugins/relx.mk b/plugins/relx.mk index d9515a4..b957bae 100644 --- a/plugins/relx.mk +++ b/plugins/relx.mk @@ -7,6 +7,7 @@ ifeq ($(filter relx,$(BUILD_DEPS) $(DEPS) $(REL_DEPS)),relx) # Configuration. RELX_CONFIG ?= $(CURDIR)/relx.config +RELX_CONFIG_SCRIPT ?= $(CURDIR)/relx.config.script RELX_OUTPUT_DIR ?= _rel RELX_REL_EXT ?= @@ -19,7 +20,7 @@ endif # Core targets. ifeq ($(IS_DEP),) -ifneq ($(wildcard $(RELX_CONFIG)),) +ifneq ($(wildcard $(RELX_CONFIG))$(wildcard $(RELX_CONFIG_SCRIPT)),) rel:: relx-rel relup:: relx-relup @@ -30,8 +31,28 @@ distclean:: distclean-relx-rel # Plugin-specific targets. +define relx_get_config.erl + (fun() -> + Config0 = + case file:consult("$(call core_native_path,$(RELX_CONFIG))") of + {ok, Terms} -> + Terms; + {error, _} -> + [] + end, + case filelib:is_file("$(call core_native_path,$(RELX_CONFIG_SCRIPT))") of + true -> + Bindings = erl_eval:add_binding('CONFIG', Config0, erl_eval:new_bindings()), + {ok, Config1} = file:script("$(call core_native_path,$(RELX_CONFIG_SCRIPT))", Bindings), + Config1; + false -> + Config0 + end + end)() +endef + define relx_release.erl - {ok, Config} = file:consult("$(call core_native_path,$(RELX_CONFIG))"), + Config = $(call relx_get_config.erl), {release, {Name, Vsn0}, _} = lists:keyfind(release, 1, Config), Vsn = case Vsn0 of {cmd, Cmd} -> os:cmd(Cmd); @@ -46,7 +67,7 @@ define relx_release.erl endef define relx_tar.erl - {ok, Config} = file:consult("$(call core_native_path,$(RELX_CONFIG))"), + Config = $(call relx_get_config.erl), {release, {Name, Vsn0}, _} = lists:keyfind(release, 1, Config), Vsn = case Vsn0 of {cmd, Cmd} -> os:cmd(Cmd); @@ -61,7 +82,7 @@ define relx_tar.erl endef define relx_relup.erl - {ok, Config} = file:consult("$(call core_native_path,$(RELX_CONFIG))"), + Config = $(call relx_get_config.erl), {release, {Name, Vsn0}, _} = lists:keyfind(release, 1, Config), Vsn = case Vsn0 of {cmd, Cmd} -> os:cmd(Cmd); @@ -99,12 +120,12 @@ relx-post-rel:: # Run target. -ifeq ($(wildcard $(RELX_CONFIG)),) +ifeq ($(wildcard $(RELX_CONFIG))$(wildcard $(RELX_CONFIG_SCRIPT)),) run:: else define get_relx_release.erl - {ok, Config} = file:consult("$(call core_native_path,$(RELX_CONFIG))"), + Config = $(call relx_get_config.erl), {release, {Name, Vsn0}, _} = lists:keyfind(release, 1, Config), Vsn = case Vsn0 of {cmd, Cmd} -> os:cmd(Cmd); diff --git a/test/plugin_relx.mk b/test/plugin_relx.mk index 15a54b8..313e043 100644 --- a/test/plugin_relx.mk +++ b/test/plugin_relx.mk @@ -145,6 +145,99 @@ relx-post-rel: init $i "Check that the output directory was removed entirely" $t test ! -d $(APP)/_rel/ +relx-rel-with-script: init + + $i "Bootstrap a new release named $(APP)" + $t mkdir $(APP)/ + $t cp ../erlang.mk $(APP)/ + $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v + + $i "Create a relx.config.script file" + $t printf "%s\n" \ + "{release, {App, _Ver}, Apps} = lists:keyfind(release, 1, CONFIG)," \ + "lists:keyreplace(release, 1, CONFIG, {release, {App, \"ONE\"}, Apps})." \ + > $(APP)/relx.config.script + + $i "Build the release" + $t $(MAKE) -C $(APP) $v + + $i "Check that the release was built" + $t test -d $(APP)/_rel + $t test -d $(APP)/_rel/$(APP)_release + $t test -d $(APP)/_rel/$(APP)_release/bin + $t test -d $(APP)/_rel/$(APP)_release/lib + $t test -d $(APP)/_rel/$(APP)_release/releases + $t test -d $(APP)/_rel/$(APP)_release/releases/ONE + + $i "Clean the application" + $t $(MAKE) -C $(APP) clean $v + + $i "Check that the release still exists" + $t test -d $(APP)/_rel + $t test -d $(APP)/_rel/$(APP)_release + $t test -d $(APP)/_rel/$(APP)_release/bin + $t test -d $(APP)/_rel/$(APP)_release/lib + $t test -d $(APP)/_rel/$(APP)_release/releases + $t test -d $(APP)/_rel/$(APP)_release/releases/ONE + + $i "Distclean the application" + $t $(MAKE) -C $(APP) distclean $v + + $i "Check that the output directory was removed entirely" + $t test ! -d $(APP)/_rel/ + +define relx-rel-with-only-script-relx.config.script.erl +endef + +relx-rel-with-script-only: init + + $i "Bootstrap a new release named $(APP)" + $t mkdir $(APP)/ + $t cp ../erlang.mk $(APP)/ + $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v + + $i "Delete relx.config and create a relx.config.script file" + $t rm -f $(APP)/relx.config + $t printf "%s\n" \ + "CONFIG = [], %% Assert that config is empty." \ + "[" \ + " {release, {$(APP)_release, \"ONE\"}, [$(APP), sasl, runtime_tools]}," \ + " {dev_mode, false}," \ + " {include_erts, true}," \ + " {extended_start_script, true}," \ + " {sys_config, \"config/sys.config\"}," \ + " {vm_args, \"config/vm.args\"}" \ + "| CONFIG]." \ + > $(APP)/relx.config.script + + $i "Build the release" + $t $(MAKE) -C $(APP) $v + + $i "Check that the release was built" + $t test -d $(APP)/_rel + $t test -d $(APP)/_rel/$(APP)_release + $t test -d $(APP)/_rel/$(APP)_release/bin + $t test -d $(APP)/_rel/$(APP)_release/lib + $t test -d $(APP)/_rel/$(APP)_release/releases + $t test -d $(APP)/_rel/$(APP)_release/releases/ONE + + $i "Clean the application" + $t $(MAKE) -C $(APP) clean $v + + $i "Check that the release still exists" + $t test -d $(APP)/_rel + $t test -d $(APP)/_rel/$(APP)_release + $t test -d $(APP)/_rel/$(APP)_release/bin + $t test -d $(APP)/_rel/$(APP)_release/lib + $t test -d $(APP)/_rel/$(APP)_release/releases + $t test -d $(APP)/_rel/$(APP)_release/releases/ONE + + $i "Distclean the application" + $t $(MAKE) -C $(APP) distclean $v + + $i "Check that the output directory was removed entirely" + $t test ! -d $(APP)/_rel/ + ifneq ($(PLATFORM),msys2) # This test is currently disabled on Windows because we are # running into too many issues preventing the test from |