aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2025-02-11 15:34:58 +0100
committerLoïc Hoguin <[email protected]>2025-02-11 15:34:58 +0100
commite9331856f9b0fab47ad10104721472262a501af9 (patch)
treed05a461729672cdb1379ef6ac0bd33cc82f39a68
parent509b15b59e6034b2099a356b243b017fd099e2af (diff)
downloaderlang.mk-e9331856f9b0fab47ad10104721472262a501af9.tar.gz
erlang.mk-e9331856f9b0fab47ad10104721472262a501af9.tar.bz2
erlang.mk-e9331856f9b0fab47ad10104721472262a501af9.zip
Add support for specifying Hex requirements for dependencies
This allows overriding the default which is to use the same explicit version as the dep_* line, and instead specify ranges of versions.
-rw-r--r--plugins/hex.mk2
-rw-r--r--test/plugin_hex.mk30
2 files changed, 31 insertions, 1 deletions
diff --git a/plugins/hex.mk b/plugins/hex.mk
index 44beb65..482a56a 100644
--- a/plugins/hex.mk
+++ b/plugins/hex.mk
@@ -91,7 +91,7 @@ define hex_tarball_create.erl
<<"$(if $(subst hex,,$(call query_fetch_method,$d)),$d,$(if $(word 3,$(dep_$d)),$(word 3,$(dep_$d)),$d))">> => #{
<<"app">> => <<"$d">>,
<<"optional">> => false,
- <<"requirement">> => <<"$(call query_version,$d)">>
+ <<"requirement">> => <<"$(if $(hex_req_$d),$(strip $(hex_req_$d)),$(call query_version,$d))">>
},)
$(if $(DEPS),dummy => dummy)
},
diff --git a/test/plugin_hex.mk b/test/plugin_hex.mk
index 99e6356..27060b6 100644
--- a/test/plugin_hex.mk
+++ b/test/plugin_hex.mk
@@ -162,6 +162,36 @@ endif
{_, <<\"2.13.0\">>} = lists:keyfind(<<\"requirement\">>, 1, Cowlib), \
halt(0)"
+hex-tarball-create-with-req: init
+
+ $i "Bootstrap a new OTP application named $(APP)"
+ $t mkdir $(APP)/
+ $t cp ../erlang.mk $(APP)/
+ $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
+
+ $i "Add Cowlib to the list of dependencies"
+ $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowlib\ndep_cowlib_commit = 2.13.0\nhex_req_cowlib = ~> 2.13\n"}' $(APP)/Makefile
+
+ifdef LEGACY
+ $i "Add Cowlib to the applications key in the .app.src file"
+ $t perl -ni.bak -e 'print;if ($$.==7) {print "\t\tcowlib,\n"}' $(APP)/src/$(APP).app.src
+endif
+
+ $i "Create a release tarball"
+ $t $(MAKE) -C $(APP) hex-tarball-create $v
+
+ $i "Confirm the tarball contents can be extracted"
+ $t cd $(APP)/.erlang.mk/ && tar xf $(APP).tar
+
+ $i "Confirm the tarball contains a metadata.config file that lists Cowlib as requirement"
+ $t $(ERL) -eval " \
+ {ok, Metadata} = file:consult(\"$(APP)/.erlang.mk/metadata.config\"), \
+ {_, [{<<\"cowlib\">>, Cowlib}]} = lists:keyfind(<<\"requirements\">>, 1, Metadata), \
+ {_, <<\"cowlib\">>} = lists:keyfind(<<\"app\">>, 1, Cowlib), \
+ {_, false} = lists:keyfind(<<\"optional\">>, 1, Cowlib), \
+ {_, <<\"~> 2.13\">>} = lists:keyfind(<<\"requirement\">>, 1, Cowlib), \
+ halt(0)"
+
hex-release-publish: init
$i "Bootstrap a new OTP application named $(APP)"