Skip to content

Commit 2f063cd

Browse files
committed
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 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.
1 parent dc6121c commit 2f063cd

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/bootstrap/bootstrap.py

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

392392
if self.rustc().startswith(self.bin_root()) and \
393393
(not os.path.exists(self.rustc()) or
394-
self.program_out_of_date(self.rustc_stamp())):
394+
self.program_out_of_date(self.rustc_stamp(), self.date)):
395395
if os.path.exists(self.bin_root()):
396396
shutil.rmtree(self.bin_root())
397397
tarball_suffix = '.tar.xz' if support_xz() else '.tar.gz'
@@ -427,7 +427,7 @@ def download_stage0(self):
427427
self.fix_bin_or_dylib("{}/bin/rustfmt".format(self.bin_root()))
428428
self.fix_bin_or_dylib("{}/bin/cargo-fmt".format(self.bin_root()))
429429
with output(self.rustfmt_stamp()) as rustfmt_stamp:
430-
rustfmt_stamp.write(self.date + self.rustfmt_channel)
430+
rustfmt_stamp.write(self.rustfmt_channel)
431431

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

459459
def downloading_llvm(self):
460460
opt = self.get_toml('download-ci-llvm', 'llvm')
@@ -616,12 +616,12 @@ def llvm_stamp(self):
616616
return os.path.join(self.llvm_root(), '.llvm-stamp')
617617

618618

619-
def program_out_of_date(self, stamp_path, extra=""):
619+
def program_out_of_date(self, stamp_path, key):
620620
"""Check if the given program stamp is out of date"""
621621
if not os.path.exists(stamp_path) or self.clean:
622622
return True
623623
with open(stamp_path, 'r') as stamp:
624-
return (self.date + extra) != stamp.read()
624+
return key != stamp.read()
625625

626626
def bin_root(self):
627627
"""Return the binary root directory

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)