Skip to content

Commit

Permalink
fix: Normalize the target path
Browse files Browse the repository at this point in the history
  • Loading branch information
linyihai committed Sep 11, 2024
1 parent 71ecce8 commit 9b4515c
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 85 deletions.
31 changes: 24 additions & 7 deletions src/cargo/ops/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::ops;
use crate::sources::path::PathSource;
use crate::sources::CRATES_IO_REGISTRY;
use crate::util::cache_lock::CacheLockMode;
use crate::util::toml::AbsolutePathTomlTarget;
use crate::util::{try_canonicalize, CargoResult, GlobalContext};
use anyhow::{bail, Context as _};
use cargo_util::{paths, Sha256};
Expand Down Expand Up @@ -410,9 +411,13 @@ fn prepare_for_vendor(
) -> CargoResult<Package> {
let contents = me.manifest().contents();
let document = me.manifest().document();
let abs_targets =
crate::util::toml::absolute_normalized_targets(me.manifest().normalized_toml(), me.root())?;
let original_toml = prepare_toml_for_vendor(
me.manifest().normalized_toml().clone(),
packaged_files,
&abs_targets,
me.root(),
gctx,
)?;
let normalized_toml = original_toml.clone();
Expand All @@ -426,10 +431,12 @@ fn prepare_for_vendor(
document.clone(),
original_toml,
normalized_toml,
&abs_targets,
features,
workspace_config,
source_id,
me.manifest_path(),
me.root(),
gctx,
&mut warnings,
&mut errors,
Expand All @@ -441,14 +448,19 @@ fn prepare_for_vendor(
fn prepare_toml_for_vendor(
mut me: cargo_util_schemas::manifest::TomlManifest,
packaged_files: &[PathBuf],
abs_targets: &AbsolutePathTomlTarget,
package_root: &Path,
gctx: &GlobalContext,
) -> CargoResult<cargo_util_schemas::manifest::TomlManifest> {
let package = me
.package
.as_mut()
.expect("venedored manifests must have packages");
if let Some(cargo_util_schemas::manifest::StringOrBool::String(path)) = &package.build {
let path = paths::normalize_path(Path::new(path));
if let Some(path) = &abs_targets.build {
let path = path
.strip_prefix(package_root)
.expect("path shoud be under the package root")
.to_path_buf();
let included = packaged_files.contains(&path);
let build = if included {
let path = path
Expand All @@ -467,37 +479,42 @@ fn prepare_toml_for_vendor(
package.build = Some(build);
}

let lib = if let Some(target) = &me.lib {
let lib = if let Some(target) = &abs_targets.lib {
crate::util::toml::prepare_target_for_publish(
target,
Some(packaged_files),
package_root,
"library",
gctx,
)?
} else {
None
};
let bin = crate::util::toml::prepare_targets_for_publish(
me.bin.as_ref(),
abs_targets.bin.as_ref(),
Some(packaged_files),
package_root,
"binary",
gctx,
)?;
let example = crate::util::toml::prepare_targets_for_publish(
me.example.as_ref(),
abs_targets.example.as_ref(),
Some(packaged_files),
package_root,
"example",
gctx,
)?;
let test = crate::util::toml::prepare_targets_for_publish(
me.test.as_ref(),
abs_targets.test.as_ref(),
Some(packaged_files),
package_root,
"test",
gctx,
)?;
let bench = crate::util::toml::prepare_targets_for_publish(
me.bench.as_ref(),
abs_targets.bench.as_ref(),
Some(packaged_files),
package_root,
"benchmark",
gctx,
)?;
Expand Down
Loading

0 comments on commit 9b4515c

Please sign in to comment.