aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorTyler Hughes <[email protected]>2023-01-29 18:02:44 +0000
committerLoïc Hoguin <[email protected]>2023-05-15 13:47:54 +0200
commit6372d2674cffcab8e6426cba80ef216c3ae1d0cf (patch)
tree0fa214351baa313eb351bbeef0439f67e19972ed /test
parenta79d0c00534584ffdefd3179256cac8e34b4febe (diff)
downloaderlang.mk-6372d2674cffcab8e6426cba80ef216c3ae1d0cf.tar.gz
erlang.mk-6372d2674cffcab8e6426cba80ef216c3ae1d0cf.tar.bz2
erlang.mk-6372d2674cffcab8e6426cba80ef216c3ae1d0cf.zip
Allow git + hex deps to be cached to XDG_CACHE_HOME
Diffstat (limited to 'test')
-rw-r--r--test/Makefile4
-rw-r--r--test/core_deps.mk51
2 files changed, 54 insertions, 1 deletions
diff --git a/test/Makefile b/test/Makefile
index f341345..82873f0 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -13,6 +13,8 @@ endif
# Temporary application name, taken from rule name.
APP = test_$(subst -,_,$@)
+CACHE_DIR = $(CURDIR)/$(APP).cache
+export CACHE_DIR
# Erlang, quickly!
@@ -126,7 +128,7 @@ endef
all:: core
clean::
- $t rm -rf erl_crash.dump packages/ $(filter-out test_rebar_git/,$(wildcard test_*/))
+ $t rm -rf erl_crash.dump packages/ $(filter-out test_rebar_git/,$(wildcard test_*/)) $(CACHE_DIR)
init: clean
$i "Prefetch Rebar if necessary"
diff --git a/test/core_deps.mk b/test/core_deps.mk
index 1dbf7b8..1d7eefc 100644
--- a/test/core_deps.mk
+++ b/test/core_deps.mk
@@ -1476,3 +1476,54 @@ core-deps-test: init
{ok, Deps} = application:get_key($(APP), applications), \
false = lists:member(triq, Deps), \
halt()"
+
+# Checks that the cache is populate and reused
+core-deps-cache-creation: init
+ $i "Bootstrap a new OTP library named $(APP)"
+ $t mkdir $(APP)/
+ $t cp ../erlang.mk $(APP)/
+ $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
+ $t tmp=`mktemp` && { echo 'DEPS += cowlib' && echo 'CACHE_DEPS=1' && cat $(APP)/Makefile; } >> $$tmp && mv $$tmp $(APP)/Makefile
+ $i "Check that the Cache Directory doesn't exist yet"
+ $t test ! -d $(CACHE_DIR)
+ $i "Pull down & Cache the deps"
+ $t $(MAKE) -C $(APP) deps
+ $i "Check that the Cache Directory has been created"
+ $t test -d $(CACHE_DIR)
+ $i "Check that cowlib was cloned"
+ $t test -d $(CACHE_DIR)/gits/cowlib
+ $t $(MAKE) -C $(APP) distclean
+ $i "Check that cowlib is still in the cache"
+ $t test -d $(CACHE_DIR)/gits/cowlib
+ $i "Break cowlib git link so we're forced to use the cache"
+ $t echo 'dep_cowlib = git bad_url master' >> $(APP)/Makefile
+ $i "Pull down the deps from the cache"
+ $t $(MAKE) -C $(APP) deps
+ $i "Check that cowlib was cloned"
+ $t test -d $(CACHE_DIR)/gits/cowlib
+
+# Checks that 2 apps can reuse the cache
+# with different versions of the same dep
+core-deps-cache-reuse: init
+ $i "Bootstrap a new OTP library named $(APP)_1"
+ $t mkdir $(APP)_1/
+ $t cp ../erlang.mk $(APP)_1/
+ $t $(MAKE) -C $(APP)_1 -f erlang.mk bootstrap-lib $v
+ $t tmp=`mktemp` && { echo 'DEPS += cowlib' && echo 'dep_cowlib = git $$(pkg_cowlib_repo) 1.0.0' && echo 'CACHE_DEPS=1' && cat $(APP)_1/Makefile; } >> $$tmp && mv $$tmp $(APP)_1/Makefile
+ $i "Bootstrap a new OTP library named $(APP)_2"
+ $t mkdir $(APP)_2/
+ $t cp ../erlang.mk $(APP)_2/
+ $t $(MAKE) -C $(APP)_2 -f erlang.mk bootstrap-lib $v
+ $t tmp=`mktemp` && { echo 'DEPS += cowlib' && echo 'dep_cowlib = git $$(pkg_cowlib_repo) 2.0.0' && echo 'CACHE_DEPS=1' && cat $(APP)_2/Makefile; } >> $$tmp && mv $$tmp $(APP)_2/Makefile
+ $i "Clone & Cache deps in $(APP)_1"
+ $t $(MAKE) -C $(APP)_1 deps
+ $i "Check that the Cache Directory has been created"
+ $t test -d $(CACHE_DIR)
+ $i "Check that cowlib was cloned"
+ $t test -d $(CACHE_DIR)/gits/cowlib
+ $i "Clone & Re-use cached deps in $(APP)_2"
+ $t $(MAKE) -C $(APP)_2 deps
+ $i "Check that $(APP)_1 cloned cowlib 1.x.x"
+ $t test "$$(cat $(APP)_1/deps/cowlib/.git/HEAD)" = "d544a494af4dbc810fc9c15eaf5cc050cced1501"
+ $i "Check that $(APP)_2 cloned cowlib 2.x.x"
+ $t test "$$(cat $(APP)_2/deps/cowlib/.git/HEAD)" = "bd37be4d3b065600c3b76b492535e76e5d413fc1" \ No newline at end of file