Skip to content

Commit 37c3080

Browse files
committed
refactor(toml): Move path processing out of convert_toml
This is in an effort to remove `convert_toml`
1 parent ff454fd commit 37c3080

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/cargo/ops/cargo_package.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,9 @@ fn build_lock(ws: &Workspace<'_>, orig_pkg: &Package) -> CargoResult<String> {
455455
// Convert Package -> TomlManifest -> Manifest -> Package
456456
let toml_manifest =
457457
prepare_for_publish(orig_pkg.manifest().resolved_toml(), ws, orig_pkg.root())?;
458-
let package_root = orig_pkg.root();
459458
let source_id = orig_pkg.package_id().source_id();
460459
let (manifest, _nested_paths) =
461-
to_real_manifest(toml_manifest, false, source_id, package_root, gctx)?;
460+
to_real_manifest(toml_manifest, source_id, orig_pkg.manifest_path(), gctx)?;
462461
let new_pkg = Package::new(manifest, orig_pkg.manifest_path());
463462

464463
// Regenerate Cargo.lock using the old one as a guide.

src/cargo/util/toml/mod.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ fn convert_toml(
175175
source_id: SourceId,
176176
gctx: &GlobalContext,
177177
) -> CargoResult<(EitherManifest, Vec<PathBuf>)> {
178-
let package_root = manifest_file.parent().unwrap();
179-
180178
if let Some(deps) = manifest
181179
.workspace
182180
.as_ref()
@@ -192,12 +190,10 @@ fn convert_toml(
192190
}
193191
}
194192
return if manifest.package().is_some() {
195-
let embedded = is_embedded(manifest_file);
196-
let (manifest, paths) =
197-
to_real_manifest(manifest, embedded, source_id, package_root, gctx)?;
193+
let (manifest, paths) = to_real_manifest(manifest, source_id, manifest_file, gctx)?;
198194
Ok((EitherManifest::Real(manifest), paths))
199195
} else {
200-
let (m, paths) = to_virtual_manifest(manifest, source_id, package_root, gctx)?;
196+
let (m, paths) = to_virtual_manifest(manifest, source_id, manifest_file, gctx)?;
201197
Ok((EitherManifest::Virtual(m), paths))
202198
};
203199
}
@@ -479,9 +475,8 @@ pub fn prepare_for_publish(
479475
#[tracing::instrument(skip_all)]
480476
pub fn to_real_manifest(
481477
me: manifest::TomlManifest,
482-
embedded: bool,
483478
source_id: SourceId,
484-
package_root: &Path,
479+
manifest_file: &Path,
485480
gctx: &GlobalContext,
486481
) -> CargoResult<(Manifest, Vec<PathBuf>)> {
487482
fn get_ws(
@@ -511,6 +506,8 @@ pub fn to_real_manifest(
511506
}
512507
}
513508

509+
let embedded = is_embedded(manifest_file);
510+
let package_root = manifest_file.parent().unwrap();
514511
if !package_root.is_dir() {
515512
bail!(
516513
"package root '{}' is not a directory",
@@ -1280,9 +1277,11 @@ pub fn to_real_manifest(
12801277
fn to_virtual_manifest(
12811278
me: manifest::TomlManifest,
12821279
source_id: SourceId,
1283-
root: &Path,
1280+
manifest_file: &Path,
12841281
gctx: &GlobalContext,
12851282
) -> CargoResult<(VirtualManifest, Vec<PathBuf>)> {
1283+
let root = manifest_file.parent().unwrap();
1284+
12861285
for field in me.requires_package() {
12871286
bail!("this virtual manifest specifies a `{field}` section, which is not allowed");
12881287
}

0 commit comments

Comments
 (0)