From b6017b4f0571885b674832e1f3fccf7a601e0394 Mon Sep 17 00:00:00 2001 From: Alexander Koz Date: Fri, 12 Jul 2024 21:42:19 +0400 Subject: [PATCH] fmt, because some nightly rustfmt fixes --- cargo/src/build/mod.rs | 128 ++++++++++++++++++++------------------- cargo/src/config.rs | 13 ++-- cargo/src/init/mod.rs | 7 ++- cargo/src/package/mod.rs | 2 +- 4 files changed, 77 insertions(+), 73 deletions(-) diff --git a/cargo/src/build/mod.rs b/cargo/src/build/mod.rs index a5bf89b1..69a38dca 100644 --- a/cargo/src/build/mod.rs +++ b/cargo/src/build/mod.rs @@ -210,53 +210,53 @@ pub fn build(cfg: &Config, tree: &MetaDeps) -> CargoResult> { let mut crate_types_cache = BTreeMap::new(); let removed = roots.extract_if(|root| { - let tk = root.node().target().kind(); - let ck = root.node().unit().platform; - - log::trace!(" check {} {}", tk.description(), match ck { - CompileKind::Host => "host", - CompileKind::Target(ref kind) => kind.short_name(), - }); - - if reserved_roots.contains(root) { - log::trace!(" excluding, reserved root"); - return true; - } - - { - use cargo::core::TargetKind as Tk; - if executable && !matches!(tk, Tk::Bin | Tk::ExampleBin) { - log::trace!(" excluding, is not executable"); - return true; - } - } - - let target = targets_cache.entry(*root) - .or_insert_with(|| target_for_root(root)); - - let ct = determine_crate_types(cfg, art, target, tk.clone(), ck).collect::>(); - - let is_good = art.filenames.len() == ct.len() && - !ct.iter().any(|(_, ct)| ct.is_none()); - if is_good { - // save resolved crate-types: - let ct = ct.into_iter() - .filter_map(|(p, ct)| ct.map(|ct| (p.to_owned(), ct))); - crate_types_cache.extend(ct); - } - - need_remove_roots && !is_good - }) - .inspect(|r| { - let p = r.package_id().name(); - let t = r.node().target().name.as_str(); - log::trace!(" excluded: {p}::{t} {:?}", match r.node().unit().platform - { - CompileKind::Host => "host", - CompileKind::Target(ref kind) => kind.short_name(), - }) - }) - .count(); + let tk = root.node().target().kind(); + let ck = root.node().unit().platform; + + log::trace!(" check {} {}", tk.description(), match ck { + CompileKind::Host => "host", + CompileKind::Target(ref kind) => kind.short_name(), + }); + + if reserved_roots.contains(root) { + log::trace!(" excluding, reserved root"); + return true; + } + + { + use cargo::core::TargetKind as Tk; + if executable && !matches!(tk, Tk::Bin | Tk::ExampleBin) { + log::trace!(" excluding, is not executable"); + return true; + } + } + + let target = targets_cache.entry(*root) + .or_insert_with(|| target_for_root(root)); + + let ct = + determine_crate_types(cfg, art, target, tk.clone(), ck).collect::>(); + + let is_good = + art.filenames.len() == ct.len() && !ct.iter().any(|(_, ct)| ct.is_none()); + if is_good { + // save resolved crate-types: + let ct = ct.into_iter() + .filter_map(|(p, ct)| ct.map(|ct| (p.to_owned(), ct))); + crate_types_cache.extend(ct); + } + + need_remove_roots && !is_good + }) + .inspect(|r| { + let p = r.package_id().name(); + let t = r.node().target().name.as_str(); + log::trace!(" excluded: {p}::{t} {:?}", match r.node().unit().platform { + CompileKind::Host => "host", + CompileKind::Target(ref kind) => kind.short_name(), + }) + }) + .count(); if removed > 0 { log::trace!(" excluded: {removed}, now roots: {}", roots.len()); @@ -335,10 +335,11 @@ pub fn build(cfg: &Config, tree: &MetaDeps) -> CargoResult> { }) .collect::>(); - let ck_exact = ck_name.iter().copied().find(|ck| { - comps.iter() - .all(|(_num, first)| matches!(first, Some(s) if *s == *ck)) - }); + let ck_exact = + ck_name.iter().copied().find(|ck| { + comps.iter() + .all(|(_num, first)| matches!(first, Some(s) if *s == *ck)) + }); let removed = if let Some(ck) = ck_exact { roots.extract_if(|root| { @@ -594,18 +595,19 @@ fn map_artifacts<'cargo, 'cfg, 't>(tree: &'t MetaDeps<'cfg>, artifacts.filter(|art| matches!(art.target.kind, TK::Lib(_) | TK::Bin | TK::Example)) .filter_map(move |art| { - let findings = tree.roots() - .iter() - .filter(|r| { - let unit = r.node().unit(); - unit.package_id == art.package_id && - unit.target.name.as_str() == art.target.name.as_str() && - unit.target.kind() == art.target.kind() && - unit.target.crate_types == art.target.crate_types && - Some(unit.target.src_path.as_str().into()) == art.target.src_path - }) - .inspect(|r| log::trace!("root for artifact found: {:?} {r}", art.target.crate_types)) - .collect::>(); + let findings = + tree.roots() + .iter() + .filter(|r| { + let unit = r.node().unit(); + unit.package_id == art.package_id && + unit.target.name.as_str() == art.target.name.as_str() && + unit.target.kind() == art.target.kind() && + unit.target.crate_types == art.target.crate_types && + Some(unit.target.src_path.as_str().into()) == art.target.src_path + }) + .inspect(|r| log::trace!("root for artifact found: {:?} {r}", art.target.crate_types)) + .collect::>(); (!findings.is_empty()).then_some((art, findings)) }) .filter(|(_, roots)| !roots.is_empty()) diff --git a/cargo/src/config.rs b/cargo/src/config.rs index 8345693e..adccf8d4 100644 --- a/cargo/src/config.rs +++ b/cargo/src/config.rs @@ -154,12 +154,13 @@ impl<'cfg> Config<'cfg> { pub fn gcc(&self) -> CargoResult<&ArmToolchain> { self.gcc.try_get_or_create(|| { - let res = (!self.no_gcc).then(|| { - self.gcc_path.as_ref().map_or_else(ArmToolchain::try_new, |p| { - Gcc::try_new_exact_path(p).and_then(ArmToolchain::try_new_with) - }) - }) - .ok_or_else(|| anyhow::anyhow!("Attempt to get arm-gcc but 'no-gcc' is set"))??; + let res = + (!self.no_gcc).then(|| { + self.gcc_path.as_ref().map_or_else(ArmToolchain::try_new, |p| { + Gcc::try_new_exact_path(p).and_then(ArmToolchain::try_new_with) + }) + }) + .ok_or_else(|| anyhow::anyhow!("Attempt to get arm-gcc but 'no-gcc' is set"))??; Ok(res) }) } diff --git a/cargo/src/init/mod.rs b/cargo/src/init/mod.rs index 485247ae..f367df4f 100644 --- a/cargo/src/init/mod.rs +++ b/cargo/src/init/mod.rs @@ -337,9 +337,10 @@ fn cargo_config>(config: &Config, path: P) -> CargoResult<()> { // default if !config.create_full_config { // target[].rustflags: - let rustflags: Vec = Rustflags::rustflags_bin_playdate().iter() - .map(|s| toml::Value::String(s.to_string())) - .collect(); + let rustflags: Vec = + Rustflags::rustflags_bin_playdate().iter() + .map(|s| toml::Value::String(s.to_string())) + .collect(); let mut target_table = toml::Table::new(); target_table.insert("rustflags".into(), rustflags.into()); diff --git a/cargo/src/package/mod.rs b/cargo/src/package/mod.rs index f2e71e91..7f49c660 100644 --- a/cargo/src/package/mod.rs +++ b/cargo/src/package/mod.rs @@ -87,7 +87,7 @@ pub fn build_all(config: &'_ Config, unit.platform == products[0].ck && unit.target.crate_types.contains(&products[0].src_ct) && unit.target.name == products[0].name) - .then_some((r, Some(arts))) + .then_some((r, Some(arts))) }) .or_else(|| { assets.tree