Skip to content

Commit 16262bb

Browse files
committed
Auto merge of #48793 - cuviper:beta-1.25-backports, r=kennytm
[beta] backport #48181 and #48362 None
2 parents e93f6e0 + 62e9f2b commit 16262bb

File tree

7 files changed

+44
-8
lines changed

7 files changed

+44
-8
lines changed

src/bootstrap/builder.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,11 @@ impl<'a> Builder<'a> {
444444

445445
fn run(self, builder: &Builder) -> Interned<PathBuf> {
446446
let compiler = self.compiler;
447-
let lib = if compiler.stage >= 1 && builder.build.config.libdir.is_some() {
448-
builder.build.config.libdir.clone().unwrap()
447+
let config = &builder.build.config;
448+
let lib = if compiler.stage >= 1 && config.libdir_relative().is_some() {
449+
builder.build.config.libdir_relative().unwrap()
449450
} else {
450-
PathBuf::from("lib")
451+
Path::new("lib")
451452
};
452453
let sysroot = builder.sysroot(self.compiler).join(lib)
453454
.join("rustlib").join(self.target).join("lib");

src/bootstrap/compile.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,7 @@ fn rustc_cargo_env(build: &Build, cargo: &mut Command) {
516516
.env("CFG_VERSION", build.rust_version())
517517
.env("CFG_PREFIX", build.config.prefix.clone().unwrap_or_default());
518518

519-
let libdir_relative =
520-
build.config.libdir.clone().unwrap_or(PathBuf::from("lib"));
519+
let libdir_relative = build.config.libdir_relative().unwrap_or(Path::new("lib"));
521520
cargo.env("CFG_LIBDIR_RELATIVE", libdir_relative);
522521

523522
// If we're not building a compiler with debugging information then remove

src/bootstrap/config.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::collections::{HashMap, HashSet};
1717
use std::env;
1818
use std::fs::File;
1919
use std::io::prelude::*;
20-
use std::path::PathBuf;
20+
use std::path::{Path, PathBuf};
2121
use std::process;
2222
use std::cmp;
2323

@@ -564,6 +564,17 @@ impl Config {
564564
config
565565
}
566566

567+
/// Try to find the relative path of `libdir`.
568+
pub fn libdir_relative(&self) -> Option<&Path> {
569+
let libdir = self.libdir.as_ref()?;
570+
if libdir.is_relative() {
571+
Some(libdir)
572+
} else {
573+
// Try to make it relative to the prefix.
574+
libdir.strip_prefix(self.prefix.as_ref()?).ok()
575+
}
576+
}
577+
567578
pub fn verbose(&self) -> bool {
568579
self.verbose > 0
569580
}

src/librustc_driver/driver.rs

+9
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,15 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
660660
disambiguator,
661661
);
662662

663+
if sess.opts.incremental.is_some() {
664+
time(time_passes, "garbage collect incremental cache directory", || {
665+
if let Err(e) = rustc_incremental::garbage_collect_session_directories(sess) {
666+
warn!("Error while trying to garbage collect incremental \
667+
compilation cache directory: {}", e);
668+
}
669+
});
670+
}
671+
663672
// If necessary, compute the dependency graph (in the background).
664673
let future_dep_graph = if sess.opts.build_dep_graph() {
665674
Some(rustc_incremental::load_dep_graph(sess, time_passes))

src/librustc_incremental/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ pub use persist::in_incr_comp_dir;
4646
pub use persist::prepare_session_directory;
4747
pub use persist::finalize_session_directory;
4848
pub use persist::delete_workproduct_files;
49+
pub use persist::garbage_collect_session_directories;

src/librustc_incremental/persist/fs.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ fn timestamp_to_string(timestamp: SystemTime) -> String {
603603
}
604604

605605
fn string_to_timestamp(s: &str) -> Result<SystemTime, ()> {
606-
let micros_since_unix_epoch = u64::from_str_radix(s, 36);
606+
let micros_since_unix_epoch = u64::from_str_radix(s, INT_ENCODE_BASE as u32);
607607

608608
if micros_since_unix_epoch.is_err() {
609609
return Err(())
@@ -733,6 +733,20 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
733733
})
734734
.collect();
735735

736+
// Delete all session directories that don't have a lock file.
737+
for directory_name in session_directories {
738+
if !lock_file_to_session_dir.values().any(|dir| *dir == directory_name) {
739+
let path = crate_directory.join(directory_name);
740+
if let Err(err) = safe_remove_dir_all(&path) {
741+
sess.warn(&format!("Failed to garbage collect invalid incremental \
742+
compilation session directory `{}`: {}",
743+
path.display(),
744+
err));
745+
}
746+
}
747+
}
748+
749+
// Now garbage collect the valid session directories.
736750
let mut deletion_candidates = vec![];
737751
let mut definitely_delete = vec![];
738752

src/librustc_incremental/persist/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ mod save;
2020
mod work_product;
2121
mod file_format;
2222

23-
pub use self::fs::prepare_session_directory;
2423
pub use self::fs::finalize_session_directory;
24+
pub use self::fs::garbage_collect_session_directories;
2525
pub use self::fs::in_incr_comp_dir;
26+
pub use self::fs::prepare_session_directory;
2627
pub use self::load::dep_graph_tcx_init;
2728
pub use self::load::load_dep_graph;
2829
pub use self::load::load_query_result_cache;

0 commit comments

Comments
 (0)