Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 718b68b

Browse files
committedSep 5, 2024·
Implement path-bases (RFC 3529) 2/n: cargo add support
RFC: rust-lang/rfcs#3529 Tracking Issue: #14355 This PR adds the `--base` option to `cargo add` to allow adding a path dependency with a path base.
1 parent 2f15e64 commit 718b68b

File tree

69 files changed

+1008
-110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1008
-110
lines changed
 

‎src/bin/cargo/commands/add.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ Example uses:
101101
.help("Filesystem path to local crate to add")
102102
.group("selected")
103103
.conflicts_with("git"),
104+
clap::Arg::new("base")
105+
.long("base")
106+
.action(ArgAction::Set)
107+
.value_name("BASE")
108+
.help("The path base to use when adding from a local crate (unstable).")
109+
.requires("path"),
104110
clap::Arg::new("git")
105111
.long("git")
106112
.action(ArgAction::Set)
@@ -224,6 +230,7 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
224230

225231
fn parse_dependencies(gctx: &GlobalContext, matches: &ArgMatches) -> CargoResult<Vec<DepOp>> {
226232
let path = matches.get_one::<String>("path");
233+
let base = matches.get_one::<String>("base");
227234
let git = matches.get_one::<String>("git");
228235
let branch = matches.get_one::<String>("branch");
229236
let rev = matches.get_one::<String>("rev");
@@ -329,6 +336,7 @@ fn parse_dependencies(gctx: &GlobalContext, matches: &ArgMatches) -> CargoResult
329336
public,
330337
registry: registry.clone(),
331338
path: path.map(String::from),
339+
base: base.map(String::from),
332340
git: git.map(String::from),
333341
branch: branch.map(String::from),
334342
rev: rev.map(String::from),

‎src/bin/cargo/commands/remove.rs

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,37 @@ fn gc_workspace(workspace: &Workspace<'_>) -> CargoResult<()> {
167167

168168
let members = workspace
169169
.members()
170-
.map(|p| LocalManifest::try_new(p.manifest_path()))
170+
.map(|p| {
171+
Ok((
172+
LocalManifest::try_new(p.manifest_path())?,
173+
p.manifest().unstable_features(),
174+
))
175+
})
171176
.collect::<CargoResult<Vec<_>>>()?;
172177

173178
let mut dependencies = members
174-
.iter()
175-
.flat_map(|manifest| {
176-
manifest.get_sections().into_iter().flat_map(|(_, table)| {
177-
table
178-
.as_table_like()
179-
.unwrap()
180-
.iter()
181-
.map(|(key, item)| Dependency::from_toml(&manifest.path, key, item))
182-
.collect::<Vec<_>>()
183-
})
179+
.into_iter()
180+
.flat_map(|(manifest, unstable_features)| {
181+
manifest
182+
.get_sections()
183+
.into_iter()
184+
.flat_map(move |(_, table)| {
185+
table
186+
.as_table_like()
187+
.unwrap()
188+
.iter()
189+
.map(|(key, item)| {
190+
Dependency::from_toml(
191+
workspace.gctx(),
192+
workspace.root(),
193+
&manifest.path,
194+
&unstable_features,
195+
key,
196+
item,
197+
)
198+
})
199+
.collect::<Vec<_>>()
200+
})
184201
})
185202
.collect::<CargoResult<Vec<_>>>()?;
186203

@@ -192,7 +209,14 @@ fn gc_workspace(workspace: &Workspace<'_>) -> CargoResult<()> {
192209
{
193210
deps_table.set_implicit(true);
194211
for (key, item) in deps_table.iter_mut() {
195-
let ws_dep = Dependency::from_toml(&workspace.root(), key.get(), item)?;
212+
let ws_dep = Dependency::from_toml(
213+
workspace.gctx(),
214+
workspace.root(),
215+
&workspace.root(),
216+
workspace.unstable_features(),
217+
key.get(),
218+
item,
219+
)?;
196220

197221
// search for uses of this workspace dependency
198222
let mut is_used = false;
@@ -329,7 +353,14 @@ fn gc_unused_patches(workspace: &Workspace<'_>, resolve: &Resolve) -> CargoResul
329353
patch_table.set_implicit(true);
330354

331355
for (key, item) in patch_table.iter_mut() {
332-
let dep = Dependency::from_toml(&workspace.root_manifest(), key.get(), item)?;
356+
let dep = Dependency::from_toml(
357+
workspace.gctx(),
358+
workspace.root(),
359+
&workspace.root_manifest(),
360+
workspace.unstable_features(),
361+
key.get(),
362+
item,
363+
)?;
333364

334365
// Generate a PackageIdSpec url for querying
335366
let url = if let MaybeWorkspace::Other(source_id) =

0 commit comments

Comments
 (0)
Please sign in to comment.