Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update hakari.yml to be more modern + switch to AHashMap #154

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions .github/workflows/hakari.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,12 @@ jobs:
RUSTFLAGS: -D warnings
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1
with:
toolchain: stable
- uses: dtolnay/rust-toolchain@stable
- name: Install cargo-hakari
uses: taiki-e/install-action@4d8504289abd3a644c6237dea6005f9f28fba01b # v2
with:
tool: cargo-hakari
- name: Check workspace-hack Cargo.toml is up-to-date
uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 # v1
with:
command: hakari
args: generate --diff
run: cargo hakari generate --diff
- name: Check all crates depend on workspace-hack
uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 # v1
with:
command: hakari
args: manage-deps --dry-run
run: cargo hakari manage-deps --dry-run
33 changes: 31 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ members = [
]

[workspace.dependencies]
ahash = "0.8.6"
guppy-workspace-hack = "0.1.0"

[patch.crates-io.guppy-workspace-hack]
Expand Down
1 change: 1 addition & 0 deletions cargo-guppy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ license = "MIT OR Apache-2.0"
edition = "2018"

[dependencies]
ahash.workspace = true
camino = "1.1.6"
# disable tracing integration since we don't use it
color-eyre = { version = "0.6.2", default-features = false }
Expand Down
15 changes: 4 additions & 11 deletions cargo-guppy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ mod mv;

pub use crate::{core::*, mv::*};

use ahash::AHashMap;
use camino::Utf8PathBuf;
use clap::{ArgEnum, Parser};
use color_eyre::eyre::{bail, Result, WrapErr};
Expand All @@ -58,15 +59,7 @@ use guppy::{
use guppy_cmdlib::{
string_to_platform_spec, CargoMetadataOptions, CargoResolverOpts, PackagesAndFeatures,
};
use std::{
borrow::Cow,
cmp,
collections::{HashMap, HashSet},
fmt, fs,
io::Write,
iter,
path::PathBuf,
};
use std::{borrow::Cow, cmp, collections::HashSet, fmt, fs, io::Write, iter, path::PathBuf};

pub fn cmd_diff(json: bool, old: &str, new: &str) -> Result<()> {
let old_json = fs::read_to_string(old)?;
Expand Down Expand Up @@ -140,7 +133,7 @@ pub fn cmd_dups(opts: &DupsOptions) -> Result<()> {
let resolver = opts.filter_opts.make_resolver(&pkg_graph)?;
let selection = pkg_graph.query_workspace();

let mut dupe_map: HashMap<_, Vec<_>> = HashMap::new();
let mut dupe_map: AHashMap<_, Vec<_>> = AHashMap::new();
for package in selection
.resolve_with_fn(resolver)
.packages(DependencyDirection::Forward)
Expand Down Expand Up @@ -387,7 +380,7 @@ pub fn cmd_subtree_size(options: &SubtreeSizeOptions) -> Result<()> {
pkg_graph.query_workspace()
};

let mut unique_deps: HashMap<&PackageId, HashSet<&PackageId>> = HashMap::new();
let mut unique_deps: AHashMap<&PackageId, HashSet<&PackageId>> = AHashMap::new();
for package_id in selection
.resolve_with_fn(&resolver)
.package_ids(DependencyDirection::Forward)
Expand Down
5 changes: 5 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
disallowed-methods = [
# use ahash everywhere instead
"std::collections::hash::map::HashMap::new",
"std::collections::hash::map::HashMap::with_capacity",
]
1 change: 1 addition & 0 deletions fixtures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ publish = false
edition = "2018"

[dependencies]
ahash.workspace = true
camino = "1.1.6"
guppy = { path = "../guppy" }
once_cell = "1.18.0"
Expand Down
21 changes: 11 additions & 10 deletions fixtures/src/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
},
package_id,
};
use ahash::AHashMap;
use camino::Utf8PathBuf;
use guppy::{
errors::FeatureGraphWarning,
Expand All @@ -19,24 +20,24 @@ use guppy::{
DependencyKind, PackageId, Version,
};
use pretty_assertions::assert_eq;
use std::collections::{BTreeMap, HashMap};
use std::collections::BTreeMap;

/// This captures metadata fields that are relevant for tests. They are meant to be written out
/// lazily as tests are filled out -- feel free to add more details as necessary!
pub struct FixtureDetails {
workspace_members: Option<BTreeMap<Utf8PathBuf, PackageId>>,
package_details: HashMap<PackageId, PackageDetails>,
link_details: HashMap<(PackageId, PackageId), LinkDetails>,
package_details: AHashMap<PackageId, PackageDetails>,
link_details: AHashMap<(PackageId, PackageId), LinkDetails>,
feature_graph_warnings: Vec<FeatureGraphWarning>,
cycles: Vec<Vec<PackageId>>,
}

impl FixtureDetails {
pub fn new(package_details: HashMap<PackageId, PackageDetails>) -> Self {
pub fn new(package_details: AHashMap<PackageId, PackageDetails>) -> Self {
Self {
workspace_members: None,
package_details,
link_details: HashMap::new(),
link_details: AHashMap::new(),
feature_graph_warnings: vec![],
cycles: vec![],
}
Expand All @@ -57,7 +58,7 @@ impl FixtureDetails {

pub fn with_link_details(
mut self,
link_details: HashMap<(PackageId, PackageId), LinkDetails>,
link_details: AHashMap<(PackageId, PackageId), LinkDetails>,
) -> Self {
self.link_details = link_details;
self
Expand Down Expand Up @@ -456,7 +457,7 @@ impl PackageDetails {
self
}

pub fn insert_into(self, map: &mut HashMap<PackageId, PackageDetails>) {
pub fn insert_into(self, map: &mut AHashMap<PackageId, PackageDetails>) {
map.insert(self.id.clone(), self);
}

Expand Down Expand Up @@ -543,7 +544,7 @@ impl LinkDetails {
self
}

pub fn insert_into(self, map: &mut HashMap<(PackageId, PackageId), Self>) {
pub fn insert_into(self, map: &mut AHashMap<(PackageId, PackageId), Self>) {
map.insert((self.from.clone(), self.to.clone()), self);
}

Expand Down Expand Up @@ -601,7 +602,7 @@ pub struct PlatformResults {
// Each pair stands for (required on, enabled on).
status: (EnabledTernary, EnabledTernary),
default_features: (EnabledTernary, EnabledTernary),
feature_statuses: HashMap<String, (EnabledTernary, EnabledTernary)>,
feature_statuses: AHashMap<String, (EnabledTernary, EnabledTernary)>,
}

impl PlatformResults {
Expand All @@ -612,7 +613,7 @@ impl PlatformResults {
Self {
status,
default_features,
feature_statuses: HashMap::new(),
feature_statuses: AHashMap::new(),
}
}

Expand Down
Loading
Loading