Skip to content

Commit 09eb536

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 a4b1143 commit 09eb536

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
@@ -732,7 +732,7 @@ fn tar(
732732
.iter()
733733
.map(|ar_file| ar_file.rel_path.clone())
734734
.collect::<Vec<_>>();
735-
let publish_pkg = prepare_for_publish(pkg, ws, &included)?;
735+
let publish_pkg = prepare_for_publish(pkg, ws, Some(&included))?;
736736

737737
let mut uncompressed_size = 0;
738738
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
@@ -2575,7 +2575,7 @@ fn unused_dep_keys(
25752575
pub fn prepare_for_publish(
25762576
me: &Package,
25772577
ws: &Workspace<'_>,
2578-
included: &[PathBuf],
2578+
included: Option<&[PathBuf]>,
25792579
) -> CargoResult<Package> {
25802580
let contents = me.manifest().contents();
25812581
let document = me.manifest().document();
@@ -2612,7 +2612,7 @@ fn prepare_toml_for_publish(
26122612
me: &manifest::TomlManifest,
26132613
ws: &Workspace<'_>,
26142614
package_root: &Path,
2615-
included: &[PathBuf],
2615+
included: Option<&[PathBuf]>,
26162616
) -> CargoResult<manifest::TomlManifest> {
26172617
let gctx = ws.gctx();
26182618

@@ -2629,7 +2629,8 @@ fn prepare_toml_for_publish(
26292629
package.workspace = None;
26302630
if let Some(StringOrBool::String(path)) = &package.build {
26312631
let path = paths::normalize_path(Path::new(path));
2632-
let build = if included.contains(&path) {
2632+
let included = included.map(|i| i.contains(&path)).unwrap_or(true);
2633+
let build = if included {
26332634
let path = path
26342635
.into_os_string()
26352636
.into_string()
@@ -2898,7 +2899,7 @@ fn prepare_toml_for_publish(
28982899

28992900
fn prepare_targets_for_publish(
29002901
targets: Option<&Vec<manifest::TomlTarget>>,
2901-
included: &[PathBuf],
2902+
included: Option<&[PathBuf]>,
29022903
context: &str,
29032904
gctx: &GlobalContext,
29042905
) -> CargoResult<Option<Vec<manifest::TomlTarget>>> {
@@ -2923,19 +2924,21 @@ fn prepare_targets_for_publish(
29232924

29242925
fn prepare_target_for_publish(
29252926
target: &manifest::TomlTarget,
2926-
included: &[PathBuf],
2927+
included: Option<&[PathBuf]>,
29272928
context: &str,
29282929
gctx: &GlobalContext,
29292930
) -> CargoResult<Option<manifest::TomlTarget>> {
29302931
let path = target.path.as_ref().expect("previously resolved");
29312932
let path = normalize_path(&path.0);
2932-
if !included.contains(&path) {
2933-
let name = target.name.as_ref().expect("previously resolved");
2934-
gctx.shell().warn(format!(
2935-
"ignoring {context} `{name}` as `{}` is not included in the published package",
2936-
path.display()
2937-
))?;
2938-
return Ok(None);
2933+
if let Some(included) = included {
2934+
if !included.contains(&path) {
2935+
let name = target.name.as_ref().expect("previously resolved");
2936+
gctx.shell().warn(format!(
2937+
"ignoring {context} `{name}` as `{}` is not included in the published package",
2938+
path.display()
2939+
))?;
2940+
return Ok(None);
2941+
}
29392942
}
29402943

29412944
let mut target = target.clone();

0 commit comments

Comments
 (0)