-
Notifications
You must be signed in to change notification settings - Fork 6
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
Use $PWD
and --manifest-path
to select a default package in workspaces
#25
Conversation
2b8ac40
to
d227346
Compare
pub struct Workspace { | ||
#[serde(default)] | ||
pub default_members: Vec<String>, |
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.
Should start using this too.
3034a40
to
29f28ea
Compare
d7f35e7
to
68b8a09
Compare
is libraryfication of cargo ever going to happen? I really whish we didn't have to rebuild these components |
No idea, would be cool. Even cooler would be a plugin system, where |
…paces This restores original, prevalent `--manifest-path` usage to select a package containing the APK crate in a `[workspace]`, instead of using `-p` for that.
When calling `.parent()` on a filename the result is `""`, which should be treated as PWD (`"."`) but `dunce::canonicalize()` ends up in a "No such file or directory".
`.ancestors()` only calls `.parent()` on a `Path` which walks up until the string empty, but this isn't the root of the filesystem if the path wasn't absolute.
68b8a09
to
89165f5
Compare
Instead of relying on non-workspace logic.
89165f5
to
2ade565
Compare
src/utils.rs
Outdated
// Find the closest member based on the given path | ||
Ok(path | ||
.ancestors() | ||
// Move manifest out of the HashMap | ||
.find_map(|dir| all_members.remove(dir)) | ||
.unwrap_or_else(|| { | ||
( | ||
workspace_manifest_path.to_owned(), | ||
workspace_manifest.clone(), | ||
) | ||
})) |
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 logic is slightly incomplete as it falls back to the package defined in the workspace (found in xbuild
):
- Even if it doesn't contain a
[package]
(leading to a panic in the outer function that expects this to have been checked already); - When there's a manifest along the way that isn't the workspace, but it is not part of it (this is a proper error in
cargo
).
I'll resolve these in xbuild
first (where an identical setup to this PR has already been merged) and apply the same solution here afterwards.
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.
Fixed here too by replicating rust-mobile/xbuild#93!
I'll probably merge this tonight and push out a new |
The previous implementation had one fatal flaw: having a non-workspace `Cargo.toml` in a subdirectory, with a `[workspace]` defined some directories higher is invalid when that `[workspace]` doesn't include the given `Cargo.toml` subdirectory/package. `cargo` rejects this with a `current package believes it's in a workspace when it's not`, and we should do the same instead of having an `unwrap_or_else` that falls back to using the workspace root `Cargo.toml` as a package (especially if it might not contain a `[package]` at all). This would for example fail when running `x new template` in the repo directory, `cd`'ing into it and invoking `x build`. Instead of complaining about `template/Cargo.toml` not being part of the workspace, it detects the workspace and falls back to building the root package because the `template` directory appears to just be a subdirectory of the root without defining a subpackage along it. Since our root doesn't define a `[package]`, the supposed-to-be-infallible `unwrap()` on `manifest.package` below fails.
f07e2bb
to
9e8401e
Compare
Fixes rust-mobile/cargo-apk#8
This restores original, prevalent
--manifest-path
usage to select a package containing the APK crate in a[workspace]
, instead of using-p
for that.