Gotcha using `workspace-dotted` without specifying a version
Closed this issue · 2 comments
Setup
My hakari.toml
has:
workspace-hack-line-style = "workspace-dotted"
My root Cargo.toml
has:
[workspace.dependencies]
my-workspace-hack = { path = "/path/to/my-workspace-hack" }
After initial setup (generate
then manage-deps
) all workspace packages have the following added as expected:
[dependencies]
my-workspace-hack.workspace = true
Issue
Later, when re-running cargo hakari manage-deps
(or running cargo hakari --dry-run --quiet
in CI), hakari
reports that many packages are missing the my-workspace-hack
dependency and attempts to add them again (or fail in the case of the CI job).
I debugged this and discovered the error, namely that the workspace dependency must specify a version as well as a path, i.e.:
[workspace.dependencies]
my-workspace-hack = { version = "0.1.0", path = "/path/to/my-workspace-hack" }
I traced this to the following code, which in my case always hits the first else clause (link.version_req() == &VersionReq::STAR
) when the hakari
package has no version:
guppy/tools/hakari/src/cli_ops/manage_deps.rs
Lines 153 to 164 in 07c17f9
So whilst this is not a bug, it is a gotcha and the cause is non-obvious (I had to step through in the debugger). Perhaps something could be added to surface this (likely not what the user intended) behaviour more directly? Perhaps running without an given version should be an explicit opt-in?
Documentation
The documentation does talk about this to an extent, though in a different context (I skipped reading the section initially as it did not apply to my circumstances).
It say (emphasis mine):
This option lets you specify the path to the workspace-hack crate, once, in the root Cargo.toml
And then shows an example where only the version
is given:
[workspace.dependencies]
my-workspace-hack = "0.1.0" # or another version number if you've changed it
So perhaps the need to specify the version could be made more prominent in the documentation?
Thanks, good catch! I think we can update the check to not require that the version be specified -- I don't think there's a particular reason to require it unless the crate is being published.
This is now out in cargo-hakari 0.9.30.