From 6372d2674cffcab8e6426cba80ef216c3ae1d0cf Mon Sep 17 00:00:00 2001 From: Tyler Hughes Date: Sun, 29 Jan 2023 18:02:44 +0000 Subject: Allow git + hex deps to be cached to XDG_CACHE_HOME --- test/Makefile | 4 +++- test/core_deps.mk | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) (limited to 'test') 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 -- cgit v1.2.3