-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
cargo clean -p package can clear the document of a single crates #9841
Closed
Closed
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dda851a
fix cargo clean -p package
heisen-li 766d38a
clean target/doc/package and target/doc/src/package
heisen-li 301796b
Merge branch 'master' into clean_p_1
heisen-li d17424d
add test
heisen-li bc95702
Merge branch 'clean_p_1' of https://github.com/QiangHeisenberg/cargo …
heisen-li fdae0ec
Merge branch 'master' of https://github.com/rust-lang/cargo into clea…
heisen-li e7a005d
fix clean and add test
heisen-li 0aff251
Narrow the deletion scope
heisen-li adeadcc
Merge branch 'master' into clean_p_1
heisen-li bb78c7a
fmt
heisen-li 950aa4f
fmt
heisen-li a2ded66
use ws.is_member(pkg)
heisen-li 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 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 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 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.
This isn't using the correct name here. The directory names are the crate names of the targets. I'm uncertain about the best way to handle this, but specifically:
pkg.library().map(|t| t.crate_name())
. I think it could be dangerous to blindly remove directories for other targets like "examples" because there could be name collisions (for example, if something has an example called "serde", it would delete the serde directory, which is probably not what you want).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.
I'm sorry, I don't quite understand your question. Could you explain it again?
I'm sorry. I really didn't think of the question in advance. If the example name in the ../examples/ folder is the same as another crate name, this should be taken into account.
Also, I'm not sure I understood this correctly: Is the current question the same as you stated above (about the example name conflicts with the crate name)?
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.
Yea, both points are related to one another.
The doc directories are based on a target's crate name. So, for example, if I have a package named "foo" with a "foo" library and a "foo-cli" binary, there would be two directories:
doc/foo
doc/foo_cli
To clean this properly, it would need to iterate over all documentable targets and get their crate names. Don't forget that the package name, the target name, and the crate name can all be different. That is, package "abc-rs" can have a library named "my-abc-lib" which has a crate name of "my_abc_lib".
However, I'd be concerned about indiscriminately iterating over a package's targets because of name collisions. Imagine my "foo" library had a dependency on "serde", and a dependency on another package named "bar". I run
cargo doc
and also get the documentation fordoc/foo
,doc/serde
, anddoc/bar
. Now, imaginebar
had an binary coincidentally namedserde
, if a user runscargo clean -p bar
, we don't want to blow away the serde directory just becausebar
had aserde
binary.So, I'm thinking, to avoid deleting the wrong things, one step would be to only look for library targets of non-workspace dependencies. That should limit the collateral damage.
Then, I'm wondering about limiting the collateral damage of workspace members, too. Perhaps including examples is overkill, and perhaps it should only delete library crate names? Or maybe libraries + binaries? Or maybe it is fine to collect all targets with
documented()
istrue
. That's where I'm uncertain, since I'm not really sure I understand the need for this functionality.I think I would lean towards just deleting the entries from
pkg.targets().iter().filter(|t| t.documented())
for workspace members, and just the lib for non-members.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.
I need some time to think, please give me some time. i am sorry, huss.
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.
No worries, feel free to take your time, there's no rush. And let me know if you have any questions or if anything wasn't clear.
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.
Sorry, I just ended my wedding leave. It was too late to reply.
This scenario was tested based on my understanding.
The directory after
cargo doc
looks like this:The binary files of
serde
andbar
seem to have nothing to do with each other. In other words, the binary files under thebar
directory will not form a document.Therefore, running
cargo clean -p bar
only needs to deletedoc/bar
, and does not need to consider the conflict between theserde
binary file underbar
and the dependentserde
offoo
.Is my understanding correct?
My understanding of this function is:
If you execute
cargo clean -p foo
, you need to delete alldoc/foo
,doc/example_name
,doc/dependence_name
.And these documents are in
pkg.targets().iter().filter(|t| t.documented())
.What does
workspace member
mean here?Is this in
Cargo.toml
?Frankly, I don't seem to fully understand
workspace members
andlib for non-members
.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.
Essentially, yea, it is the
members
list. It's a little more complicated, since additional members can be inferred.I think my question was: why does someone want to delete directories from the
doc
directory? What is the drawback of leaving them there? What is the use case for needing to delete them? Is it OK for it to only partially delete a package's data?I think what I'm trying to get at is that when you document a package, it documents the libraries and its binaries. If you have a package
mypackage
with binariesbar
andbaz
, there will be three directories in thedoc
directory. To properly cleanmypackage
, it will need to iterate over all documentable targets and delete those directories. My concern is that could be too aggressive in some cases, as it could delete too much.When
cargo doc
is run, it will document all documentable targets for workspace members, and all libraries for non-workspace members.So my thought is that it would look for
pkg.targets().iter().filter(|t| t.documented())
for workspace members, andpkg.targets().iter().find(|t| t.is_lib())
for non-members maybe?