-
Notifications
You must be signed in to change notification settings - Fork 43
Prune dependencies of timezone_provider in normal mode, add depcheck #310
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| [package] | ||
| name = "depcheck" | ||
| edition.workspace = true | ||
| version.workspace = true | ||
| rust-version.workspace = true | ||
| authors.workspace = true | ||
| license.workspace = true | ||
| repository.workspace = true | ||
| readme.workspace = true | ||
| exclude.workspace = true | ||
|
|
||
| [dependencies] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| //! Test for ensuring that we don't unintentionally add deps | ||
|
|
||
| use std::collections::BTreeSet; | ||
| use std::process::{self, Command}; | ||
| use std::str; | ||
|
|
||
| #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
| struct DepSpec { | ||
| crate_name: String, | ||
| crate_version: String, | ||
| } | ||
|
|
||
| /// Get the deep (fully resolved) dependency list produced by `cargo tree -p {package} -e {edge_kind}` | ||
| fn get_dep_list(package: &str, edge_kind: &str, extra_args: &str) -> Vec<DepSpec> { | ||
| let mut cmd = Command::new("cargo"); | ||
| cmd.arg("tree") | ||
| .arg("-p") | ||
| .arg(package) | ||
| .arg("-e") | ||
| .arg(edge_kind) | ||
| .arg("--no-default-features"); | ||
| for arg in extra_args.split(' ') { | ||
| if !arg.is_empty() { | ||
| cmd.arg(arg); | ||
| } | ||
| } | ||
| let output = cmd.output().expect("Failed to run `cargo tree`"); | ||
|
|
||
| if !output.status.success() { | ||
| eprintln!("Failed to run `cargo tree -p {package} -e {edge_kind} --no-default-features {extra_args}`:"); | ||
| if let Ok(s) = str::from_utf8(&output.stderr) { | ||
| eprintln!("{s}"); | ||
| } | ||
| process::exit(1); | ||
| } | ||
| let mut spec: Vec<_> = output | ||
| .stdout | ||
| .split(|b| *b == b'\n') | ||
| .filter_map(|slice| { | ||
| if slice.is_empty() { | ||
| return None; | ||
| } | ||
| if slice[0] == b'[' { | ||
| // cargo tree output has sections like `[dev-dependencies]` | ||
| return None; | ||
| } | ||
|
|
||
| let mut iter = slice.split(|b| *b == b' '); | ||
| let mut found_crate_name = None; | ||
| for section in &mut iter { | ||
| if section.is_empty() { | ||
| continue; | ||
| } | ||
| // The format is {line drawing characters} {crate name} {crate version} | ||
| if char::from(section[0]).is_ascii_alphabetic() { | ||
| found_crate_name = | ||
| Some(str::from_utf8(section).expect("Must be utf-8").to_owned()); | ||
| break; | ||
| } | ||
| } | ||
| if let Some(crate_name) = found_crate_name { | ||
| let crate_version = iter | ||
| .next() | ||
| .expect("There must be a version after the crate name!"); | ||
| let crate_version = str::from_utf8(crate_version) | ||
| .expect("Must be utf-8") | ||
| .to_owned(); | ||
| Some(DepSpec { | ||
| crate_name, | ||
| crate_version, | ||
| }) | ||
| } else { | ||
| None | ||
| } | ||
| }) | ||
| .collect(); | ||
| spec.sort(); | ||
| spec.dedup(); | ||
|
|
||
| spec | ||
| } | ||
|
|
||
| /// Given a `cargo tree` invocation and the dependency sets to check, checks for any unlisted or duplicated deps | ||
| /// | ||
| /// `dep_list_name_for_error` is the name of the const above to show in the error suggestion | ||
| fn test_dep_list( | ||
| package: &str, | ||
| edge_kind: &str, | ||
| extra_args: &str, | ||
| sets: &[&BTreeSet<&str>], | ||
| dep_list_name_for_error: &str, | ||
| ) { | ||
| println!("Testing `cargo tree -p {package} -e {edge_kind} --no-default-features {extra_args}`"); | ||
| let mut errors = Vec::new(); | ||
| let dep_list = get_dep_list(package, edge_kind, extra_args); | ||
| for i in dep_list.windows(2) { | ||
| if i[0].crate_name == i[1].crate_name { | ||
| errors.push(format!( | ||
| "Found two versions for `{0}` ({1} & {2})", | ||
| i[0].crate_name, i[0].crate_version, i[1].crate_version | ||
| )); | ||
| } | ||
| } | ||
|
|
||
| 'dep_loop: for i in dep_list { | ||
| if i.crate_name == package { | ||
| continue; | ||
| } | ||
| let name = &i.crate_name; | ||
| for s in sets { | ||
| if s.contains(&**name) { | ||
| continue 'dep_loop; | ||
| } | ||
| } | ||
| errors.push(format!( | ||
| "Found non-allowlisted crate `{name}`, consider adding to \ | ||
| {dep_list_name_for_error} in depcheck/src/main.rs if intentional" | ||
| )); | ||
| } | ||
|
|
||
| if !errors.is_empty() { | ||
| eprintln!("Found invalid dependencies:"); | ||
| for e in errors { | ||
| eprintln!("\t{e}"); | ||
| } | ||
| process::exit(1); | ||
| } | ||
| } | ||
|
|
||
| fn main() { | ||
| let basic_runtime: BTreeSet<_> = BASIC_RUNTIME_DEPS.iter().copied().collect(); | ||
| let compiled_data: BTreeSet<_> = COMPILED_DEPS.iter().copied().collect(); | ||
|
|
||
| test_dep_list( | ||
| "temporal_capi", | ||
| "normal,no-proc-macro", | ||
| "", | ||
| &[&basic_runtime], | ||
| "`BASIC_RUNTIME_DEPS`", | ||
| ); | ||
|
|
||
| test_dep_list( | ||
| "temporal_capi", | ||
| "normal,no-proc-macro", | ||
| "--features compiled_data", | ||
| &[&basic_runtime, &compiled_data], | ||
| "`COMPILED_DEPS`", | ||
| ); | ||
| } | ||
|
|
||
| /// Dependencies that are always allowed as runtime dependencies | ||
| /// | ||
| pub const BASIC_RUNTIME_DEPS: &[&str] = &[ | ||
| // temporal_rs crates | ||
| "temporal_rs", | ||
| // ICU4X components and utils | ||
| "calendrical_calculations", | ||
| "core_maths", | ||
| "diplomat-runtime", | ||
| "icu_calendar", | ||
| "icu_calendar_data", | ||
| "icu_collections", | ||
| "icu_locale", | ||
| "icu_locale_core", | ||
| "icu_locale_data", | ||
| "icu_provider", | ||
| "ixdtf", | ||
| "litemap", | ||
| "potential_utf", | ||
| "tinystr", | ||
| "writeable", | ||
| "yoke", | ||
| "zerofrom", | ||
| "zerotrie", | ||
| "zerovec", | ||
| // Other deps | ||
| "libm", | ||
| "num-traits", | ||
| "stable_deref_trait", | ||
| ]; | ||
|
|
||
| // Most of these should be removed | ||
| pub const COMPILED_DEPS: &[&str] = &[ | ||
| "bytes", | ||
| "combine", | ||
| "jiff-tzdb", | ||
| "memchr", | ||
| "tzif", | ||
| "timezone_provider", | ||
| ]; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of these parser deps should be showing up here.