Skip to content

Commit

Permalink
Update cargo dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed May 10, 2023
1 parent 3e035a4 commit 95b4bbc
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 60 deletions.
85 changes: 29 additions & 56 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions dylint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ repository = "https://github.com/trailofbits/dylint"
ansi_term = "0.12"
anyhow = "1.0"
atty = "0.2"
cargo = { version = "0.69", optional = true }
# smoelius: The `cargo` dependency should be kept in sync with dylint/src/toml.rs.
cargo = { version = "0.70", optional = true }
cargo-platform = { version = "0.1", optional = true }
cargo-util = { version = "0.2", optional = true }
cargo_metadata = "0.15"
Expand All @@ -26,6 +27,7 @@ semver = "1.0"
serde = "1.0"
serde_json = "1.0"
tempfile = "3.5"
toml = { version = "0.7", optional = true }
walkdir = "2.3"

dylint_internal = { version = "=2.1.7", path = "../internal", features = ["git", "packaging", "rustup", "sed"] }
Expand All @@ -42,5 +44,5 @@ dylint_internal = { version = "=2.1.7", path = "../internal", features = ["examp

[features]
default = ["metadata"]
metadata = ["cargo", "cargo-platform", "cargo-util", "glob", "if_chain"]
metadata = ["cargo", "cargo-platform", "cargo-util", "glob", "if_chain", "toml"]
package_options = ["dylint_internal/clippy_utils", "dylint_internal/git"]
12 changes: 12 additions & 0 deletions dylint/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,18 @@ fn dependency(
config: &Config,
library: &Library,
) -> Result<Dependency> {
let mut unused_keys = library.details.unused_keys();
if !unused_keys.is_empty() {
unused_keys.sort_unstable();
bail!(
"Unknown library keys:{}",
unused_keys
.iter()
.map(|name| format!("\n {name}"))
.collect::<String>()
);
}

let name_in_toml = "library";

let mut deps = vec![];
Expand Down
24 changes: 22 additions & 2 deletions dylint/src/toml.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
// smoelius: This file is essentially the dependency specific portions of
// https://github.com/rust-lang/cargo/blob/master/src/cargo/util/toml/mod.rs (version 0.69.1) with
// https://github.com/rust-lang/cargo/blob/master/src/cargo/util/toml/mod.rs (version 0.70.1) with
// adjustments to make some things public.
// smoelius: I experimented with creating a reduced Cargo crate that included just this module and
// the things it depends upon. Such a crate could reduce build times and incur less of a maintenance
// burden than this file. However, Cargo's modules appear to be highly interdependent, as can be
// seen by running the following command in the root of the Cargo repository:
//
// cargo modules generate graph --package cargo --lib --uses
//
// Hence, I think that idea is a dead end.

#![allow(unused_imports)]
#![allow(clippy::default_trait_access)]
Expand All @@ -19,6 +27,13 @@
)]
#![cfg_attr(dylint_lib = "overscoped_allow", allow(overscoped_allow))]

// smoelius: `DetailedTomlDependency::unused_keys` does not appear in the original.
impl DetailedTomlDependency {
pub fn unused_keys(&self) -> Vec<String> {
self.other.keys().cloned().collect()
}
}

// smoelius: `Context::new` does not appear in the original.
#[allow(clippy::too_many_arguments)]
impl<'a, 'b> Context<'a, 'b> {
Expand Down Expand Up @@ -60,9 +75,9 @@ use cargo_util::paths;
use log::{debug, trace};
use semver::{self, VersionReq};
use serde::de;
use serde::de::IntoDeserializer as _;
use serde::ser;
use serde::{Deserialize, Serialize};
// use toml_edit::easy as toml;
// use url::Url;

use crate::core::compiler::{CompileKind, CompileTarget};
Expand Down Expand Up @@ -132,6 +147,10 @@ pub struct DetailedTomlDependency<P: Clone = String> {
lib: Option<bool>,
/// A platform name, like `x86_64-apple-darwin`
target: Option<String>,
/// This is here to provide a way to see the "unused manifest keys" when deserializing
#[serde(skip_serializing)]
#[serde(flatten)]
other: BTreeMap<String, toml::Value>,
}

// Explicit implementation so we avoid pulling in P: Default
Expand All @@ -155,6 +174,7 @@ impl<P: Clone> Default for DetailedTomlDependency<P> {
artifact: Default::default(),
lib: Default::default(),
target: Default::default(),
other: Default::default(),
}
}
}
Expand Down

0 comments on commit 95b4bbc

Please sign in to comment.