fix(new): Add to workspace relative to manifest, not current-dir

We were correctly doing this for cases like `cargo new foo` or
`cargo new deeper/than/this/directory/foo` but not `cargo new ../foo`.

This came up when discussing #14501
This commit is contained in:
Ed Page 2024-09-06 09:45:19 -05:00
parent 6a3255c386
commit f8467c641c
3 changed files with 4 additions and 14 deletions

View file

@ -802,7 +802,7 @@ fn mk(gctx: &GlobalContext, opts: &MkOptions<'_>) -> CargoResult<()> {
} }
} }
let manifest_path = path.join("Cargo.toml"); let manifest_path = paths::normalize_path(&path.join("Cargo.toml"));
if let Ok(root_manifest_path) = find_root_manifest_for_wd(&manifest_path) { if let Ok(root_manifest_path) = find_root_manifest_for_wd(&manifest_path) {
let root_manifest = paths::read(&root_manifest_path)?; let root_manifest = paths::read(&root_manifest_path)?;
// Sometimes the root manifest is not a valid manifest, so we only try to parse it if it is. // Sometimes the root manifest is not a valid manifest, so we only try to parse it if it is.

View file

@ -1,5 +1,4 @@
[workspace] [workspace]
members = ["../out-of-workspace"]
[package] [package]
name = "foo" name = "foo"

View file

@ -1,10 +1,9 @@
<svg width="1902px" height="146px" xmlns="http://www.w3.org/2000/svg"> <svg width="970px" height="74px" xmlns="http://www.w3.org/2000/svg">
<style> <style>
.fg { fill: #AAAAAA } .fg { fill: #AAAAAA }
.bg { background: #000000 } .bg { background: #000000 }
.fg-cyan { fill: #00AAAA } .fg-cyan { fill: #00AAAA }
.fg-green { fill: #00AA00 } .fg-green { fill: #00AA00 }
.fg-yellow { fill: #AA5500 }
.container { .container {
padding: 0 10px; padding: 0 10px;
line-height: 18px; line-height: 18px;
@ -22,17 +21,9 @@
<text xml:space="preserve" class="container fg"> <text xml:space="preserve" class="container fg">
<tspan x="10px" y="28px"><tspan class="fg-green bold"> Creating</tspan><tspan> library `out-of-workspace` package</tspan> <tspan x="10px" y="28px"><tspan class="fg-green bold"> Creating</tspan><tspan> library `out-of-workspace` package</tspan>
</tspan> </tspan>
<tspan x="10px" y="46px"><tspan class="fg-green bold"> Adding</tspan><tspan> `out-of-workspace` as member of workspace at `[ROOT]/case/workspace`</tspan> <tspan x="10px" y="46px"><tspan class="fg-cyan bold">note</tspan><tspan class="bold">:</tspan><tspan> see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html</tspan>
</tspan> </tspan>
<tspan x="10px" y="64px"><tspan class="fg-yellow bold">warning</tspan><tspan class="bold">:</tspan><tspan> compiling this new package may not work due to invalid workspace configuration</tspan> <tspan x="10px" y="64px">
</tspan>
<tspan x="10px" y="82px">
</tspan>
<tspan x="10px" y="100px"><tspan>workspace member `[ROOT]/case/out-of-workspace/Cargo.toml` is not hierarchically below the workspace root `[ROOT]/case/workspace/Cargo.toml`</tspan>
</tspan>
<tspan x="10px" y="118px"><tspan class="fg-cyan bold">note</tspan><tspan class="bold">:</tspan><tspan> see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html</tspan>
</tspan>
<tspan x="10px" y="136px">
</tspan> </tspan>
</text> </text>

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1,003 B