Skip to content

Commit 033ac54

Browse files
committed
Fix rust-lang#3225: Check for old Rust libraries when building and installing.
When building Rust libraries (e.g. librustc, libstd, etc), checks for and verbosely removes previous build products before invoking rustc. (Also, when Make variable VERBOSE is defined, it will list all of the libraries matching the object library's glob after the rustc invocation has completed.) When installing Rust libraries, checks for previous libraries in target install directory, but does not remove them. The thinking behind these two different modes of operation is that the installation target, unlike the build tree, is not under the control of this infrastructure and it is not up to this Makefile to decide if the previous libraries should be removed.
1 parent 63f7857 commit 033ac54

File tree

6 files changed

+171
-57
lines changed

6 files changed

+171
-57
lines changed

Makefile.in

+27
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,33 @@ LIBRUST_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rust)
235235

236236
endef
237237

238+
# $(1) is the path for directory to match against
239+
# $(2) is the glob to use in the match
240+
# $(3) is filename (usually the target being created) to filter out from match
241+
# (i.e. filename is not out-of-date artifact from prior Rust version/build)
242+
# The glob denoted by $(2) often is constructed with a space character prefix,
243+
# which is why we cannot just do `ls` on $(1)/$(2).
244+
define CHECK_FOR_OLD_GLOB_MATCHES_EXCEPT
245+
$(Q)( cd $(1) && ( ls $(2) 2>/dev/null || true ) | grep -v $(3) > /dev/null && echo "Warning: there are previous" '$(2)' "libraries:" || true )
246+
$(Q)( cd $(1) && ( ls $(2) 2>/dev/null || true ) | grep -v $(3) || true )
247+
endef
248+
249+
# Same interface as above, but deletes rather than just listing the files.
250+
define REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT
251+
$(Q)( cd $(1) && ( ls $(2) 2>/dev/null || true ) | grep -v $(3) > /dev/null && echo "Warning: removing previous" '$(2)' "libraries:" || true )
252+
$(Q)( cd $(1) && ( ls $(2) 2>/dev/null || true ) | grep -v $(3) | xargs rm -v )
253+
endef
254+
255+
ifdef VERBOSE
256+
define LIST_ALL_OLD_GLOB_MATCHES_EXCEPT
257+
@echo "Info: now are following matches for" '$(2)' "libraries:"
258+
@( cd $(1) && ( ls $(2) 2>/dev/null || true ) | grep -v $(3) || true )
259+
endef
260+
else
261+
define LIST_ALL_OLD_GLOB_MATCHES_EXCEPT
262+
endef
263+
endif
264+
238265
$(foreach target,$(CFG_TARGET_TRIPLES),\
239266
$(eval $(call DEF_LIBS,$(target))))
240267

mk/host.mk

+8
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ $$(HLIB$(2)_H_$(4))/$(CFG_LIBRUSTC_$(4)): \
4545
| $$(HLIB$(2)_H_$(4))/
4646

4747
@$$(call E, cp: $$@)
48+
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(LIBRUSTC_GLOB_$(4)), `basename $$@`)
4849
$$(Q)cp $$< $$@
4950
$$(Q)cp -R $$(TLIB$(1)_T_$(4)_H_$(3))/$(LIBRUSTC_GLOB_$(4)) \
5051
$(wildcard $$(TLIB$(1)_T_$(4)_H_$(3))/$(LIBRUSTC_DSYM_GLOB_$(4))) \
5152
$$(HLIB$(2)_H_$(4))
53+
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(LIBRUSTC_GLOB_$(4)), `basename $$@`)
5254

5355
$$(HLIB$(2)_H_$(4))/$(CFG_LIBSYNTAX_$(4)): \
5456
$$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_LIBSYNTAX_$(4)) \
@@ -58,10 +60,12 @@ $$(HLIB$(2)_H_$(4))/$(CFG_LIBSYNTAX_$(4)): \
5860
$$(HEXTRALIB_DEFAULT$(2)_H_$(4)) \
5961
| $$(HLIB$(2)_H_$(4))/
6062
@$$(call E, cp: $$@)
63+
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(LIBSYNTAX_GLOB_$(4)), `basename $$@`)
6164
$$(Q)cp $$< $$@
6265
$$(Q)cp -R $$(TLIB$(1)_T_$(4)_H_$(3))/$(LIBSYNTAX_GLOB_$(4)) \
6366
$$(wildcard $$(TLIB$(1)_T_$(4)_H_$(3))/$(LIBSYNTAX_DSYM_GLOB_$(4))) \
6467
$$(HLIB$(2)_H_$(4))
68+
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(LIBSYNTAX_GLOB_$(4)), `basename $$@`)
6569

