Only depend on CFG_VERSION in rustc_interface
this avoids having to rebuild the whole compiler on each commit when `omit-git-hash = false`.
This commit is contained in:
parent
0dddad0dc5
commit
d5f2b8e5c6
24 changed files with 97 additions and 71 deletions
|
@ -14,6 +14,7 @@ use rustc_data_structures::memmap::Mmap;
|
|||
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
|
||||
use rustc_serialize::Encoder;
|
||||
use rustc_session::Session;
|
||||
use std::borrow::Cow;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::io::{self, Read};
|
||||
|
@ -25,17 +26,12 @@ const FILE_MAGIC: &[u8] = b"RSIC";
|
|||
/// Change this if the header format changes.
|
||||
const HEADER_FORMAT_VERSION: u16 = 0;
|
||||
|
||||
/// A version string that hopefully is always different for compiler versions
|
||||
/// with different encodings of incremental compilation artifacts. Contains
|
||||
/// the Git commit hash.
|
||||
const RUSTC_VERSION: Option<&str> = option_env!("CFG_VERSION");
|
||||
|
||||
pub(crate) fn write_file_header(stream: &mut FileEncoder, nightly_build: bool) {
|
||||
pub(crate) fn write_file_header(stream: &mut FileEncoder, sess: &Session) {
|
||||
stream.emit_raw_bytes(FILE_MAGIC);
|
||||
stream
|
||||
.emit_raw_bytes(&[(HEADER_FORMAT_VERSION >> 0) as u8, (HEADER_FORMAT_VERSION >> 8) as u8]);
|
||||
|
||||
let rustc_version = rustc_version(nightly_build);
|
||||
let rustc_version = rustc_version(sess.is_nightly_build(), sess.cfg_version);
|
||||
assert_eq!(rustc_version.len(), (rustc_version.len() as u8) as usize);
|
||||
stream.emit_raw_bytes(&[rustc_version.len() as u8]);
|
||||
stream.emit_raw_bytes(rustc_version.as_bytes());
|
||||
|
@ -73,7 +69,7 @@ where
|
|||
}
|
||||
};
|
||||
|
||||
write_file_header(&mut encoder, sess.is_nightly_build());
|
||||
write_file_header(&mut encoder, sess);
|
||||
|
||||
match encode(encoder) {
|
||||
Ok(position) => {
|
||||
|
@ -100,9 +96,10 @@ where
|
|||
/// - Returns `Err(..)` if some kind of IO error occurred while reading the
|
||||
/// file.
|
||||
pub fn read_file(
|
||||
report_incremental_info: bool,
|
||||
path: &Path,
|
||||
nightly_build: bool,
|
||||
report_incremental_info: bool,
|
||||
is_nightly_build: bool,
|
||||
cfg_version: &'static str,
|
||||
) -> io::Result<Option<(Mmap, usize)>> {
|
||||
let file = match fs::File::open(path) {
|
||||
Ok(file) => file,
|
||||
|
@ -152,7 +149,7 @@ pub fn read_file(
|
|||
let mut buffer = vec![0; rustc_version_str_len];
|
||||
file.read_exact(&mut buffer)?;
|
||||
|
||||
if buffer != rustc_version(nightly_build).as_bytes() {
|
||||
if buffer != rustc_version(is_nightly_build, cfg_version).as_bytes() {
|
||||
report_format_mismatch(report_incremental_info, path, "Different compiler version");
|
||||
return Ok(None);
|
||||
}
|
||||
|
@ -174,17 +171,15 @@ fn report_format_mismatch(report_incremental_info: bool, file: &Path, message: &
|
|||
}
|
||||
}
|
||||
|
||||
fn rustc_version(nightly_build: bool) -> String {
|
||||
/// A version string that hopefully is always different for compiler versions
|
||||
/// with different encodings of incremental compilation artifacts. Contains
|
||||
/// the Git commit hash.
|
||||
fn rustc_version(nightly_build: bool, cfg_version: &'static str) -> Cow<'static, str> {
|
||||
if nightly_build {
|
||||
if let Some(val) = env::var_os("RUSTC_FORCE_RUSTC_VERSION") {
|
||||
return val.to_string_lossy().into_owned();
|
||||
if let Ok(val) = env::var("RUSTC_FORCE_RUSTC_VERSION") {
|
||||
return val.into();
|
||||
}
|
||||
}
|
||||
|
||||
RUSTC_VERSION
|
||||
.expect(
|
||||
"Cannot use rustc without explicit version for \
|
||||
incremental compilation",
|
||||
)
|
||||
.to_string()
|
||||
cfg_version.into()
|
||||
}
|
||||
|
|
|
@ -73,12 +73,22 @@ impl<T: Default> LoadResult<T> {
|
|||
}
|
||||
}
|
||||
|
||||
fn load_data(
|
||||
report_incremental_info: bool,
|
||||
fn load_data(path: &Path, sess: &Session) -> LoadResult<(Mmap, usize)> {
|
||||
load_data_no_sess(
|
||||
path,
|
||||
sess.opts.unstable_opts.incremental_info,
|
||||
sess.is_nightly_build(),
|
||||
sess.cfg_version,
|
||||
)
|
||||
}
|
||||
|
||||
fn load_data_no_sess(
|
||||
path: &Path,
|
||||
nightly_build: bool,
|
||||
report_incremental_info: bool,
|
||||
is_nightly_build: bool,
|
||||
cfg_version: &'static str,
|
||||
) -> LoadResult<(Mmap, usize)> {
|
||||
match file_format::read_file(report_incremental_info, path, nightly_build) {
|
||||
match file_format::read_file(path, report_incremental_info, is_nightly_build, cfg_version) {
|
||||
Ok(Some(data_and_pos)) => LoadResult::Ok { data: data_and_pos },
|
||||
Ok(None) => {
|
||||
// The file either didn't exist or was produced by an incompatible
|
||||
|
@ -138,14 +148,13 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
|
|||
let expected_hash = sess.opts.dep_tracking_hash(false);
|
||||
|
||||
let mut prev_work_products = FxHashMap::default();
|
||||
let nightly_build = sess.is_nightly_build();
|
||||
|
||||
// If we are only building with -Zquery-dep-graph but without an actual
|
||||
// incr. comp. session directory, we skip this. Otherwise we'd fail
|
||||
// when trying to load work products.
|
||||
if sess.incr_comp_session_dir_opt().is_some() {
|
||||
let work_products_path = work_products_path(sess);
|
||||
let load_result = load_data(report_incremental_info, &work_products_path, nightly_build);
|
||||
let load_result = load_data(&work_products_path, sess);
|
||||
|
||||
if let LoadResult::Ok { data: (work_products_data, start_pos) } = load_result {
|
||||
// Decode the list of work_products
|
||||
|
@ -173,10 +182,13 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
|
|||
}
|
||||
}
|
||||
|
||||
let is_nightly_build = sess.is_nightly_build();
|
||||
let cfg_version = sess.cfg_version;
|
||||
|
||||
MaybeAsync::Async(std::thread::spawn(move || {
|
||||
let _prof_timer = prof.generic_activity("incr_comp_load_dep_graph");
|
||||
|
||||
match load_data(report_incremental_info, &path, nightly_build) {
|
||||
match load_data_no_sess(&path, report_incremental_info, is_nightly_build, cfg_version) {
|
||||
LoadResult::DataOutOfDate => LoadResult::DataOutOfDate,
|
||||
LoadResult::LoadDepGraph(path, err) => LoadResult::LoadDepGraph(path, err),
|
||||
LoadResult::DecodeIncrCache(err) => LoadResult::DecodeIncrCache(err),
|
||||
|
@ -218,11 +230,7 @@ pub fn load_query_result_cache(sess: &Session) -> Option<OnDiskCache<'_>> {
|
|||
|
||||
let _prof_timer = sess.prof.generic_activity("incr_comp_load_query_result_cache");
|
||||
|
||||
match load_data(
|
||||
sess.opts.unstable_opts.incremental_info,
|
||||
&query_cache_path(sess),
|
||||
sess.is_nightly_build(),
|
||||
) {
|
||||
match load_data(&query_cache_path(sess), sess) {
|
||||
LoadResult::Ok { data: (bytes, start_pos) } => {
|
||||
Some(OnDiskCache::new(sess, bytes, start_pos))
|
||||
}
|
||||
|
|
|
@ -164,7 +164,7 @@ pub fn build_dep_graph(
|
|||
}
|
||||
};
|
||||
|
||||
file_format::write_file_header(&mut encoder, sess.is_nightly_build());
|
||||
file_format::write_file_header(&mut encoder, sess);
|
||||
|
||||
// First encode the commandline arguments hash
|
||||
sess.opts.dep_tracking_hash(false).encode(&mut encoder);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue