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

Script that runs the lints on most popular crates #207

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

tonowak
Copy link
Collaborator

@tonowak tonowak commented Dec 3, 2022

It downloads data from crates.io about the most downloaded crates and its versions, and then runs cargo-semver-checks on those crates to find false-positives or bugs in the tool.

scripts/run_on_popular_crates/src/main.rs Outdated Show resolved Hide resolved
scripts/run_on_popular_crates/src/main.rs Outdated Show resolved Hide resolved
scripts/run_on_popular_crates/src/main.rs Outdated Show resolved Hide resolved
scripts/run_on_popular_crates/src/main.rs Outdated Show resolved Hide resolved
scripts/run_on_popular_crates/src/main.rs Outdated Show resolved Hide resolved
for (i, version_i0) in versions.iter().enumerate() {
if i + 1 < versions.len() {
let version_i1 = &versions[i + 1];
if version_i0.yanked && !version_i1.yanked { // it gives more interesting results for testing
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would certainly give interesting results, but aren't we primarily interested in checking the most recent version vs its baseline? I'd assume we want to make sure:

  • new crates can adopt cargo-semver-checks without running into any errors
  • we don't keep re-checking mostly-the-same code over and over again, and instead make better use of our limited CPU time

I think this is fine to have as a mode behind a flag, but I think the primary mode of this tool would just be to check the most recent "normal" version of each crate against its baseline.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed yanked releases in 4f46322.
It nerveless didn't work, because cargo doesn't allow setting a yanked release as a dependency.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I plan to add --all-releases and --only-latest-release as commands when the script will work.

Comment on lines 91 to 93
save_manifest(create_rustdoc_manifest_for_crate_version(&crate_info.name, &version_i0.num, &version_i0.features), "crate_current/Cargo.toml")?;
save_manifest(create_rustdoc_manifest_for_crate_version(&crate_info.name, &version_i1.num, &version_i1.features), "crate_baseline/Cargo.toml")?;
run_checks_on_manifest()?;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this control flow through the ? operators, won't all this immediately break as soon as some crate fails to build and generate rustdoc? This happens in a noticeable fraction of all crates, due to things like missing binary dependencies for example, and I think we want to catch and report that error rather than stopping the entire run over it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. When the script will work I'll rewrite this part to log an appropriate information and skip this particular crate.

@@ -0,0 +1,13 @@
[package]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to put an entire crate in scripts. Future maintainers of this project would find that very confusing, and it's not in line with how Rust projects tend to be structured. Consider moving the crate into its own top-level directory.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you suggest a good name for the crate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe check-semver-of-registry-crates?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps registry-semver-scanner? Or, a different direction, semver-crater as a riff on crater, the tool that tests new Rust releases against all registry crates?

check-semver-of-registry-crates is a bit long, especially for something we may need to type in.

Also, depending on the discussion in #86, you may be able to move this to src/bin/ and configure the Cargo.toml to gate this code behind a new unstable feature.

scripts/run_on_popular_crates/src/main.rs Outdated Show resolved Hide resolved
@tonowak tonowak force-pushed the script_run_on_popular_crates branch from cc007c8 to ca77a4b Compare February 9, 2023 09:25
@tonowak
Copy link
Collaborator Author

tonowak commented Feb 9, 2023

This PR is now stacked on #314.

(damn, I made a mess with the big list of commits, ugh rebases)

Comment on lines 16 to 45
let mut filtered: Vec<Version> = vec![versions
.first()
.expect("received empty list of versions")
.clone()];
filtered.extend(versions.windows(3).filter_map(|vec| {
let mut iter = vec.iter();
let version_v0 = semver::Version::parse(&iter.next().unwrap().num).unwrap();
let v1 = iter.next().unwrap();
let version_v2 = semver::Version::parse(&iter.next().unwrap().num).unwrap();
assert!(iter.next().is_none());

let keep_middle = match self {
Self::CheckAllReleases => true,
Self::SkipAdjacentPatches => {
version_v0.major != version_v2.major || version_v0.minor != version_v2.minor
}
Self::SkipAdjacentMinor => version_v0.major != version_v2.major,
};
match keep_middle {
true => Some(v1.clone()),
false => None,
}
}));
filtered.push(
versions
.last()
.expect("received empty list of versions")
.clone(),
);
filtered
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't deny -- this code is ugly as hell. But it works. And I don't really have any ideas on how to make it nicer.

@tonowak
Copy link
Collaborator Author

tonowak commented Feb 9, 2023

The CLI needs some polishing, but I'm not experienced in stuff like that -- @obi1kenobi can you review it?

I'm thinking that semver-crater might be useful not only for data gathering, but also for convincing people that the tool is worthy. The semver-crater allows to easily check whether there has been any issues in the user's crate (just run a single cargo command that install cargo-semver-checks and runs it on all releases of the user's crate) and to show people "look, some popular crates (like clap) had issues, here is how in a single command you can check that it is indeed true and the tool even detects it".

Assuming semver-crater would be used in this manner, we have to think about how to make its CLI convenient to use.

@tonowak tonowak force-pushed the script_run_on_popular_crates branch from 3badf18 to a3a236a Compare March 3, 2023 10:49
Comment on lines 57 to 58
#[arg(short, long)]
crates: Vec<String>,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, how to make it clear that some arguments run the tool on all crates (and then another argument like "crate_count_limit" would be used to tell semver-crater how many crates to check) and some arguments are so that the tool runs only on the selected crates?

@tonowak tonowak force-pushed the script_run_on_popular_crates branch from a3a236a to 5adbdd7 Compare March 26, 2023 18:09
@tonowak tonowak force-pushed the script_run_on_popular_crates branch from 5adbdd7 to 45cc338 Compare March 26, 2023 18:22
@tonowak tonowak force-pushed the script_run_on_popular_crates branch from 45cc338 to 91f7816 Compare March 26, 2023 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants