Skip to content

Commit

Permalink
Merge pull request #143 from dtolnay/outdir
Browse files Browse the repository at this point in the history
Normalize paths under Cargo out directory
  • Loading branch information
dtolnay authored Dec 3, 2021
2 parents eeae38a + d222526 commit b90de83
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
34 changes: 33 additions & 1 deletion src/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}

Expand Down Expand Up @@ -162,14 +163,45 @@ 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
.to_string_lossy()
.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 {
Expand Down
1 change: 1 addition & 0 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
);
Expand Down
37 changes: 36 additions & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@ 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 {
krate: "trybuild000",
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"),
Expand Down Expand Up @@ -308,3 +317,29 @@ note: required by a bound in `dropshot::Query`
| pub struct Query<QueryType: DeserializeOwned + JsonSchema + Send + Sync> {
| ^^^^^^^^^^ required by this 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<Counter>: FfiConverter` is not satisfied
--> /git/uniffi-rs/target/debug/build/uniffi_uitests-1a51d46aecb559a7/out/counter.uniffi.rs:160:19
|
160 | match <std::sync::Arc<Counter> as uniffi::FfiConverter>::try_lift(ptr) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FfiConverter` is not implemented for `Arc<Counter>`
|
= help: the following implementations were found:
<Arc<T> as FfiConverter>
= note: required by `try_lift`
" "
error[E0277]: the trait bound `Arc<Counter>: FfiConverter` is not satisfied
--> $OUT_DIR[uniffi_uitests]/counter.uniffi.rs
|
| match <std::sync::Arc<Counter> as uniffi::FfiConverter>::try_lift(ptr) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FfiConverter` is not implemented for `Arc<Counter>`
|
= help: the following implementations were found:
<Arc<T> as FfiConverter>
= note: required by `try_lift`
"}

0 comments on commit b90de83

Please sign in to comment.