Skip to content

Commit

Permalink
Fix stuff and add --locked
Browse files Browse the repository at this point in the history
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  • Loading branch information
ggwpez committed Jul 27, 2023
1 parent 5a07466 commit 9e61f90
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/cmd/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl LintCmd {
}
}

#[derive(Clone, Eq, Ord, PartialEq, PartialOrd)]
#[derive(Clone, Eq, Ord, PartialEq, PartialOrd, Debug)]
struct CrateAndFeature(String, String);

impl Display for CrateAndFeature {
Expand Down Expand Up @@ -227,8 +227,11 @@ impl NeverImpliesCmd {
// TODO cleanup this cluster fuck
let lookup = |id: &str| {
pkgs.iter()
.find(|pkg| pkg.id.to_string() == id)
.unwrap_or_else(|| panic!("Could not find crate '{id}' in the metadata"))
.find(|pkg| {
pkg.id.to_string().split(' ').next().unwrap() ==
id.split(' ').next().unwrap()
})
.unwrap_or_else(|| panic!("Could not find crate '{id}' in the metadata."))
};

let delimiter = self.path_delimiter.replace("\\n", "\n").replace("\\t", "\t");
Expand All @@ -248,6 +251,8 @@ impl NeverImpliesCmd {
if self.show_source {
if let Some(source) = krate.source.as_ref() {
out.push_str(&format!(" ({})", source.repr));
} else {
out.push_str(" (local)");
}
}
});
Expand Down Expand Up @@ -276,13 +281,20 @@ impl NeverEnablesCmd {

for lhs in pkgs.iter() {
let Some(enabled) = lhs.features.get(&self.precondition) else { continue };

// TODO do the same in other command.
if enabled.contains(&format!("{}", self.stays_disabled)) {
offenders.entry(lhs.id.to_string()).or_default().insert(RenamedPackage::new(
(*lhs).clone(),
None,
false,
)); // TODO
} else {
log::info!(
"Feature {:?} not enabled on crate {:?}: {enabled:?}",
self.stays_disabled,
lhs.id
);
}

for rhs in lhs.dependencies.iter() {
Expand Down Expand Up @@ -548,6 +560,8 @@ impl OnlyEnablesCmd {
for (feat, imply) in pkg.features.iter() {
if feat == &self.precondition {
continue
} else {
log::info!("{}: {}", feat, imply.join(", "));
}

let opt = if dep.optional { "?" } else { "" };
Expand Down
9 changes: 9 additions & 0 deletions src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ pub struct CargoArgs {
#[clap(long, global = true)]
pub offline: bool,

/// Whether to use all the locked dependencies from the `Cargo.lock`.
///
/// Otherwise it may update some dependencies. For CI usage its a good idea to use it.
#[clap(long, global = true)]
pub locked: bool,

#[clap(long, global = true)]
pub all_features: bool,
}
Expand All @@ -81,6 +87,9 @@ impl CargoArgs {
if self.offline {
cmd.other_options(vec!["--offline".to_string()]);
}
if self.locked {
cmd.other_options(vec!["--locked".to_string()]);
}

cmd.exec().map_err(|e| format!("Failed to load metadata: {e}"))
}
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ impl TraceCmd {
if self.show_source {
if let Some(source) = krate.source.as_ref() {
out.push_str(&format!(" ({})", source.repr));
} else {
out.push_str(" (local)");
}
}
});
Expand Down
14 changes: 14 additions & 0 deletions src/dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ pub struct Dag<T> {
pub edges: BTreeMap<T, BTreeSet<T>>,
}

impl<T> Display for Dag<T>
where
T: Display,
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
for (from, tos) in self.edges.iter() {
for to in tos {
write!(f, "{} -> {}\n", from, to)?;
}
}
Ok(())
}
}

impl<T> Default for Dag<T> {
fn default() -> Self {
Self { edges: BTreeMap::new() }
Expand Down

0 comments on commit 9e61f90

Please sign in to comment.