Skip to content

Commit 129173f

Browse files
committed
Auto merge of #22997 - pnkfelix:make-timestamps-robust-to-concurrent-edits, r=nikomatsakis
Make build timestamp files robust in face of concurrent source modification. Strategy: If the end goal is to touch e.g. `stamp.std`, then we first touch `stamp.std.start_time` before doing anything else. Then when the receipe finishes, we touch `stamp.std` using the timestamp from `stamp.std.start_time` as the reference time, and remove `stamp.std.start_time`. Fix #6518.
2 parents 14f0942 + 62aa899 commit 129173f

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

mk/debuggers.mk

+12-6
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,32 @@ define DEF_INSTALL_DEBUGGER_SCRIPTS_HOST
5656
tmp/install-debugger-scripts$(1)_H_$(2)-gdb.done: \
5757
$$(DEBUGGER_RUSTLIB_ETC_SCRIPTS_GDB_ABS) \
5858
$$(DEBUGGER_BIN_SCRIPTS_GDB_ABS)
59+
$(Q)touch $$@.start_time
5960
$(Q)mkdir -p $$(HBIN$(1)_H_$(2))
6061
$(Q)mkdir -p $$(HLIB$(1)_H_$(2))/rustlib/etc
6162
$(Q)install $$(DEBUGGER_BIN_SCRIPTS_GDB_ABS) $$(HBIN$(1)_H_$(2))
6263
$(Q)install $$(DEBUGGER_RUSTLIB_ETC_SCRIPTS_GDB_ABS) $$(HLIB$(1)_H_$(2))/rustlib/etc
63-
$(Q)touch $$@
64+
$(Q)touch -r $$@.start_time $$@ && rm $$@.start_time
6465

6566
tmp/install-debugger-scripts$(1)_H_$(2)-lldb.done: \
6667
$$(DEBUGGER_RUSTLIB_ETC_SCRIPTS_LLDB_ABS) \
6768
$$(DEBUGGER_BIN_SCRIPTS_LLDB_ABS)
69+
$(Q)touch $$@.start_time
6870
$(Q)mkdir -p $$(HBIN$(1)_H_$(2))
6971
$(Q)mkdir -p $$(HLIB$(1)_H_$(2))/rustlib/etc
7072
$(Q)install $$(DEBUGGER_BIN_SCRIPTS_LLDB_ABS) $$(HBIN$(1)_H_$(2))
7173
$(Q)install $$(DEBUGGER_RUSTLIB_ETC_SCRIPTS_LLDB_ABS) $$(HLIB$(1)_H_$(2))/rustlib/etc
72-
$(Q)touch $$@
74+
$(Q)touch -r $$@.start_time $$@ && rm $$@.start_time
7375

7476
tmp/install-debugger-scripts$(1)_H_$(2)-all.done: \
7577
$$(DEBUGGER_RUSTLIB_ETC_SCRIPTS_ALL_ABS) \
7678
$$(DEBUGGER_BIN_SCRIPTS_ALL_ABS)
79+
$(Q)touch $$@.start_time
7780
$(Q)mkdir -p $$(HBIN$(1)_H_$(2))
7881
$(Q)mkdir -p $$(HLIB$(1)_H_$(2))/rustlib/etc
7982
$(Q)install $$(DEBUGGER_BIN_SCRIPTS_ALL_ABS) $$(HBIN$(1)_H_$(2))
8083
$(Q)install $$(DEBUGGER_RUSTLIB_ETC_SCRIPTS_ALL_ABS) $$(HLIB$(1)_H_$(2))/rustlib/etc
81-
$(Q)touch $$@
84+
$(Q)touch -r $$@.start_time $$@ && rm $$@.start_time
8285

8386
tmp/install-debugger-scripts$(1)_H_$(2)-none.done:
8487
$(Q)touch $$@
@@ -98,29 +101,32 @@ define DEF_INSTALL_DEBUGGER_SCRIPTS_TARGET
98101
tmp/install-debugger-scripts$(1)_T_$(2)_H_$(3)-gdb.done: \
99102
$$(DEBUGGER_RUSTLIB_ETC_SCRIPTS_GDB_ABS) \
100103
$$(DEBUGGER_BIN_SCRIPTS_GDB_ABS)
104+
$(Q)touch $$@.start_time
101105
$(Q)mkdir -p $$(TBIN$(1)_T_$(2)_H_$(3))
102106
$(Q)mkdir -p $$(TLIB$(1)_T_$(2)_H_$(3))/rustlib/etc
103107
$(Q)install $(DEBUGGER_BIN_SCRIPTS_GDB_ABS) $$(TBIN$(1)_T_$(2)_H_$(3))
104108
$(Q)install $(DEBUGGER_RUSTLIB_ETC_SCRIPTS_GDB_ABS) $$(TLIB$(1)_T_$(2)_H_$(3))/rustlib/etc
105-
$(Q)touch $$@
109+
$(Q)touch -r $$@.start_time $$@ && rm $$@.start_time
106110

