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

Make default output less noisy #81

Merged
merged 7 commits into from
Dec 26, 2022

Conversation

marcospb19
Copy link
Collaborator

@marcospb19 marcospb19 commented Dec 25, 2022

Fixes #74.

cargo-sweep logs every deleted file, this makes the output
very noisy and hard to follow (outputs approximately a thousand
lines per cleaned project).

This PR changes the default output to omit deleted files, and
only show them with the --verbose flag.

@marcospb19
Copy link
Collaborator Author

PR is a draft because this is the remaining output after the changes:

[INFO] Cleaned 5.34 GiB
[INFO] Using all installed toolchains: ["stable-2022-09-22-x86_64-unknown-linux-
gnu", "stable-x86_64-unknown-linux-gnu", "nightly-2022-06-20-x86_64-unknown-linu
x-gnu", "nightly-2022-08-06-x86_64-unknown-linux-gnu", "nightly-x86_64-unknown-l
inux-gnu", "1.63.0-x86_64-unknown-linux-gnu", "1.64.0-x86_64-unknown-linux-gnu"]

So now you don't know what project was cleaned.

@marcospb19
Copy link
Collaborator Author

The list of installed toolchains is shown for every project it sweeps, but I think it is always the same.

So we should probably just show it once at the start.

This is the function that loads the toolchains:

fn rustup_toolchain_list() -> Option<Vec<String>> {
let out = Command::new("rustup").args(["toolchain", "list"]).output();

It's always constant, because it calls the rustup binary, I think we can assume the binary doesn't change (also, cargo sweep nevers cd into other directory).

@marcospb19 marcospb19 force-pushed the make-default-output-less-noisy branch 2 times, most recently from 68271d3 to ccebf4b Compare December 25, 2022 20:01
@marcospb19 marcospb19 marked this pull request as ready for review December 25, 2022 20:01
@marcospb19
Copy link
Collaborator Author

Should be ready for review now, fixing the list of toolchains being outputted repeatedly will require a little bit of refactoring, so I prefer doing it in another PR.

@marcospb19
Copy link
Collaborator Author

Sorry I had to force push again, cargo clippy --fix broke a test.

@jyn514
Copy link
Collaborator

jyn514 commented Dec 25, 2022

I just fixed the clippy warnings in #80 (and made a couple other changes that should make the errors easier to read) - do you mind rebasing over master?

Also, please revert the changes to the assertion message, like the error says they don't do what you expect in 2018 edition and I would prefer to switch the edition in a separate PR (edit: done #83).

@marcospb19
Copy link
Collaborator Author

Oh ok, I'll do that, I was having a lot of trouble with the assertion message, so I force pushed like 5 times, let me fix it.

by logging the list of deleted files on the 'Debug' log level, requiring
the user to provide the --verbose flag to see it

previously, this list was logged to the 'Info' log level
tests/integration.rs Outdated Show resolved Hide resolved
@jyn514
Copy link
Collaborator

jyn514 commented Dec 25, 2022

Do you mind adding a test showing the new output? Comparing run(sweep(&["--maxsize", "0"])).get_output().stdout to some string would be ideal; I guess it's annoying because it hashes in the name but maybe you can normalize those?

@marcospb19 marcospb19 marked this pull request as draft December 26, 2022 01:44
tests/integration.rs Outdated Show resolved Hide resolved
now it requires a target directory to which cargo-sweep will try to
perform the cleaning
@marcospb19 marcospb19 marked this pull request as ready for review December 26, 2022 17:12
Comment on lines 215 to 231
let pattern = unindent(&format!(
r#"\[DEBUG\] cleaning: "/tmp/{regex_skip}" with remove_older_until_fits
\[DEBUG\] size_to_remove: {regex_skip}
\[DEBUG\] Sizing: "/tmp/{regex_skip}/debug" with total_disk_space_in_a_profile
\[DEBUG\] Hashs by time: \[
\(
{regex_skip},
"{regex_skip}",
\),
\]
\[DEBUG\] cleaning: "/tmp/{regex_skip}/debug" with remove_not_built_with_in_a_profile
\[DEBUG\] Successfully removed: "/tmp/{regex_skip}/debug/deps/libsample_project-{regex_skip}.rlib"
\[DEBUG\] Successfully removed: "/tmp/{regex_skip}/debug/deps/libsample_project-{regex_skip}.rmeta"
\[DEBUG\] Successfully removed: "/tmp/{regex_skip}/debug/deps/sample_project-{regex_skip}.d"
\[DEBUG\] Successfully removed: "/tmp/{regex_skip}/debug/.fingerprint/sample-project-{regex_skip}"
\[INFO\] Cleaned {regex_skip} from "/tmp/{regex_skip}""#,
));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This does work, but if the test fails, it doesn't give any tips on what changed, I'm not sure if it's a great approach.

Copy link
Collaborator Author

@marcospb19 marcospb19 Dec 26, 2022

Choose a reason for hiding this comment

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

For reference, here's the output we are matching:

[DEBUG] cleaning: "/tmp/.tmpXhoLjT" with remove_older_until_fits
[DEBUG] size_to_remove: 46978
[DEBUG] Sizing: "/tmp/.tmpXhoLjT/debug" with total_disk_space_in_a_profile
[DEBUG] Hashs by time: [
    (
        13.926894ms,
        "261b05c2354104eb",
    ),
]
[DEBUG] cleaning: "/tmp/.tmpXhoLjT/debug" with remove_not_built_with_in_a_profile
[DEBUG] Successfully removed: "/tmp/.tmpXhoLjT/debug/deps/libsample_project-261b05c2354104eb.rlib"
[DEBUG] Successfully removed: "/tmp/.tmpXhoLjT/debug/deps/libsample_project-261b05c2354104eb.rmeta"
[DEBUG] Successfully removed: "/tmp/.tmpXhoLjT/debug/deps/sample_project-261b05c2354104eb.d"
[DEBUG] Successfully removed: "/tmp/.tmpXhoLjT/debug/.fingerprint/sample-project-261b05c2354104eb"
[INFO] Cleaned 9.43 KiB from "/tmp/.tmpXhoLjT"

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's ok; if you run the test with --nocapture it will show the original output.


let output = std::str::from_utf8(&assert.get_output().stdout).unwrap();

let regex_skip = r#".+?"#;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this can just be .* instead of needing to make it optional; and at that point I think it would be simpler to inline it instead of using format.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Aha! A regex Gotcha.

Fun fact: Inserting an ? after a quantifier (*, +, ? or {N..M}) switches
to non-greedy matching, which can be good for performance as it decreases
excessive backtracking from the usual greedy eater.

(It's the same symbol to make stuff optional... why...)

Well, that's a tiny text to match so I'll switch to .+ anyways 👍.

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 do think this is a bit less readable from the editor, but the GitHub diff doesn't highlight the format placeholder.

image

image

Copy link
Collaborator

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

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

Thanks! Happy to merge this with the last nit fixed :)

tests/integration.rs Outdated Show resolved Hide resolved
@marcospb19
Copy link
Collaborator Author

Now it's failing because of Windows paths

"C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\.tmpBWHDFH\\debug\\.fingerprint\\

@marcospb19
Copy link
Collaborator Author

Fixed, if you want I can squash the last (one or two) commits.

@jyn514
Copy link
Collaborator

jyn514 commented Dec 26, 2022

Thanks for sticking with this!

@jyn514 jyn514 merged commit fd4dc55 into holmgr:master Dec 26, 2022
@marcospb19 marcospb19 deleted the make-default-output-less-noisy branch December 26, 2022 21:54
@marcospb19 marcospb19 mentioned this pull request Feb 4, 2023
@marcospb19 marcospb19 mentioned this pull request Sep 12, 2023
@marcospb19 marcospb19 mentioned this pull request Oct 5, 2023
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.

Make the default output less noisy
2 participants