Skip to content

Commit

Permalink
fmt, because some nightly rustfmt fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
boozook committed Jul 12, 2024
1 parent 549fc34 commit b6017b4
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 73 deletions.
128 changes: 65 additions & 63 deletions cargo/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,53 +210,53 @@ pub fn build(cfg: &Config, tree: &MetaDeps) -> CargoResult<Vec<BuildProduct>> {
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::<Vec<_>>();

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::<Vec<_>>();

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());
Expand Down Expand Up @@ -335,10 +335,11 @@ pub fn build(cfg: &Config, tree: &MetaDeps) -> CargoResult<Vec<BuildProduct>> {
})
.collect::<BTreeSet<_>>();

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| {
Expand Down Expand Up @@ -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::<Vec<_>>();
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::<Vec<_>>();
(!findings.is_empty()).then_some((art, findings))
})
.filter(|(_, roots)| !roots.is_empty())
Expand Down
13 changes: 7 additions & 6 deletions cargo/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down
7 changes: 4 additions & 3 deletions cargo/src/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,10 @@ fn cargo_config<P: AsRef<Path>>(config: &Config, path: P) -> CargoResult<()> {
// default
if !config.create_full_config {
// target[].rustflags:
let rustflags: Vec<toml::Value> = Rustflags::rustflags_bin_playdate().iter()
.map(|s| toml::Value::String(s.to_string()))
.collect();
let rustflags: Vec<toml::Value> =
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());
Expand Down
2 changes: 1 addition & 1 deletion cargo/src/package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b6017b4

Please sign in to comment.