107111
tmp/install-debugger-scripts$(1)_T_$(2)_H_$(3)-lldb.done: \
108112
$$(DEBUGGER_RUSTLIB_ETC_SCRIPTS_LLDB_ABS) \
109113
$$(DEBUGGER_BIN_SCRIPTS_LLDB_ABS)
114+
$(Q)touch $$@.start_time
110115
$(Q)mkdir -p $$(TBIN$(1)_T_$(2)_H_$(3))
111116
$(Q)mkdir -p $$(TLIB$(1)_T_$(2)_H_$(3))/rustlib/etc
112117
$(Q)install $(DEBUGGER_BIN_SCRIPTS_LLDB_ABS) $$(TBIN$(1)_T_$(2)_H_$(3))
113118
$(Q)install $(DEBUGGER_RUSTLIB_ETC_SCRIPTS_LLDB_ABS) $$(TLIB$(1)_T_$(2)_H_$(3))/rustlib/etc
114-
$(Q)touch $$@
119+
$(Q)touch -r $$@.start_time $$@ && rm $$@.start_time
115120

116121
tmp/install-debugger-scripts$(1)_T_$(2)_H_$(3)-all.done: \
117122
$$(DEBUGGER_RUSTLIB_ETC_SCRIPTS_ALL_ABS) \
118123
$$(DEBUGGER_BIN_SCRIPTS_ALL_ABS)
124+
$(Q)touch $$@.start_time
119125
$(Q)mkdir -p $$(TBIN$(1)_T_$(2)_H_$(3))
120126
$(Q)mkdir -p $$(TLIB$(1)_T_$(2)_H_$(3))/rustlib/etc
121127
$(Q)install $(DEBUGGER_BIN_SCRIPTS_ALL_ABS) $$(TBIN$(1)_T_$(2)_H_$(3))
122128
$(Q)install $(DEBUGGER_RUSTLIB_ETC_SCRIPTS_ALL_ABS) $$(TLIB$(1)_T_$(2)_H_$(3))/rustlib/etc
123-
$(Q)touch $$@
129+
$(Q)touch -r $$@.start_time $$@ && rm $$@.start_time
124130

125131
tmp/install-debugger-scripts$(1)_T_$(2)_H_$(3)-none.done:
126132
$(Q)touch $$@

mk/llvm.mk

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ endif
3838
# the stamp in the source dir.
3939
$$(LLVM_STAMP_$(1)): $(S)src/rustllvm/llvm-auto-clean-trigger
4040
@$$(call E, make: cleaning llvm)
41+
$(Q)touch $$@.start_time
4142
$(Q)$(MAKE) clean-llvm$(1)
4243
@$$(call E, make: done cleaning llvm)
43-
touch $$@
44+
touch -r $$@.start_time $$@ && rm $$@.start_time
4445