6670
$$(HLIB$(2)_H_$(4))/$(CFG_RUNTIME_$(4)): \
6771
$$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_RUNTIME_$(4)) \
@@ -74,6 +78,7 @@ $$(HLIB$(2)_H_$(4))/$(CFG_STDLIB_$(4)): \
7478
$$(HLIB$(2)_H_$(4))/$(CFG_RUNTIME_$(4)) \
7579
| $$(HLIB$(2)_H_$(4))/
7680
@$$(call E, cp: $$@)
81+
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(STDLIB_GLOB_$(4)), `basename $$@`)
7782
$$(Q)cp $$< $$@
7883
# Subtle: We do not let the shell expand $(STDLIB_DSYM_GLOB) directly rather
7984
# we use Make's $$(wildcard) facility. The reason is that, on mac, when using
@@ -85,17 +90,20 @@ $$(HLIB$(2)_H_$(4))/$(CFG_STDLIB_$(4)): \
8590
$$(Q)cp -R $$(TLIB$(1)_T_$(4)_H_$(3))/$(STDLIB_GLOB_$(4)) \
8691
$$(wildcard $$(TLIB$(1)_T_$(4)_H_$(3))/$(STDLIB_DSYM_GLOB_$(4))) \
8792
$$(HLIB$(2)_H_$(4))
93+
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(STDLIB_GLOB_$(4)), `basename $$@`)
8894

8995
$$(HLIB$(2)_H_$(4))/$(CFG_EXTRALIB_$(4)): \
9096
$$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_EXTRALIB_$(4)) \
9197
$$(HLIB$(2)_H_$(4))/$(CFG_STDLIB_$(4)) \
9298
$$(HLIB$(2)_H_$(4))/$(CFG_RUNTIME_$(4)) \
9399
| $$(HLIB$(2)_H_$(4))/
94100
@$$(call E, cp: $$@)
101+
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(EXTRALIB_GLOB_$(4)), `basename $$@`)
95102
$$(Q)cp $$< $$@
96103
$$(Q)cp -R $$(TLIB$(1)_T_$(4)_H_$(3))/$(EXTRALIB_GLOB_$(4)) \
97104
$$(wildcard $$(TLIB$(1)_T_$(4)_H_$(3))/$(EXTRALIB_DSYM_GLOB_$(4))) \
98105
$$(HLIB$(2)_H_$(4))
106+
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(EXTRALIB_GLOB_$(4)), `basename $$@`)
99107

100108
$$(HLIB$(2)_H_$(4))/libstd.rlib: \
101109
$$(TLIB$(1)_T_$(4)_H_$(3))/libstd.rlib \

mk/install.mk

+10-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,21 @@
1616
# destination directory as arg 2, and filename/libname-glob as arg 3
1717
ifdef VERBOSE
1818
INSTALL = install -m755 $(1)/$(3) $(2)/$(3)
19-
INSTALL_LIB = install -m644 `ls -drt1 $(1)/$(3) | tail -1` $(2)/
19+
DO_INSTALL_LIB = install -m644 `ls -drt1 $(1)/$(3) | tail -1` $(2)/
2020
else
2121
INSTALL = $(Q)$(call E, install: $(2)/$(3)) && install -m755 $(1)/$(3) $(2)/$(3)
22-
INSTALL_LIB = $(Q)$(call E, install_lib: $(2)/$(3)) && \
22+
DO_INSTALL_LIB = $(Q)$(call E, install_lib: $(2)/$(3)) && \
2323
install -m644 `ls -drt1 $(1)/$(3) | tail -1` $(2)/
2424
endif
2525

26+
# $(1) is the source dirctory
27+
# $(2) is the destination directory
28+
# $(3) is the filename/libname-glob
29+
define INSTALL_LIB
30+
LIB_NAME=`ls -drt1 $(1)/$(3) | tail -1 | xargs basename` ; ( ls -drt1 $(2)/$(3) 2>/dev/null || true ) | grep -v $$LIB_NAME >/dev/null 2>&1 && echo "Warning, one or more libraries matching Rust library '$(3)'" && echo " (other than '$$LIB_NAME' itself) already present" && echo " at destination $(2):" && ( ls -drt1 $(2)/$(3) 2>/dev/null || true ) | grep -v $$LIB_NAME || true
31+
$(call DO_INSTALL_LIB,$(1),$(2),$(3))
32+
endef
33+
2634
# The stage we install from
2735
ISTAGE = 2
2836

mk/stage0.mk

+42-13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
# Extract the snapshot host compiler
22

3+
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/:
4+
mkdir -p $@
35

