Skip to content

Commit 9919ad6

Browse files
committed
Auto merge of #80426 - jyn514:bootstrap-caching, r=Mark-Simulacrum
Don't use `self.date` unconditionally for `program_out_of_date()` This avoids unnecessary cache invalidations for programs not affected by the stage0 version (which is everything except the stage0 compiler itself). The redundant invalidations weren't noticed until now because they only showed up on stage0 bumps, at which point people are used to rebuilding everything anyway. I noticed it in #79540 because I wasn't adding `self.date` to the stamp file (because I didn't realize it was necessary). Rather than adding self.date I thought it was better to remove it from the cache key.
2 parents 61f5a00 + 2f063cd commit 9919ad6

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

Diff for: src/bootstrap/bootstrap.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def download_stage0(self):
393393

394394
if self.rustc().startswith(self.bin_root()) and \
395395
(not os.path.exists(self.rustc()) or
396-
self.program_out_of_date(self.rustc_stamp())):
396+
self.program_out_of_date(self.rustc_stamp(), self.date)):
397397
if os.path.exists(self.bin_root()):
398398
shutil.rmtree(self.bin_root())
399399
tarball_suffix = '.tar.xz' if support_xz() else '.tar.gz'
@@ -429,7 +429,7 @@ def download_stage0(self):
429429
self.fix_bin_or_dylib("{}/bin/rustfmt".format(self.bin_root()))
430430
self.fix_bin_or_dylib("{}/bin/cargo-fmt".format(self.bin_root()))
431431
with output(self.rustfmt_stamp()) as rustfmt_stamp:
432-
rustfmt_stamp.write(self.date + self.rustfmt_channel)
432+
rustfmt_stamp.write(self.rustfmt_channel)
433433

434434
if self.downloading_llvm():
435435
# We want the most recent LLVM submodule update to avoid downloading
@@ -456,7 +456,7 @@ def download_stage0(self):
456456
for binary in ["llvm-config", "FileCheck"]:
457457
self.fix_bin_or_dylib("{}/bin/{}".format(self.llvm_root(), binary))
458458
with output(self.llvm_stamp()) as llvm_stamp:
459-
llvm_stamp.write(self.date + llvm_sha + str(llvm_assertions))
459+
llvm_stamp.write(llvm_sha + str(llvm_assertions))
460460

461461
def downloading_llvm(self):
462462
opt = self.get_toml('download-ci-llvm', 'llvm')
@@ -623,12 +623,12 @@ def llvm_stamp(self):
623623
return os.path.join(self.llvm_root(), '.llvm-stamp')
624624

625625

626-
def program_out_of_date(self, stamp_path, extra=""):
626+
def program_out_of_date(self, stamp_path, key):
627627
"""Check if the given program stamp is out of date"""
628628
if not os.path.exists(stamp_path) or self.clean:
629629
return True
630630
with open(stamp_path, 'r') as stamp:
631-
return (self.date + extra) != stamp.read()
631+
return key != stamp.read()
632632

633633
def bin_root(self):
634634
"""Return the binary root directory

Diff for: src/bootstrap/bootstrap_test.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def setUp(self):
7070
self.build.build_dir = self.container
7171
self.rustc_stamp_path = os.path.join(self.container, "stage0",
7272
".rustc-stamp")
73+
self.key = self.build.date + str(None)
7374

7475
def tearDown(self):
7576
rmtree(self.container)
@@ -78,19 +79,19 @@ def test_stamp_path_does_not_exists(self):
7879
"""Return True when the stamp file does not exists"""
7980
if os.path.exists(self.rustc_stamp_path):
8081
os.unlink(self.rustc_stamp_path)
81-
self.assertTrue(self.build.program_out_of_date(self.rustc_stamp_path))
82+
self.assertTrue(self.build.program_out_of_date(self.rustc_stamp_path, self.key))
8283

8384
def test_dates_are_different(self):
8485
"""Return True when the dates are different"""
8586
with open(self.rustc_stamp_path, "w") as rustc_stamp:
86-
rustc_stamp.write("2017-06-14")
87-
self.assertTrue(self.build.program_out_of_date(self.rustc_stamp_path))
87+
rustc_stamp.write("2017-06-14None")
88+
self.assertTrue(self.build.program_out_of_date(self.rustc_stamp_path, self.key))
8889

8990
def test_same_dates(self):
9091
"""Return False both dates match"""
9192
with open(self.rustc_stamp_path, "w") as rustc_stamp:
92-
rustc_stamp.write("2017-06-15")
93-
self.assertFalse(self.build.program_out_of_date(self.rustc_stamp_path))
93+
rustc_stamp.write("2017-06-15None")
94+
self.assertFalse(self.build.program_out_of_date(self.rustc_stamp_path, self.key))
9495

9596

9697
if __name__ == '__main__':

0 commit comments

Comments
 (0)