5457: Simplify r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-07-20 16:13:18 +00:00 committed by GitHub
commit 7a089a7bab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 33 deletions

View file

@ -34,6 +34,7 @@ pub struct Crate {
pub(crate) target: Option<String>, pub(crate) target: Option<String>,
pub(crate) out_dir: Option<AbsPathBuf>, pub(crate) out_dir: Option<AbsPathBuf>,
pub(crate) proc_macro_dylib_path: Option<AbsPathBuf>, pub(crate) proc_macro_dylib_path: Option<AbsPathBuf>,
pub(crate) is_workspace_member: bool,
} }
impl ProjectJson { impl ProjectJson {
@ -43,7 +44,13 @@ impl ProjectJson {
crates: data crates: data
.crates .crates
.into_iter() .into_iter()
.map(|crate_data| Crate { .map(|crate_data| {
let is_workspace_member = crate_data.is_workspace_member.unwrap_or_else(|| {
crate_data.root_module.is_relative()
&& !crate_data.root_module.starts_with("..")
|| crate_data.root_module.starts_with(base)
});
Crate {
root_module: base.join(crate_data.root_module), root_module: base.join(crate_data.root_module),
edition: crate_data.edition.into(), edition: crate_data.edition.into(),
deps: crate_data deps: crate_data
@ -68,7 +75,11 @@ impl ProjectJson {
}, },
target: crate_data.target, target: crate_data.target,
out_dir: crate_data.out_dir.map(|it| base.join(it)), out_dir: crate_data.out_dir.map(|it| base.join(it)),
proc_macro_dylib_path: crate_data.proc_macro_dylib_path.map(|it| base.join(it)), proc_macro_dylib_path: crate_data
.proc_macro_dylib_path
.map(|it| base.join(it)),
is_workspace_member,
}
}) })
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
} }
@ -91,6 +102,7 @@ struct CrateData {
target: Option<String>, target: Option<String>,
out_dir: Option<PathBuf>, out_dir: Option<PathBuf>,
proc_macro_dylib_path: Option<PathBuf>, proc_macro_dylib_path: Option<PathBuf>,
is_workspace_member: Option<bool>,
} }
#[derive(Deserialize)] #[derive(Deserialize)]

View file

@ -83,11 +83,11 @@ impl Directories {
self.includes_path(path) self.includes_path(path)
} }
fn includes_path(&self, path: &AbsPath) -> bool { fn includes_path(&self, path: &AbsPath) -> bool {
let mut include = None; let mut include: Option<&AbsPathBuf> = None;
for incl in &self.include { for incl in &self.include {
if is_prefix(incl, path) { if path.starts_with(incl) {
include = Some(match include { include = Some(match include {
Some(prev) if is_prefix(incl, prev) => prev, Some(prev) if prev.starts_with(incl) => prev,
_ => incl, _ => incl,
}) })
} }
@ -97,15 +97,11 @@ impl Directories {
None => return false, None => return false,
}; };
for excl in &self.exclude { for excl in &self.exclude {
if is_prefix(excl, path) && is_prefix(include, excl) { if path.starts_with(excl) && excl.starts_with(include) {
return false; return false;
} }
} }
return true; true
fn is_prefix(short: &AbsPath, long: &AbsPath) -> bool {
long.strip_prefix(short).is_some()
}
} }
} }