6+
$(HLIB0_H_$(CFG_BUILD_TRIPLE))/:
7+
mkdir -p $@
48

59
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE)): \
610
$(S)src/snapshots.txt \
7-
$(S)src/etc/get-snapshot.py $(MKFILE_DEPS)
11+
$(S)src/etc/get-snapshot.py $(MKFILE_DEPS) \
12+
| $(HBIN0_H_$(CFG_BUILD_TRIPLE))/
13+
814
@$(call E, fetch: $@)
915
# Note: the variable "SNAPSHOT_FILE" is generally not set, and so
1016
# we generally only pass one argument to this script.
@@ -22,23 +28,28 @@ endif
2228
# Host libs will be extracted by the above rule
2329

2430
$(HLIB0_H_$(CFG_BUILD_TRIPLE))/$(CFG_RUNTIME_$(CFG_BUILD_TRIPLE)): \
25-
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE))
31+
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE)) \
32+
| $(HLIB0_H_$(CFG_BUILD_TRIPLE))/
2633
$(Q)touch $@
2734

2835
$(HLIB0_H_$(CFG_BUILD_TRIPLE))/$(CFG_STDLIB_$(CFG_BUILD_TRIPLE)): \
29-
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE))
36+
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE)) \
37+
| $(HLIB0_H_$(CFG_BUILD_TRIPLE))/
3038
$(Q)touch $@
3139

3240
$(HLIB0_H_$(CFG_BUILD_TRIPLE))/$(CFG_EXTRALIB_$(CFG_BUILD_TRIPLE)): \
33-
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE))
41+
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE)) \
42+
| $(HLIB0_H_$(CFG_BUILD_TRIPLE))/
3443
$(Q)touch $@
3544

3645
$(HLIB0_H_$(CFG_BUILD_TRIPLE))/$(CFG_LIBRUSTC_$(CFG_BUILD_TRIPLE)): \
37-
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE))
46+
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE)) \
47+
| $(HLIB0_H_$(CFG_BUILD_TRIPLE))/
3848
$(Q)touch $@
3949

4050
$(HLIB0_H_$(CFG_BUILD_TRIPLE))/$(CFG_RUSTLLVM_$(CFG_BUILD_TRIPLE)): \
41-
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE))
51+
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE)) \
52+
| $(HLIB0_H_$(CFG_BUILD_TRIPLE))/
4253
$(Q)touch $@
4354

4455
# For other targets, let the host build the target:
@@ -48,33 +59,51 @@ define BOOTSTRAP_STAGE0
4859
# $(2) stage to bootstrap from
4960
# $(3) target to bootstrap from
5061

51-
$$(HBIN0_H_$(1))/rustc$$(X_$(1)): \
52-
$$(TBIN$(2)_T_$(1)_H_$(3))/rustc$$(X_$(1))
62+
$(HBIN0_H_$(1))/:
63+
mkdir -p $@
64+
65+
$(HLIB0_H_$(1))/:
66+
mkdir -p $@
67+
68+
$$(HBIN0_H_$(1))/rustc$$(X_$(1)): \
69+
$$(TBIN$(2)_T_$(1)_H_$(3))/rustc$$(X_$(1)) \
70+
| $(HBIN0_H_$(1))/
5371
@$$(call E, cp: $$@)
5472
$$(Q)cp $$< $$@
5573

5674
$$(HLIB0_H_$(1))/$(CFG_RUNTIME_$(1)): \
57-
$$(TLIB$(2)_T_$(1)_H_$(3))/$(CFG_RUNTIME_$(1))
75+
$$(TLIB$(2)_T_$(1)_H_$(3))/$(CFG_RUNTIME_$(1)) \
76+
| $(HLIB0_H_$(1))/
5877
@$$(call E, cp: $$@)
5978
$$(Q)cp $$< $$@
6079

6180
$$(HLIB0_H_$(1))/$(CFG_STDLIB_$(1)): \
62-
$$(TLIB$(2)_T_$(1)_H_$(3))/$(CFG_STDLIB_$(1))
81+
$$(TLIB$(2)_T_$(1)_H_$(3))/$(CFG_STDLIB_$(1)) \
82+
| $(HLIB0_H_$(1))/
6383
@$$(call E, cp: $$@)
84+
$$(call CHECK_FOR_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(EXTRALIB_GLOB_$(4)), `basename $$@`)
6485
$$(Q)cp $$(TLIB$(2)_T_$(1)_H_$(3))/$(STDLIB_GLOB_$(1)) $$@
86+
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(EXTRALIB_GLOB_$(4)), `basename $$@`)
6587

