-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Warn about cargo publish
with git submodules not checked out
#8635
Comments
Tagging as |
Hi, I am trying to debug this problem. Are you possibly referring to this snippet here? It seems to have already checked for dirty submodules but maybe the logic is flawed? cargo/src/cargo/ops/cargo_package.rs Lines 394 to 456 in 51b6612
In particular, it will perform the submodule check iff this match fails cargo/src/cargo/ops/cargo_package.rs Line 422 in 51b6612
And I dont quite understand how git internally works... Edit: Also, do you have a project where I can reproduce this by changing one of its submodule? I tried creating a dummy project with a submodule but it does not work? Specifically, the submodule's source code is not included in here cargo/src/cargo/ops/cargo_package.rs Line 89 in 51b6612
|
@hbina The issue is this snippet: cargo/src/cargo/ops/cargo_package.rs Lines 464 to 469 in 868a1cf
The comment there is somewhat incorrect. Some projects are structured in such a way that even the verification step won't fail if the files are missing. For example, some C library bindings may use the system library by default, and only use the local code (which is often included via a git submodule) when a certain feature is enabled. The intent of this issue is that call to There are several projects you can try that have a submodule. Some examples:
These should all fail if the submodule has not been initialized. |
It's not too complicated, but I don't think that there is any function available to get the answer easily. I'm not sure, but I think the best approach would be to test the submodule path against the I would create the |
Thanks, I will try this. |
@ehuss Is this still an issue? If yes, I'd like to tackle it. I fee this is a good issue to get started to contribute. |
Yea, sure! This may not be terribly easy, but the comments above should be a guide on where to get started. |
I looked into this more closely and it turns out it is unfortunately not as straight forward as running the submodule path against the include and exclude list. The include list could look like: I don't see a way to resolve this problem. For the general case there is simply no way to know whether there is something in the submodule that is needed for the package build. What is your oppinion @ehuss? Might a better solution for example be to print a warning that a not initialized submodule was encountered? |
Hm, good point! Thinking about this some more, there are a couple different issues:
Does that sound feasible? I haven't looked at how that could be implemented, but I'm guessing it shouldn't be too hard to check if the submodule path is under the package directory, and check if the submodule is initialized. |
@rustbot claim |
I ran into an issue, where I manually merged a PR for a project of mine, but forgot to also update the git submodule. I published a new version of the crate to crates.io, and cargo publish did not complain about the dirty submodule, although it was shown as such in git status. |
I think this can happen quite easily, when one is not aware of this problem, and simply trusts cargo publish. Imagine someone pushing a security update for a crate, which just updates a submodule dependency. Unfixed security issue on crates.io, and nobody notices. Especially since I do not know a way to check the actual source on crates.io. I usually just check the referenced repository, only sometimes do I bother to lookup the crate source code in my ~/.cargo folder. |
It seems that if a git submodule is not properly initialize on the machine that will publish the crate, cargo won't warn or detect it, as described in this issue rust-lang/cargo#8635. This is hard to detect because the CI is setup to properly `git clone --recursive` and therefore should not detect this issue. To reduce the likelyhood of #23 from happening again in the future, the `testcrate` was added as a dev-dedependecy to the root crate and the tests were moved to the root crate so that if `cargo test` is ran (even without the --workspace flag), the tests won't compile and the error should be detected.
I've managed to publish crates without checking out the git submodules first, and I've seen others do the same. Could cargo publish check if you have a git submodule but don't have it checked out?
As an added bonus, we could only check that if the submodule isn't excluded (or not-included) from the published crate, but that isn't necessary for a first implementation since you can always run
cargo publish --allow-dirty
.The text was updated successfully, but these errors were encountered: