Skip to content

Commit 53fe2b6

Browse files
committed
refactor(package): Make target filtering optional
We'll be doing a second `prepare_for_publish` call that doesn't need the filtering, we don't have access to the `included`, and we don't want the warnings duplicated.
1 parent 9e730ec commit 53fe2b6

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/cargo/ops/cargo_package.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ fn tar(
893893
.iter()
894894
.map(|ar_file| ar_file.rel_path.clone())
895895
.collect::<Vec<_>>();
896-
let publish_pkg = prepare_for_publish(pkg, ws, &included)?;
896+
let publish_pkg = prepare_for_publish(pkg, ws, Some(&included))?;
897897

898898
let mut uncompressed_size = 0;
899899
for ar_file in ar_files {

src/cargo/util/toml/mod.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2554,7 +2554,7 @@ fn unused_dep_keys(
25542554
pub fn prepare_for_publish(
25552555
me: &Package,
25562556
ws: &Workspace<'_>,
2557-
included: &[PathBuf],
2557+
included: Option<&[PathBuf]>,
25582558
) -> CargoResult<Package> {
25592559
let contents = me.manifest().contents();
25602560
let document = me.manifest().document();
@@ -2591,7 +2591,7 @@ fn prepare_toml_for_publish(
25912591
me: &manifest::TomlManifest,
25922592
ws: &Workspace<'_>,
25932593
package_root: &Path,
2594-
included: &[PathBuf],
2594+
included: Option<&[PathBuf]>,
25952595
) -> CargoResult<manifest::TomlManifest> {
25962596
let gctx = ws.gctx();
25972597

@@ -2608,7 +2608,8 @@ fn prepare_toml_for_publish(
26082608
package.workspace = None;
26092609
if let Some(StringOrBool::String(path)) = &package.build {
26102610
let path = paths::normalize_path(Path::new(path));
2611-
let build = if included.contains(&path) {
2611+
let included = included.map(|i| i.contains(&path)).unwrap_or(true);
2612+
let build = if included {
26122613
let path = path
26132614
.into_os_string()
26142615
.into_string()
@@ -2877,7 +2878,7 @@ fn prepare_toml_for_publish(
28772878

28782879
fn prepare_targets_for_publish(
28792880
targets: Option<&Vec<manifest::TomlTarget>>,
2880-
included: &[PathBuf],
2881+
included: Option<&[PathBuf]>,
28812882
context: &str,
28822883
gctx: &GlobalContext,
28832884
) -> CargoResult<Option<Vec<manifest::TomlTarget>>> {
@@ -2902,19 +2903,21 @@ fn prepare_targets_for_publish(
29022903

29032904
fn prepare_target_for_publish(
29042905
target: &manifest::TomlTarget,
2905-
included: &[PathBuf],
2906+
included: Option<&[PathBuf]>,
29062907
context: &str,
29072908
gctx: &GlobalContext,
29082909
) -> CargoResult<Option<manifest::TomlTarget>> {
29092910
let path = target.path.as_ref().expect("previously resolved");
29102911
let path = normalize_path(&path.0);
2911-
if !included.contains(&path) {
2912-
let name = target.name.as_ref().expect("previously resolved");
2913-
gctx.shell().warn(format!(
2914-
"ignoring {context} `{name}` as `{}` is not included in the published package",
2915-
path.display()
2916-
))?;
2917-
return Ok(None);
2912+
if let Some(included) = included {
2913+
if !included.contains(&path) {
2914+
let name = target.name.as_ref().expect("previously resolved");
2915+
gctx.shell().warn(format!(
2916+
"ignoring {context} `{name}` as `{}` is not included in the published package",
2917+
path.display()
2918+
))?;
2919+
return Ok(None);
2920+
}
29182921
}
29192922

29202923
let mut target = target.clone();

0 commit comments

Comments
 (0)