Skip to content

Commit

Permalink
Fix #3225: Check for old Rust libraries when building and installing.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pnkfelix committed Jul 7, 2013
1 parent 63f7857 commit 033ac54
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 57 deletions.
27 changes: 27 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,33 @@ LIBRUST_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rust)

endef

# $(1) is the path for directory to match against
# $(2) is the glob to use in the match
# $(3) is filename (usually the target being created) to filter out from match
# (i.e. filename is not out-of-date artifact from prior Rust version/build)
# The glob denoted by $(2) often is constructed with a space character prefix,
# which is why we cannot just do `ls` on $(1)/$(2).
define CHECK_FOR_OLD_GLOB_MATCHES_EXCEPT
$(Q)( cd $(1) && ( ls $(2) 2>/dev/null || true ) | grep -v $(3) > /dev/null && echo "Warning: there are previous" '$(2)' "libraries:" || true )
$(Q)( cd $(1) && ( ls $(2) 2>/dev/null || true ) | grep -v $(3) || true )
endef

# Same interface as above, but deletes rather than just listing the files.
define REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT
$(Q)( cd $(1) && ( ls $(2) 2>/dev/null || true ) | grep -v $(3) > /dev/null && echo "Warning: removing previous" '$(2)' "libraries:" || true )
$(Q)( cd $(1) && ( ls $(2) 2>/dev/null || true ) | grep -v $(3) | xargs rm -v )
endef

ifdef VERBOSE
define LIST_ALL_OLD_GLOB_MATCHES_EXCEPT
@echo "Info: now are following matches for" '$(2)' "libraries:"
@( cd $(1) && ( ls $(2) 2>/dev/null || true ) | grep -v $(3) || true )
endef
else
define LIST_ALL_OLD_GLOB_MATCHES_EXCEPT
endef
endif

$(foreach target,$(CFG_TARGET_TRIPLES),\
$(eval $(call DEF_LIBS,$(target))))

Expand Down
8 changes: 8 additions & 0 deletions mk/host.mk
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ $$(HLIB$(2)_H_$(4))/$(CFG_LIBRUSTC_$(4)): \
| $$(HLIB$(2)_H_$(4))/

@$$(call E, cp: $$@)
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(LIBRUSTC_GLOB_$(4)), `basename $$@`)
$$(Q)cp $$< $$@
$$(Q)cp -R $$(TLIB$(1)_T_$(4)_H_$(3))/$(LIBRUSTC_GLOB_$(4)) \
$(wildcard $$(TLIB$(1)_T_$(4)_H_$(3))/$(LIBRUSTC_DSYM_GLOB_$(4))) \
$$(HLIB$(2)_H_$(4))
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(LIBRUSTC_GLOB_$(4)), `basename $$@`)

$$(HLIB$(2)_H_$(4))/$(CFG_LIBSYNTAX_$(4)): \
$$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_LIBSYNTAX_$(4)) \
Expand All @@ -58,10 +60,12 @@ $$(HLIB$(2)_H_$(4))/$(CFG_LIBSYNTAX_$(4)): \
$$(HEXTRALIB_DEFAULT$(2)_H_$(4)) \
| $$(HLIB$(2)_H_$(4))/
@$$(call E, cp: $$@)
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(LIBSYNTAX_GLOB_$(4)), `basename $$@`)
$$(Q)cp $$< $$@
$$(Q)cp -R $$(TLIB$(1)_T_$(4)_H_$(3))/$(LIBSYNTAX_GLOB_$(4)) \
$$(wildcard $$(TLIB$(1)_T_$(4)_H_$(3))/$(LIBSYNTAX_DSYM_GLOB_$(4))) \
$$(HLIB$(2)_H_$(4))
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(LIBSYNTAX_GLOB_$(4)), `basename $$@`)

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

$$(HLIB$(2)_H_$(4))/$(CFG_EXTRALIB_$(4)): \
$$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_EXTRALIB_$(4)) \
$$(HLIB$(2)_H_$(4))/$(CFG_STDLIB_$(4)) \
$$(HLIB$(2)_H_$(4))/$(CFG_RUNTIME_$(4)) \
| $$(HLIB$(2)_H_$(4))/
@$$(call E, cp: $$@)
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(EXTRALIB_GLOB_$(4)), `basename $$@`)
$$(Q)cp $$< $$@
$$(Q)cp -R $$(TLIB$(1)_T_$(4)_H_$(3))/$(EXTRALIB_GLOB_$(4)) \
$$(wildcard $$(TLIB$(1)_T_$(4)_H_$(3))/$(EXTRALIB_DSYM_GLOB_$(4))) \
$$(HLIB$(2)_H_$(4))
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(EXTRALIB_GLOB_$(4)), `basename $$@`)

