-
-
Notifications
You must be signed in to change notification settings - Fork 834
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
Added dx clean
stats
#2934
base: main
Are you sure you want to change the base?
Added dx clean
stats
#2934
Conversation
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.
Looks great! 👍
Something I'm curious about here is maybe directly checking the folder sizes before and after a clean instead of parsing? 🤔 Just in case cargo changes its format or etc
Just a couple ideas I had poking around:
// Maybe add optional LockOptions argument? | ||
pub fn new(target: &TargetArgs) -> Result<Self, CrateConfigError> { | ||
// Use this struct in new/init subcommands? | ||
let mut cmd = Cmd::new(); | ||
cmd.lock_opts(LockOptions { | ||
offline: true, // Don't access Internet when `dx clean` is run. | ||
frozen: false, | ||
locked: false, | ||
}); | ||
cmd.features(target.features.clone()); | ||
let builder = krates::Builder::new(); | ||
// Tries to access Internet when offline. | ||
let krates = builder.build(cmd, |_| {})?; | ||
let package = find_main_package(target.package.clone(), &krates)?; |
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.
Is this necessary here? I'm not sure cargo clean
will attempt to access the internet, but I'm definitely not sure
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.
It wouldn't have been there if I didn't try calling dx clean
on a place with no Internet connection. It was failing for some reason. That was the reason. I was thinking that this should be a separate issue. But I'm not sure. I think a global --offline
(and others) flag should be added, and it should be enabled by default for clean
subcommand.
So it's necessary if you are offline and want to just clean up the project dir. But an additional if statement is missing.
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.
Ohh ok that does sound like a great idea 👍 I’ll see if I can reproduce that error, that definitely sounds like the right fix
Yes, but if you consider that the project can have a giant directory or is in a workspace or something, this can lead to a longer clean up time. But in the happy case, this is definitely one of the easiest things to do. Directly checking this makes sure that we don't spend any extra time evaluating the size that will be removed. Since Rust apps are supposed to be fast, I think we can trade a bit of more verbose clean up code for maximum performance. But again, if only |
It looks like it is indeed only ever removes the target dir and nothing else. But you can configure in more ways than I thought: https://doc.rust-lang.org/cargo/guide/build-cache.html. I'm not sure if looking for |
Now the command shows this:
Because of that same file that is being added at the top of the function call. You can't get 0 files and bytes. But at least now everything is counted manually and precisely. But I noticed that there is also 5 spaces on the left (or maybe a tab) in the |
d2a296e
to
bf3064e
Compare
#2788 (comment):
Currently, I just naively parsed the output of
cargo clean
and then summed it with Dioxus-specific cleanings.DioxusCrate::new()
uses Internet connection when usingdx clean
DioxusCrate::new()
also creates a 1.7 KiB JSON file every single time, can't we eliminate that? This will probably fail if there's no available space.clean
subcommand must remove, not add.Doescargo clean
only remove the${CARGO_TARGET_DIR:-target}
? If so, then I can directly grab its size, which will eliminate string parsing and the call tocargo clean
(optionally).Currently, can only print the total removed size, but not the total number of files removed.Need to create 2 static hashmaps by usingonce_cell
(can be removed if MSRV is 1.80, IIRC).