6688
$$(HLIB0_H_$(1))/$(CFG_EXTRALIB_$(1)): \
67-
$$(TLIB$(2)_T_$(1)_H_$(3))/$(CFG_EXTRALIB_$(1))
89+
$$(TLIB$(2)_T_$(1)_H_$(3))/$(CFG_EXTRALIB_$(1)) \
90+
| $(HLIB0_H_$(1))/
6891
@$$(call E, cp: $$@)
92+
$$(call CHECK_FOR_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(EXTRALIB_GLOB_$(4)), `basename $$@`)
6993
$$(Q)cp $$(TLIB$(2)_T_$(1)_H_$(3))/$(EXTRALIB_GLOB_$(1)) $$@
94+
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(EXTRALIB_GLOB_$(4)), `basename $$@`)
7095

7196
$$(HLIB0_H_$(1))/$(CFG_LIBRUSTC_$(1)): \
72-
$$(TLIB$(2)_T_$(1)_H_$(3))/$(CFG_LIBRUSTC_$(1))
97+
$$(TLIB$(2)_T_$(1)_H_$(3))/$(CFG_LIBRUSTC_$(1)) \
98+
| $(HLIB0_H_$(1))/
7399
@$$(call E, cp: $$@)
100+
$$(call CHECK_FOR_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(LIBRUSTC_GLOB_$(4)), `basename $$@`)
74101
$$(Q)cp $$(TLIB$(2)_T_$(1)_H_$(3))/$(LIBRUSTC_GLOB_$(1)) $$@
102+
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(LIBRUSTC_GLOB_$(4)), `basename $$@`)
75103

76104
$$(HLIB0_H_$(1))/$(CFG_RUSTLLVM_$(1)): \
77-
$$(TLIB$(2)_T_$(1)_H_$(3))/$(CFG_RUSTLLVM_$(1))
105+
$$(TLIB$(2)_T_$(1)_H_$(3))/$(CFG_RUSTLLVM_$(1)) \
106+
| $(HLIB0_H_$(1))/
78107
@$$(call E, cp: $$@)
79108
$$(Q)cp $$< $$@
80109

mk/target.mk

+8
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,19 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)): \
4848
$$(TSREQ$(1)_T_$(2)_H_$(3)) \
4949
| $$(TLIB$(1)_T_$(2)_H_$(3))/
5050
@$$(call E, compile_and_link: $$@)
51+
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(STDLIB_GLOB_$(2)), `basename $$@`)
5152
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) -o $$@ $$< && touch $$@
53+
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(STDLIB_GLOB_$(2)), `basename $$@`)
5254

5355
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2)): \
5456
$$(EXTRALIB_CRATE) $$(EXTRALIB_INPUTS) \
5557
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)) \
5658
$$(TSREQ$(1)_T_$(2)_H_$(3)) \
5759
| $$(TLIB$(1)_T_$(2)_H_$(3))/
5860
@$$(call E, compile_and_link: $$@)
61+
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(EXTRALIB_GLOB_$(2)), `basename $$@`)
5962
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) -o $$@ $$< && touch $$@
63+
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(EXTRALIB_GLOB_$(2)), `basename $$@`)
6064

6165
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBSYNTAX_$(3)): \
6266
$$(LIBSYNTAX_CRATE) $$(LIBSYNTAX_INPUTS) \
@@ -65,7 +69,9 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBSYNTAX_$(3)): \
6569
$$(TEXTRALIB_DEFAULT$(1)_T_$(2)_H_$(3)) \
6670
| $$(TLIB$(1)_T_$(2)_H_$(3))/
6771
@$$(call E, compile_and_link: $$@)
72+
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(LIBSYNTAX_GLOB_$(2)), `basename $$@`)
6873
$$(STAGE$(1)_T_$(2)_H_$(3)) $(BORROWCK) -o $$@ $$< && touch $$@
74+
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(LIBSYNTAX_GLOB_$(2)), `basename $$@`)
6975

7076
# Only build the compiler for host triples
7177
ifneq ($$(findstring $(2),$$(CFG_HOST_TRIPLES)),)
@@ -83,7 +89,9 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(3)): \
8389
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_RUSTLLVM_$(3)) \
8490
| $$(TLIB$(1)_T_$(2)_H_$(3))/
8591
@$$(call E, compile_and_link: $$@)
92+
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(LIBRUSTC_GLOB_$(2)), `basename $$@`)
8693
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@
94+
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(LIBRUSTC_GLOB_$(2)), `basename $$@`)
8795

8896
$$(TBIN$(1)_T_$(2)_H_$(3))/rustc$$(X_$(3)): \
8997
$$(DRIVER_CRATE) \

0 commit comments

Comments
 (0)