$$(HLIB$(2)_H_$(4))/libstd.rlib: \
$$(TLIB$(1)_T_$(4)_H_$(3))/libstd.rlib \
Expand Down
12 changes: 10 additions & 2 deletions mk/install.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@
# destination directory as arg 2, and filename/libname-glob as arg 3
ifdef VERBOSE
INSTALL = install -m755 $(1)/$(3) $(2)/$(3)
INSTALL_LIB = install -m644 `ls -drt1 $(1)/$(3) | tail -1` $(2)/
DO_INSTALL_LIB = install -m644 `ls -drt1 $(1)/$(3) | tail -1` $(2)/
else
INSTALL = $(Q)$(call E, install: $(2)/$(3)) && install -m755 $(1)/$(3) $(2)/$(3)
INSTALL_LIB = $(Q)$(call E, install_lib: $(2)/$(3)) && \
DO_INSTALL_LIB = $(Q)$(call E, install_lib: $(2)/$(3)) && \
install -m644 `ls -drt1 $(1)/$(3) | tail -1` $(2)/
endif

# $(1) is the source dirctory
# $(2) is the destination directory
# $(3) is the filename/libname-glob
define INSTALL_LIB
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
$(call DO_INSTALL_LIB,$(1),$(2),$(3))
endef

# The stage we install from
ISTAGE = 2

Expand Down
55 changes: 42 additions & 13 deletions mk/stage0.mk
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# Extract the snapshot host compiler

$(HBIN0_H_$(CFG_BUILD_TRIPLE))/:
mkdir -p $@

$(HLIB0_H_$(CFG_BUILD_TRIPLE))/:
mkdir -p $@

$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE)): \
$(S)src/snapshots.txt \
$(S)src/etc/get-snapshot.py $(MKFILE_DEPS)
$(S)src/etc/get-snapshot.py $(MKFILE_DEPS) \
| $(HBIN0_H_$(CFG_BUILD_TRIPLE))/

@$(call E, fetch: $@)
# Note: the variable "SNAPSHOT_FILE" is generally not set, and so
# we generally only pass one argument to this script.
Expand All @@ -22,23 +28,28 @@ endif
# Host libs will be extracted by the above rule

$(HLIB0_H_$(CFG_BUILD_TRIPLE))/$(CFG_RUNTIME_$(CFG_BUILD_TRIPLE)): \
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE))
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE)) \
| $(HLIB0_H_$(CFG_BUILD_TRIPLE))/
$(Q)touch $@

$(HLIB0_H_$(CFG_BUILD_TRIPLE))/$(CFG_STDLIB_$(CFG_BUILD_TRIPLE)): \
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE))
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE)) \
| $(HLIB0_H_$(CFG_BUILD_TRIPLE))/
$(Q)touch $@

$(HLIB0_H_$(CFG_BUILD_TRIPLE))/$(CFG_EXTRALIB_$(CFG_BUILD_TRIPLE)): \
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE))
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE)) \
| $(HLIB0_H_$(CFG_BUILD_TRIPLE))/
$(Q)touch $@

$(HLIB0_H_$(CFG_BUILD_TRIPLE))/$(CFG_LIBRUSTC_$(CFG_BUILD_TRIPLE)): \
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE))
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE)) \
| $(HLIB0_H_$(CFG_BUILD_TRIPLE))/
$(Q)touch $@

$(HLIB0_H_$(CFG_BUILD_TRIPLE))/$(CFG_RUSTLLVM_$(CFG_BUILD_TRIPLE)): \
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE))
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE)) \
| $(HLIB0_H_$(CFG_BUILD_TRIPLE))/
$(Q)touch $@

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

$$(HBIN0_H_$(1))/rustc$$(X_$(1)): \
$$(TBIN$(2)_T_$(1)_H_$(3))/rustc$$(X_$(1))
$(HBIN0_H_$(1))/:
mkdir -p $@

$(HLIB0_H_$(1))/:
mkdir -p $@

$$(HBIN0_H_$(1))/rustc$$(X_$(1)): \
$$(TBIN$(2)_T_$(1)_H_$(3))/rustc$$(X_$(1)) \
| $(HBIN0_H_$(1))/
@$$(call E, cp: $$@)
$$(Q)cp $$< $$@

$$(HLIB0_H_$(1))/$(CFG_RUNTIME_$(1)): \
$$(TLIB$(2)_T_$(1)_H_$(3))/$(CFG_RUNTIME_$(1))
$$(TLIB$(2)_T_$(1)_H_$(3))/$(CFG_RUNTIME_$(1)) \
| $(HLIB0_H_$(1))/
@$$(call E, cp: $$@)
$$(Q)cp $$< $$@