4546
ifeq ($$(CFG_ENABLE_LLVM_STATIC_STDCPP),1)
4647
LLVM_STDCPP_LOCATION_$(1) = $$(shell $$(CC_$(1)) $$(CFG_GCCISH_CFLAGS_$(1)) \

mk/target.mk

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \
7575
$$(TSREQ$(1)_T_$(2)_H_$(3)) \
7676
| $$(TLIB$(1)_T_$(2)_H_$(3))/
7777
@$$(call E, rustc: $$(@D)/lib$(4))
78+
@touch $$@.start_time
7879
$$(call REMOVE_ALL_OLD_GLOB_MATCHES, \
7980
$$(dir $$@)$$(call CFG_LIB_GLOB_$(2),$(4)))
8081
$$(call REMOVE_ALL_OLD_GLOB_MATCHES, \
@@ -89,7 +90,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \
8990
--out-dir $$(@D) \
9091
-C extra-filename=-$$(CFG_FILENAME_EXTRA) \
9192
$$<
92-
@touch $$@
93+
@touch -r $$@.start_time $$@ && rm $$@.start_time
9394
$$(call LIST_ALL_OLD_GLOB_MATCHES, \
9495
$$(dir $$@)$$(call CFG_LIB_GLOB_$(2),$(4)))
9596
$$(call LIST_ALL_OLD_GLOB_MATCHES, \

mk/tests.mk

+16-7
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,11 @@ check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4
389389
$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
390390
$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
391391
@$$(call E, run: $$<)
392+
$$(Q)touch $$@.start_time
392393
$$(Q)$$(call CFG_RUN_TEST_$(2),$$<,$(1),$(2),$(3)) $$(TESTARGS) \
393394
--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
394395
$$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) \
395-
&& touch $$@
396+
&& touch -r $$@.start_time $$@ && rm $$@.start_time
396397
endef
397398

398399
define DEF_TEST_CRATE_RULES_android
@@ -401,6 +402,7 @@ check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4
401402
$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
402403
$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
403404
@$$(call E, run: $$< via adb)
405+
$$(Q)touch $$@.start_time
404406
$$(Q)$(CFG_ADB) push $$< $(CFG_ADB_TEST_DIR)
405407
$$(Q)$(CFG_ADB) shell '(cd $(CFG_ADB_TEST_DIR); LD_LIBRARY_PATH=./$(2) \
406408
./$$(notdir $$<) \
@@ -414,7 +416,7 @@ $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
414416
@if grep -q "result: ok" tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
415417
then \
416418
rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
417-
touch $$@; \
419+
touch -r $$@.start_time $$@ && rm $$@.start_time; \
418420
else \
419421
rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
420422
exit 101; \
@@ -690,10 +692,11 @@ $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
690692
$$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
691693
$$(CTEST_DEPS_$(4)_$(1)-T-$(2)-H-$(3))
692694
@$$(call E, run $(4) [$(2)]: $$<)
695+
$$(Q)touch $$@.start_time
693696
$$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
694697
$$(CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
695698
--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
696-
&& touch $$@
699+
&& touch -r $$@.start_time $$@ && rm $$@.start_time
697700

698701
else
699702

@@ -750,10 +753,11 @@ $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
750753
$$(PRETTY_DEPS_$(4)) \
751754
$$(PRETTY_DEPS$(1)_H_$(3)_$(4))
752755
@$$(call E, run pretty-rpass [$(2)]: $$<)
756+
$$(Q)touch $$@.start_time
753757
$$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
754758
$$(PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
755759
--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
756-
&& touch $$@
760+
&& touch -r $$@.start_time $$@ && rm $$@.start_time
757761

758762
endef
759763

@@ -799,8 +803,10 @@ endif
799803
ifeq ($(2),$$(CFG_BUILD))
800804
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)): $$(DOCTESTDEP_$(1)_$(2)_$(3)_$(4))
801805
@$$(call E, run doc-$(4) [$(2)])
806+
$$(Q)touch $$@.start_time
802807
$$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --cfg dox --test $$< \
803-
--test-args "$$(TESTARGS)" && touch $$@
808+
--test-args "$$(TESTARGS)" && \
809+
touch -r $$@.start_time $$@ && rm $$@.start_time
804810
else
805811
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)):
806812
touch $$@
@@ -835,9 +841,11 @@ check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$(4)-exec: \
835841
ifeq ($(2),$$(CFG_BUILD))
836842
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)): $$(CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4))
837843
@$$(call E, run doc-crate-$(4) [$(2)])
844+
$$(Q)touch $$@.start_time
838845
$$(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(3)) \
839846
$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --test --cfg dox \
840-
$$(CRATEFILE_$(4)) --test-args "$$(TESTARGS)" && touch $$@
847+
$$(CRATEFILE_$(4)) --test-args "$$(TESTARGS)" && \
848+
touch -r $$@.start_time $$@ && rm $$@.start_time
841849
else
842850
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)):
843851
touch $$@
@@ -984,6 +992,7 @@ $(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
984992
$$(CSREQ$(1)_T_$(2)_H_$(3))
985993
@rm -rf $(3)/test/run-make/$$*
986994
@mkdir -p $(3)/test/run-make/$$*
995+
$$(Q)touch $$@.start_time
987996
$$(Q)$$(CFG_PYTHON) $(S)src/etc/maketest.py $$(dir $$<) \
988997
$$(MAKE) \
989998
$$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
@@ -996,7 +1005,7 @@ $(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
9961005
"$$(LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3))" \
9971006
$(1) \
9981007
$$(S)
999-
@touch $$@
1008+
@touch -r $$@.start_time $$@ && rm $$@.start_time
10001009
else
10011010
# FIXME #11094 - The above rule doesn't work right for multiple targets
10021011
check-stage$(1)-T-$(2)-H-$(3)-rmake-exec:

0 commit comments

Comments
 (0)