Skip to content

Commit 9a9033b

Browse files
committed
Delete json error metadata for a crate if it is out-of-date.
I could not figure out a good way to encode this solely in makefile rules. Even the approach here is pretty ad-hoc; it is heavily relying on the fact that all rustc crates (and thus all the json files that compiling such crates would generate on the side) have to wait for `libsyntax` to be built before they can be compiled, and thus it should be sound to make this check a prereq for the `stamp.syntax`. (At least, that is what I hope.) Fix rust-lang#25364
1 parent fa43387 commit 9a9033b

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

mk/target.mk

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,20 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/%: $$(RT_OUTPUT_DIR_$(2))/% \
151151
$$(Q)cp $$< $$@
152152
endef
153153

154+
ERROR_METADATA_DIR:="tmp/extended-errors"
155+
156+
define TARGET_HOST_RUSTC_CRATE
157+
# This is solely adding a dependency to ensure that we do the
158+
# appropriate check for each rustc crate that its associated error
159+
# diagnostics data has not become stale.
160+
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.syntax: $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.meta.$(4).check-ext-errors
161+
162+
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.meta.$(4).check-ext-errors: $$(RSINPUTS_$(4))
163+
$(CFG_SRC_DIR)src/etc/check-error-metadata.py $(ERROR_METADATA_DIR)/lib$(4).json $$(RSINPUTS_$(4))
164+
touch $$@
165+
endef
166+
167+
154168
$(foreach source,$(CFG_HOST), \
155169
$(foreach target,$(CFG_TARGET), \
156170
$(eval $(call TARGET_HOST_RULES,0,$(target),$(source))) \
@@ -167,6 +181,14 @@ $(foreach crate,$(CRATES), \
167181
$(eval $(call RUST_TARGET_STAGE_N,2,$(target),$(source),$(crate))) \
168182
$(eval $(call RUST_TARGET_STAGE_N,3,$(target),$(source),$(crate))))))
169183

184+
$(foreach crate,$(RUSTC_CRATES), \
185+
$(foreach source,$(CFG_HOST), \
186+
$(foreach target,$(CFG_TARGET), \
187+
$(eval $(call TARGET_HOST_RUSTC_CRATE,0,$(target),$(source),$(crate))) \
188+
$(eval $(call TARGET_HOST_RUSTC_CRATE,1,$(target),$(source),$(crate))) \
189+
$(eval $(call TARGET_HOST_RUSTC_CRATE,2,$(target),$(source),$(crate))) \
190+
$(eval $(call TARGET_HOST_RUSTC_CRATE,3,$(target),$(source),$(crate))))))
191+
170192
$(foreach host,$(CFG_HOST), \
171193
$(foreach target,$(CFG_TARGET), \
172194
$(foreach stage,$(STAGES), \

src/etc/check-error-metadata.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2015 The Rust Project Developers. See the COPYRIGHT
4+
# file at the top-level directory of this distribution and at
5+
# http://rust-lang.org/COPYRIGHT.
6+
#
7+
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8+
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9+
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10+
# option. This file may not be copied, modified, or distributed
11+
# except according to those terms.
12+
13+
# This script takes n+1 arguments. The first argument is a path to the
14+
# serialized error metadata file (usually a json file, though that
15+
# does not actually matter here). The rest of the arguments are the
16+
# paths to source files that we generate the error metadata file.
17+
#
18+
# If any of the source files are newer than the error metadata file,
19+
# then we *delete* the error metadata file. The driving assumption is
20+
# that it will be regenerated during the subsequent make-driven build.
21+
#
22+
# It is not an error if any of the files do not exist; they are simply
23+
# left out of the comparison in that case.
24+
25+
import os
26+
import sys
27+
28+
if __name__ == '__main__':
29+
metadata = sys.argv[1]
30+
# print "Running %s on metadata %s" % (sys.argv[0], metadata)
31+
if not os.path.exists(metadata):
32+
# print "Skipping metadata %s; does not exist" % metadata
33+
sys.exit(0)
34+
metadata_mtime = os.path.getmtime(metadata);
35+
source_files = sys.argv[2:]
36+
for f in source_files:
37+
if not os.path.exists(f):
38+
# print "Skipping comparison with %s since latter does not exist" % f
39+
continue
40+
f_mtime = os.path.getmtime(f);
41+
# print("Comparing %s against %s" % (f, metadata))
42+
# print("time (%d) against time (%d)" % (f_mtime, metadata_mtime))
43+
if f_mtime > metadata_mtime:
44+
print "Removing %s since %s is newer" % (metadata, f)
45+
os.remove(metadata)
46+
sys.exit(0)

0 commit comments

Comments
 (0)