Skip to content

Instantly share code, notes, and snippets.

@ehuss
Created June 22, 2019 18:51
Show Gist options
  • Save ehuss/7ab5572e6b7c1e41d908021172fc815b to your computer and use it in GitHub Desktop.
Save ehuss/7ab5572e6b7c1e41d908021172fc815b to your computer and use it in GitHub Desktop.
hack for dep-info relative paths
diff --git a/src/cargo/core/compiler/fingerprint.rs b/src/cargo/core/compiler/fingerprint.rs
index 1804be9a..d039b3d1 100644
--- a/src/cargo/core/compiler/fingerprint.rs
+++ b/src/cargo/core/compiler/fingerprint.rs
@@ -210,7 +210,7 @@ use super::job::{
Freshness::{Dirty, Fresh},
Job, Work,
};
-use super::{BuildContext, Context, FileFlavor, Kind, Unit};
+use super::{BuildContext, Context, FileFlavor, Unit};
/// Determines if a `unit` is up-to-date, and if not prepares necessary work to
/// update the persisted fingerprint.
@@ -555,10 +555,13 @@ impl LocalFingerprint {
// We need to verify that no paths listed in `paths` are newer than
// the `output` path itself, or the last time the build script ran.
- LocalFingerprint::RerunIfChanged { output, paths } => Ok(find_stale_file(
- &target_root.join(output),
- paths.iter().map(|p| pkg_root.join(p)),
- )),
+ LocalFingerprint::RerunIfChanged { output, paths } => {
+ // println!("find_stale_file target_root={:?} output={:?} paths={:?}", target_root, output, paths);
+ Ok(find_stale_file(
+ &target_root.join(output),
+ paths.iter().map(|p| pkg_root.join(p)),
+ ))
+ }
// These have no dependencies on the filesystem, and their values
// are included natively in the `Fingerprint` hash so nothing
@@ -1046,6 +1049,7 @@ fn calculate_normal<'a, 'cfg>(
let target_root = target_root(cx, unit);
let local = if use_dep_info(unit) {
let dep_info = dep_info_loc(cx, unit);
+ // println!("dep_info={:?} strip {:?}", dep_info, target_root);
let dep_info = dep_info.strip_prefix(&target_root).unwrap().to_path_buf();
vec![LocalFingerprint::CheckDepInfo { dep_info }]
} else {
@@ -1205,8 +1209,9 @@ fn build_script_local_fingerprints<'a, 'cfg>(
// package. Remember that the fact that this is an `Option` is a bug, but a
// longstanding bug, in Cargo. Recent refactorings just made it painfully
// obvious.
- let script_root = cx.files().build_script_run_dir(unit);
+ // let script_root = cx.files().build_script_run_dir(unit);
let pkg_root = unit.pkg.root().to_path_buf();
+ let target_dir = cx.bcx.ws.target_dir().into_path_unlocked();
let calculate =
move |deps: &BuildDeps, pkg_fingerprint: Option<&dyn Fn() -> CargoResult<String>>| {
if deps.rerun_if_changed.is_empty() && deps.rerun_if_env_changed.is_empty() {
@@ -1233,7 +1238,7 @@ fn build_script_local_fingerprints<'a, 'cfg>(
// Ok so now we're in "new mode" where we can have files listed as
// dependencies as well as env vars listed as dependencies. Process
// them all here.
- Ok(Some(local_fingerprints_deps(deps, &script_root, &pkg_root)))
+ Ok(Some(local_fingerprints_deps(deps, &target_dir, &pkg_root)))
};
// Note that `false` == "not overridden"
@@ -1280,6 +1285,7 @@ fn local_fingerprints_deps(
.iter()
.map(|p| p.strip_prefix(pkg_root).unwrap_or(p).to_path_buf())
.collect();
+ // println!("rerun-if-changed target_root={:?} output={:?} paths={:?}", target_root, output, paths);
local.push(LocalFingerprint::RerunIfChanged { output, paths });
}
@@ -1335,14 +1341,16 @@ pub fn dep_info_loc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> Pa
/// Returns an absolute path that the `unit`'s outputs should always be relative
/// to. This `target_root` variable is used to store relative path names in
/// `Fingerprint` instead of absolute pathnames (see module comment).
-fn target_root<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> PathBuf {
- if unit.mode.is_run_custom_build() {
- cx.files().build_script_run_dir(unit)
- } else if unit.kind == Kind::Host {
- cx.files().host_root().to_path_buf()
- } else {
- cx.files().target_root().to_path_buf()
- }
+// TODO: Rename to output_base or something
+fn target_root<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, _unit: &Unit<'a>) -> PathBuf {
+ cx.bcx.ws.target_dir().into_path_unlocked()
+ // if unit.mode.is_run_custom_build() {
+ // cx.files().build_script_run_dir(unit)
+ // // } else if unit.kind == Kind::Host {
+ // } else {
+ // cx.files().host_root().to_path_buf()
+ // // cx.files().target_root().to_path_buf()
+ // }
}
fn compare_old_fingerprint(
@@ -1395,6 +1403,7 @@ pub fn parse_dep_info(
target_root: &Path,
dep_info: &Path,
) -> CargoResult<Option<Vec<PathBuf>>> {
+ // eprintln!("parse target_root={:?}", target_root);
let data = match paths::read_bytes(dep_info) {
Ok(data) => data,
Err(_) => return Ok(None),
@@ -1414,12 +1423,13 @@ pub fn parse_dep_info(
DepInfoPathType::TargetRootRelative => Ok(target_root.join(path)),
}
})
+ // .inspect(|p| eprintln!("parsed={:?}", p))
.collect::<Result<Vec<_>, _>>()?;
- if paths.is_empty() {
- Ok(None)
- } else {
+ // if paths.is_empty() {
+ // Ok(None)
+ // } else {
Ok(Some(paths))
- }
+ // }
}
fn pkg_fingerprint(bcx: &BuildContext<'_, '_>, pkg: &Package) -> CargoResult<String> {
@@ -1541,6 +1551,7 @@ pub fn translate_dep_info(
rustc_cwd: &Path,
pkg_root: &Path,
target_root: &Path,
+ allow_package: bool,
) -> CargoResult<()> {
let target = parse_rustc_dep_info(rustc_dep_info)?;
let deps = &target
@@ -1548,10 +1559,15 @@ pub fn translate_dep_info(
.ok_or_else(|| internal("malformed dep-info format, no targets".to_string()))?
.1;
+ // eprintln!("translate target_root={:?}", target_root);
let mut new_contents = Vec::new();
for file in deps {
let file = rustc_cwd.join(file);
let (ty, path) = if let Ok(stripped) = file.strip_prefix(pkg_root) {
+ if !allow_package {
+ eprintln!("skipping {:?} {:?}", pkg_root, stripped);
+ continue;
+ }
(DepInfoPathType::PackageRootRelative, stripped)
} else if let Ok(stripped) = file.strip_prefix(target_root) {
(DepInfoPathType::TargetRootRelative, stripped)
@@ -1562,6 +1578,7 @@ pub fn translate_dep_info(
assert!(file.is_absolute(), "{:?} is absolute", file);
(DepInfoPathType::TargetRootRelative, &*file)
};
+ // eprintln!("file={:?} stripped={:?}", file, path);
new_contents.push(ty as u8);
new_contents.extend(util::path2bytes(&path)?);
new_contents.push(0);
diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs
index 628ac8bb..f6209a79 100644
--- a/src/cargo/core/compiler/mod.rs
+++ b/src/cargo/core/compiler/mod.rs
@@ -226,6 +226,7 @@ fn rustc<'a, 'cfg>(
let exec = exec.clone();
let root_output = cx.files().host_root().to_path_buf();
+ let target_dir = cx.bcx.ws.target_dir().into_path_unlocked();
let pkg_root = unit.pkg.root().to_path_buf();
let cwd = rustc
.get_cwd()
@@ -320,7 +321,8 @@ fn rustc<'a, 'cfg>(
&dep_info_loc,
&cwd,
&pkg_root,
- &root_output,
+ &target_dir,
+ current_id.source_id().is_path()
)
.chain_err(|| {
internal(format!(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment