Browse Source

Fix concurrent creation of `recursive-*deps-list.log` files

To do that, we simply include the PID of the Make process in temporary
file.

We also compare the finished temporary file with the actual target file.
If they are different, the temporary file is moved to the final target,
otherwise, we just get rid of the temporary file. This way, the target
timestamp stays the same if the content does not change.
Jean-Sébastien Pédron 5 years ago
parent
commit
a9a667e5bc
1 changed files with 6 additions and 2 deletions
  1. 6 2
      core/deps-tools.mk

+ 6 - 2
core/deps-tools.mk

@@ -53,7 +53,7 @@ ifneq ($(filter shell,$(DEP_TYPES)),)
 $(ERLANG_MK_RECURSIVE_DEPS_LIST): $(ALL_SHELL_DEPS_DIRS)
 $(ERLANG_MK_RECURSIVE_DEPS_LIST): $(ALL_SHELL_DEPS_DIRS)
 endif
 endif
 
 
-ERLANG_MK_RECURSIVE_TMP_LIST := $(abspath $(ERLANG_MK_TMP)/recursive-tmp-deps.log)
+ERLANG_MK_RECURSIVE_TMP_LIST := $(abspath $(ERLANG_MK_TMP)/recursive-tmp-deps-$(shell echo $$PPID).log)
 
 
 $(ERLANG_MK_RECURSIVE_DEPS_LIST) \
 $(ERLANG_MK_RECURSIVE_DEPS_LIST) \
 $(ERLANG_MK_RECURSIVE_DOC_DEPS_LIST) \
 $(ERLANG_MK_RECURSIVE_DOC_DEPS_LIST) \
@@ -82,7 +82,11 @@ endif
 		fi \
 		fi \
 	done
 	done
 ifeq ($(IS_APP)$(IS_DEP),)
 ifeq ($(IS_APP)$(IS_DEP),)
-	$(verbose) sort < $(ERLANG_MK_RECURSIVE_TMP_LIST) | uniq > $@
+	$(verbose) sort < $(ERLANG_MK_RECURSIVE_TMP_LIST) | \
+		uniq > $(ERLANG_MK_RECURSIVE_TMP_LIST).sorted
+	$(verbose) cmp -s $(ERLANG_MK_RECURSIVE_TMP_LIST).sorted $@ \
+		|| mv $(ERLANG_MK_RECURSIVE_TMP_LIST).sorted $@
+	$(verbose) rm -f $(ERLANG_MK_RECURSIVE_TMP_LIST).sorted
 	$(verbose) rm $(ERLANG_MK_RECURSIVE_TMP_LIST)
 	$(verbose) rm $(ERLANG_MK_RECURSIVE_TMP_LIST)
 endif
 endif
 endif # ifneq ($(SKIP_DEPS),)
 endif # ifneq ($(SKIP_DEPS),)