From 8f8088ac4df9b4d4660f0b15d09f3fdaa991bea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 26 Nov 2018 07:57:55 +0100 Subject: Use flock/lockf when available to avoid a -j issue Fetching rebar is conditional depending on the project being built, and if two projects require it and -j is used this could mean the fetching happens at the same time and one would fail. --- core/deps.mk | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'core/deps.mk') diff --git a/core/deps.mk b/core/deps.mk index d5b12a6..fa6ad84 100644 --- a/core/deps.mk +++ b/core/deps.mk @@ -198,8 +198,19 @@ define dep_autopatch_gen "include ../../erlang.mk" > $(DEPS_DIR)/$(1)/Makefile endef +# We use flock/lockf when available to avoid concurrency issues. define dep_autopatch_fetch_rebar mkdir -p $(ERLANG_MK_TMP); \ + if command -v flock >/dev/null; then \ + flock $(ERLANG_MK_TMP)/rebar.lock -c "$(call dep_autopatch_fetch_rebar2)"; \ + elif command -v lockf >/dev/null; then \ + lockf $(ERLANG_MK_TMP)/rebar.lock sh -c "$(call dep_autopatch_fetch_rebar2)"; \ + else \ + $(call dep_autopatch_fetch_rebar2); \ + fi +endef + +define dep_autopatch_fetch_rebar2 if [ ! -d $(ERLANG_MK_TMP)/rebar ]; then \ git clone -q -n -- https://github.com/rebar/rebar $(ERLANG_MK_TMP)/rebar; \ cd $(ERLANG_MK_TMP)/rebar; \ -- cgit v1.2.3