Skip to content

Commit

Permalink
Auto merge of #48793 - cuviper:beta-1.25-backports, r=kennytm
Browse files Browse the repository at this point in the history
[beta] backport #48181 and #48362

None
  • Loading branch information
bors committed Mar 9, 2018
2 parents e93f6e0 + 62e9f2b commit b89a2a4
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,11 @@ impl<'a> Builder<'a> {

fn run(self, builder: &Builder) -> Interned<PathBuf> {
let compiler = self.compiler;
let lib = if compiler.stage >= 1 && builder.build.config.libdir.is_some() {
builder.build.config.libdir.clone().unwrap()
let config = &builder.build.config;
let lib = if compiler.stage >= 1 && config.libdir_relative().is_some() {
builder.build.config.libdir_relative().unwrap()
} else {
PathBuf::from("lib")
Path::new("lib")
};
let sysroot = builder.sysroot(self.compiler).join(lib)
.join("rustlib").join(self.target).join("lib");
Expand Down
3 changes: 1 addition & 2 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,7 @@ fn rustc_cargo_env(build: &Build, cargo: &mut Command) {
.env("CFG_VERSION", build.rust_version())
.env("CFG_PREFIX", build.config.prefix.clone().unwrap_or_default());

let libdir_relative =
build.config.libdir.clone().unwrap_or(PathBuf::from("lib"));
let libdir_relative = build.config.libdir_relative().unwrap_or(Path::new("lib"));
cargo.env("CFG_LIBDIR_RELATIVE", libdir_relative);

// If we're not building a compiler with debugging information then remove
Expand Down
13 changes: 12 additions & 1 deletion src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::collections::{HashMap, HashSet};
use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process;
use std::cmp;

Expand Down Expand Up @@ -564,6 +564,17 @@ impl Config {
config
}

/// Try to find the relative path of `libdir`.
pub fn libdir_relative(&self) -> Option<&Path> {
let libdir = self.libdir.as_ref()?;
if libdir.is_relative() {
Some(libdir)
} else {
// Try to make it relative to the prefix.
libdir.strip_prefix(self.prefix.as_ref()?).ok()
}
}

pub fn verbose(&self) -> bool {
self.verbose > 0
}
Expand Down
9 changes: 9 additions & 0 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,15 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
disambiguator,
);

if sess.opts.incremental.is_some() {
time(time_passes, "garbage collect incremental cache directory", || {
if let Err(e) = rustc_incremental::garbage_collect_session_directories(sess) {
warn!("Error while trying to garbage collect incremental \
compilation cache directory: {}", e);
}
});
}

// If necessary, compute the dependency graph (in the background).
let future_dep_graph = if sess.opts.build_dep_graph() {
Some(rustc_incremental::load_dep_graph(sess, time_passes))
Expand Down
1 change: 1 addition & 0 deletions src/librustc_incremental/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ pub use persist::in_incr_comp_dir;
pub use persist::prepare_session_directory;
pub use persist::finalize_session_directory;
pub use persist::delete_workproduct_files;
pub use persist::garbage_collect_session_directories;
16 changes: 15 additions & 1 deletion src/librustc_incremental/persist/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ fn timestamp_to_string(timestamp: SystemTime) -> String {
}

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

if micros_since_unix_epoch.is_err() {
return Err(())
Expand Down Expand Up @@ -733,6 +733,20 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
})
.collect();

// Delete all session directories that don't have a lock file.
for directory_name in session_directories {
if !lock_file_to_session_dir.values().any(|dir| *dir == directory_name) {
let path = crate_directory.join(directory_name);
if let Err(err) = safe_remove_dir_all(&path) {
sess.warn(&format!("Failed to garbage collect invalid incremental \
compilation session directory `{}`: {}",
path.display(),
err));
}
}
}

// Now garbage collect the valid session directories.
let mut deletion_candidates = vec![];
let mut definitely_delete = vec![];

Expand Down
3 changes: 2 additions & 1 deletion src/librustc_incremental/persist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ mod save;
mod work_product;
mod file_format;

pub use self::fs::prepare_session_directory;
pub use self::fs::finalize_session_directory;
pub use self::fs::garbage_collect_session_directories;
pub use self::fs::in_incr_comp_dir;
pub use self::fs::prepare_session_directory;
pub use self::load::dep_graph_tcx_init;
pub use self::load::load_dep_graph;
pub use self::load::load_query_result_cache;
Expand Down

0 comments on commit b89a2a4

Please sign in to comment.