From 8b9ef3fec060927deaa57c67191a01e036d8b825 Mon Sep 17 00:00:00 2001 From: Soc Virnyl Estela Date: Fri, 17 Nov 2023 13:48:09 +0800 Subject: [PATCH] fix: sometimes lockfiles can't be found Lockfiles are weird. The behavior is to generate the lockfile at the parent dir of the `--manifest-path` parameter of `cargo vendor`, and NOT where `cargo vendor` was invoked. If it is a subcrate that is part of a workspace, the lockfile is regenerated from where the workspace manifest is. For now we do a simple logic to get the lockfile path. In the future, a big maybe, we will check if a sub project's manifest file is part of a workspace so in that way, we can determine where the lockfile is Signed-off-by: Soc Virnyl Estela --- cargo/src/utils/mod.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/cargo/src/utils/mod.rs b/cargo/src/utils/mod.rs index b71a317..2809c4d 100644 --- a/cargo/src/utils/mod.rs +++ b/cargo/src/utils/mod.rs @@ -87,8 +87,28 @@ pub fn process_src(args: &Opts, prjdir: &Path) -> Result<(), OBSCargoError> { // Setup some common paths we'll use from here out. let outdir = args.outdir.to_owned(); - let cargo_lock = prjdir.join("Cargo.lock"); - // let cargo_config = prjdir.join("cargo_config"); + let first_manifest_parent_path = first_manifest.parent(); + + // Lockfiles are weird. The behavior is to generate + // the lockfile at the parent dir of the `--manifest-path` + // parameter of `cargo vendor`, and NOT where `cargo vendor` + // was invoked. If it is a subcrate that is part of a workspace, + // the lockfile is regenerated from where the workspace + // manifest is. + // WARN For now we do a simple logic to get the lockfile path. + // TODO Check if a manifest file is part of a workspace + // so in that way, we can determine where the lockfile is + let cargo_lock = match first_manifest_parent_path { + Some(custom_path) => { + let lockfilepath = custom_path.join("Cargo.lock"); + if lockfilepath.exists() { + lockfilepath + } else { + prjdir.join("Cargo.lock") + } + } + None => prjdir.join("Cargo.lock"), + }; let cargo_config = prjdir.join(".cargo/config"); let vendor_dir = prjdir.join("vendor"); let update = args.update;