From 42eb79e1f6205dd688b9cf87f1352c4ea72e79fb Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 2 Dec 2021 17:50:12 -0800 Subject: [PATCH 1/2] Add test of normalizing errors emitted by uniffi inside OUT_DIR --- src/tests.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/tests.rs b/src/tests.rs index 604c1fb..aa9cd34 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -308,3 +308,28 @@ note: required by a bound in `dropshot::Query` | pub struct Query { | ^^^^^^^^^^ required by this bound in `dropshot::Query` "} + +test_normalize! {test_uniffi_out_dir + DIR="/git/uniffi-rs/fixtures/uitests" + WORKSPACE="/git/uniffi-rs" +" +error[E0277]: the trait bound `Arc: FfiConverter` is not satisfied + --> /git/uniffi-rs/target/debug/build/uniffi_uitests-1a51d46aecb559a7/out/counter.uniffi.rs:160:19 + | +160 | match as uniffi::FfiConverter>::try_lift(ptr) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FfiConverter` is not implemented for `Arc` + | + = help: the following implementations were found: + as FfiConverter> + = note: required by `try_lift` +" " +error[E0277]: the trait bound `Arc: FfiConverter` is not satisfied + --> $WORKSPACE/target/debug/build/uniffi_uitests-1a51d46aecb559a7/out/counter.uniffi.rs + | + | match as uniffi::FfiConverter>::try_lift(ptr) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FfiConverter` is not implemented for `Arc` + | + = help: the following implementations were found: + as FfiConverter> + = note: required by `try_lift` +"} From d2225265665c5ed376c3572f72663947bfa74d43 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 2 Dec 2021 19:13:48 -0800 Subject: [PATCH 2/2] Normalize paths under Cargo out directory --- src/normalize.rs | 34 +++++++++++++++++++++++++++++++++- src/run.rs | 1 + src/tests.rs | 14 ++++++++++++-- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/normalize.rs b/src/normalize.rs index 13eabbc..3cd5699 100644 --- a/src/normalize.rs +++ b/src/normalize.rs @@ -12,6 +12,7 @@ pub struct Context<'a> { pub source_dir: &'a Directory, pub workspace: &'a Directory, pub input_file: &'a Path, + pub target_dir: &'a Directory, pub path_dependencies: &'a [PathDependency], } @@ -162,6 +163,12 @@ impl<'a> Filter<'a> { if let Some(prefix) = prefix { line = line.replace('\\', "/"); let line_lower = line.to_ascii_lowercase(); + let target_dir_pat = self + .context + .target_dir + .to_string_lossy() + .to_ascii_lowercase() + .replace('\\', "/"); let source_dir_pat = self .context .source_dir @@ -169,7 +176,32 @@ impl<'a> Filter<'a> { .to_ascii_lowercase() .replace('\\', "/"); let mut other_crate = false; - if let Some(i) = line_lower.find(&source_dir_pat) { + if line_lower.find(&target_dir_pat) == Some(indent + 4) { + let mut offset = indent + 4 + target_dir_pat.len(); + let mut out_dir_crate_name = None; + while let Some(slash) = line[offset..].find('/') { + let component = &line[offset..offset + slash]; + if component == "out" { + if let Some(out_dir_crate_name) = out_dir_crate_name { + let replacement = format!("$OUT_DIR[{}]", out_dir_crate_name); + line.replace_range(indent + 4..offset + 3, &replacement); + other_crate = true; + break; + } + } else if component.len() > 17 + && component.rfind('-') == Some(component.len() - 17) + && component[component.len() - 16..].bytes().all(|b| match b { + b'0'..=b'9' | b'a'..=b'f' => true, + _ => false, + }) + { + out_dir_crate_name = Some(&component[..component.len() - 17]); + } else { + out_dir_crate_name = None; + } + offset += slash + 1; + } + } else if let Some(i) = line_lower.find(&source_dir_pat) { if self.normalization >= RelativeToDir && i == indent + 4 { line.replace_range(i..i + source_dir_pat.len(), ""); if self.normalization < LinesOutsideInputFile { diff --git a/src/run.rs b/src/run.rs index cca7cf9..0495908 100644 --- a/src/run.rs +++ b/src/run.rs @@ -268,6 +268,7 @@ impl Test { source_dir: &project.source_dir, workspace: &project.workspace, input_file: &self.path, + target_dir: &project.target_dir, path_dependencies: &project.path_dependencies, }, ); diff --git a/src/tests.rs b/src/tests.rs index aa9cd34..611a482 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -3,7 +3,15 @@ use crate::run::PathDependency; use std::path::Path; macro_rules! test_normalize { - ($name:ident $(DIR=$dir:literal)? $(WORKSPACE=$workspace:literal)? $(INPUT=$input:literal)? $original:literal $expected:literal) => { + ( + $name:ident + $(DIR=$dir:literal)? + $(WORKSPACE=$workspace:literal)? + $(INPUT=$input:literal)? + $(TARGET=$target:literal)? + $original:literal + $expected:literal + ) => { #[test] fn $name() { let context = super::Context { @@ -11,6 +19,7 @@ macro_rules! test_normalize { input_file: Path::new({ "tests/ui/error.rs" $(; $input)? }), source_dir: &Directory::new({ "/git/trybuild/test_suite" $(; $dir)? }), workspace: &Directory::new({ "/git/trybuild" $(; $workspace)? }), + target_dir: &Directory::new({ "/git/trybuild/target" $(; $target)? }), path_dependencies: &[PathDependency { name: String::from("diesel"), normalized_path: Directory::new("/home/user/documents/rust/diesel/diesel"), @@ -312,6 +321,7 @@ note: required by a bound in `dropshot::Query` test_normalize! {test_uniffi_out_dir DIR="/git/uniffi-rs/fixtures/uitests" WORKSPACE="/git/uniffi-rs" + TARGET="/git/uniffi-rs/target" " error[E0277]: the trait bound `Arc: FfiConverter` is not satisfied --> /git/uniffi-rs/target/debug/build/uniffi_uitests-1a51d46aecb559a7/out/counter.uniffi.rs:160:19 @@ -324,7 +334,7 @@ error[E0277]: the trait bound `Arc: FfiConverter` is not satisfied = note: required by `try_lift` " " error[E0277]: the trait bound `Arc: FfiConverter` is not satisfied - --> $WORKSPACE/target/debug/build/uniffi_uitests-1a51d46aecb559a7/out/counter.uniffi.rs + --> $OUT_DIR[uniffi_uitests]/counter.uniffi.rs | | match as uniffi::FfiConverter>::try_lift(ptr) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FfiConverter` is not implemented for `Arc`