$$(HLIB0_H_$(1))/$(CFG_STDLIB_$(1)): \
$$(TLIB$(2)_T_$(1)_H_$(3))/$(CFG_STDLIB_$(1))
$$(TLIB$(2)_T_$(1)_H_$(3))/$(CFG_STDLIB_$(1)) \
| $(HLIB0_H_$(1))/
@$$(call E, cp: $$@)
$$(call CHECK_FOR_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(EXTRALIB_GLOB_$(4)), `basename $$@`)
$$(Q)cp $$(TLIB$(2)_T_$(1)_H_$(3))/$(STDLIB_GLOB_$(1)) $$@
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(EXTRALIB_GLOB_$(4)), `basename $$@`)

$$(HLIB0_H_$(1))/$(CFG_EXTRALIB_$(1)): \
$$(TLIB$(2)_T_$(1)_H_$(3))/$(CFG_EXTRALIB_$(1))
$$(TLIB$(2)_T_$(1)_H_$(3))/$(CFG_EXTRALIB_$(1)) \
| $(HLIB0_H_$(1))/
@$$(call E, cp: $$@)
$$(call CHECK_FOR_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(EXTRALIB_GLOB_$(4)), `basename $$@`)
$$(Q)cp $$(TLIB$(2)_T_$(1)_H_$(3))/$(EXTRALIB_GLOB_$(1)) $$@
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(EXTRALIB_GLOB_$(4)), `basename $$@`)

$$(HLIB0_H_$(1))/$(CFG_LIBRUSTC_$(1)): \
$$(TLIB$(2)_T_$(1)_H_$(3))/$(CFG_LIBRUSTC_$(1))
$$(TLIB$(2)_T_$(1)_H_$(3))/$(CFG_LIBRUSTC_$(1)) \
| $(HLIB0_H_$(1))/
@$$(call E, cp: $$@)
$$(call CHECK_FOR_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(LIBRUSTC_GLOB_$(4)), `basename $$@`)
$$(Q)cp $$(TLIB$(2)_T_$(1)_H_$(3))/$(LIBRUSTC_GLOB_$(1)) $$@
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(LIBRUSTC_GLOB_$(4)), `basename $$@`)

$$(HLIB0_H_$(1))/$(CFG_RUSTLLVM_$(1)): \
$$(TLIB$(2)_T_$(1)_H_$(3))/$(CFG_RUSTLLVM_$(1))
$$(TLIB$(2)_T_$(1)_H_$(3))/$(CFG_RUSTLLVM_$(1)) \
| $(HLIB0_H_$(1))/
@$$(call E, cp: $$@)
$$(Q)cp $$< $$@

Expand Down
8 changes: 8 additions & 0 deletions mk/target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,19 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)): \
$$(TSREQ$(1)_T_$(2)_H_$(3)) \
| $$(TLIB$(1)_T_$(2)_H_$(3))/
@$$(call E, compile_and_link: $$@)
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(STDLIB_GLOB_$(2)), `basename $$@`)
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) -o $$@ $$< && touch $$@
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(STDLIB_GLOB_$(2)), `basename $$@`)

$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2)): \
$$(EXTRALIB_CRATE) $$(EXTRALIB_INPUTS) \
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)) \
$$(TSREQ$(1)_T_$(2)_H_$(3)) \
| $$(TLIB$(1)_T_$(2)_H_$(3))/
@$$(call E, compile_and_link: $$@)
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(EXTRALIB_GLOB_$(2)), `basename $$@`)
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) -o $$@ $$< && touch $$@
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(EXTRALIB_GLOB_$(2)), `basename $$@`)

$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBSYNTAX_$(3)): \
$$(LIBSYNTAX_CRATE) $$(LIBSYNTAX_INPUTS) \
Expand All @@ -65,7 +69,9 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBSYNTAX_$(3)): \
$$(TEXTRALIB_DEFAULT$(1)_T_$(2)_H_$(3)) \
| $$(TLIB$(1)_T_$(2)_H_$(3))/
@$$(call E, compile_and_link: $$@)
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(LIBSYNTAX_GLOB_$(2)), `basename $$@`)
$$(STAGE$(1)_T_$(2)_H_$(3)) $(BORROWCK) -o $$@ $$< && touch $$@
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT, `dirname $$@`, $(LIBSYNTAX_GLOB_$(2)), `basename $$@`)

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

$$(TBIN$(1)_T_$(2)_H_$(3))/rustc$$(X_$(3)): \
$$(DRIVER_CRATE) \
Expand Down
Loading

0 comments on commit 033ac54

Please sign in to comment.