fix(toml): Warn, rather than fail publish, if targets are excluded

This could offer performance gains when parsing a published
manifest since the targets don't need to be discovered.
To see this, we'd first need to stop discovering potential targets even when it isn't
needed.
This commit is contained in:
Ed Page 2024-04-03 16:52:22 -05:00
parent 1e6047763d
commit 06a57142f1
9 changed files with 500 additions and 90 deletions

View file

@ -264,7 +264,7 @@ fn resolve_toml(
manifest_file: &Path,
gctx: &GlobalContext,
warnings: &mut Vec<String>,
_errors: &mut Vec<String>,
errors: &mut Vec<String>,
) -> CargoResult<manifest::TomlManifest> {
if let Some(workspace) = &original_toml.workspace {
if workspace.resolver.as_deref() == Some("3") {
@ -277,11 +277,11 @@ fn resolve_toml(
package: None,
project: None,
profile: original_toml.profile.clone(),
lib: original_toml.lib.clone(),
bin: original_toml.bin.clone(),
example: original_toml.example.clone(),
test: original_toml.test.clone(),
bench: original_toml.bench.clone(),
lib: None,
bin: None,
example: None,
test: None,
bench: None,
dependencies: None,
dev_dependencies: None,
dev_dependencies2: None,
@ -318,6 +318,47 @@ fn resolve_toml(
});
resolved_toml.package = Some(resolved_package);
resolved_toml.lib = targets::resolve_lib(
original_toml.lib.as_ref(),
package_root,
&original_package.name,
edition,
warnings,
)?;
resolved_toml.bin = Some(targets::resolve_bins(
original_toml.bin.as_ref(),
package_root,
&original_package.name,
edition,
original_package.autobins,
warnings,
resolved_toml.lib.is_some(),
)?);
resolved_toml.example = Some(targets::resolve_examples(
original_toml.example.as_ref(),
package_root,
edition,
original_package.autoexamples,
warnings,
errors,
)?);
resolved_toml.test = Some(targets::resolve_tests(
original_toml.test.as_ref(),
package_root,
edition,
original_package.autotests,
warnings,
errors,
)?);
resolved_toml.bench = Some(targets::resolve_benches(
original_toml.bench.as_ref(),
package_root,
edition,
original_package.autobenches,
warnings,
errors,
)?);
let activated_opt_deps = resolved_toml
.features
.as_ref()
@ -519,10 +560,10 @@ fn resolve_package_toml<'a>(
.map(manifest::InheritableField::Value),
workspace: original_package.workspace.clone(),
im_a_teapot: original_package.im_a_teapot.clone(),
autobins: original_package.autobins.clone(),
autoexamples: original_package.autoexamples.clone(),
autotests: original_package.autotests.clone(),
autobenches: original_package.autobenches.clone(),
autobins: Some(false),
autoexamples: Some(false),
autotests: Some(false),
autobenches: Some(false),
default_run: original_package.default_run.clone(),
description: original_package
.description
@ -1149,8 +1190,8 @@ fn to_real_manifest(
// If we have a lib with no path, use the inferred lib or else the package name.
let targets = to_targets(
&features,
&original_toml,
&resolved_toml,
package_name,
package_root,
edition,
&resolved_package.metabuild,
@ -2520,14 +2561,14 @@ fn prepare_toml_for_publish(
}
let lib = if let Some(target) = &me.lib {
Some(prepare_target_for_publish(target, "library")?)
prepare_target_for_publish(target, included, "library", ws.gctx())?
} else {
None
};
let bin = prepare_targets_for_publish(me.bin.as_ref(), "binary")?;
let example = prepare_targets_for_publish(me.example.as_ref(), "example")?;
let test = prepare_targets_for_publish(me.test.as_ref(), "test")?;
let bench = prepare_targets_for_publish(me.bench.as_ref(), "benchmark")?;
let bin = prepare_targets_for_publish(me.bin.as_ref(), included, "binary", ws.gctx())?;
let example = prepare_targets_for_publish(me.example.as_ref(), included, "example", ws.gctx())?;
let test = prepare_targets_for_publish(me.test.as_ref(), included, "test", ws.gctx())?;
let bench = prepare_targets_for_publish(me.bench.as_ref(), included, "benchmark", ws.gctx())?;
let all = |_d: &manifest::TomlDependency| true;
let mut manifest = manifest::TomlManifest {
@ -2685,7 +2726,9 @@ fn prepare_toml_for_publish(
fn prepare_targets_for_publish(
targets: Option<&Vec<manifest::TomlTarget>>,
included: &[PathBuf],
context: &str,
gctx: &GlobalContext,
) -> CargoResult<Option<Vec<manifest::TomlTarget>>> {
let Some(targets) = targets else {
return Ok(None);
@ -2693,23 +2736,41 @@ fn prepare_targets_for_publish(
let mut prepared = Vec::with_capacity(targets.len());
for target in targets {
let target = prepare_target_for_publish(target, context)?;
let Some(target) = prepare_target_for_publish(target, included, context, gctx)? else {
continue;
};
prepared.push(target);
}
Ok(Some(prepared))
if prepared.is_empty() {
Ok(None)
} else {
Ok(Some(prepared))
}
}
fn prepare_target_for_publish(
target: &manifest::TomlTarget,
included: &[PathBuf],
context: &str,
) -> CargoResult<manifest::TomlTarget> {
let mut target = target.clone();
if let Some(path) = target.path {
let path = normalize_path(&path.0);
target.path = Some(manifest::PathValue(normalize_path_sep(path, context)?));
gctx: &GlobalContext,
) -> CargoResult<Option<manifest::TomlTarget>> {
let path = target.path.as_ref().expect("previously resolved");
let path = normalize_path(&path.0);
if !included.contains(&path) {
let name = target.name.as_ref().expect("previously resolved");
gctx.shell().warn(format!(
"ignoring {context} `{name}` as `{}` is not included in the published package",
path.display()
))?;
return Ok(None);
}
Ok(target)
let mut target = target.clone();
let path = normalize_path_sep(path, context)?;
target.path = Some(manifest::PathValue(path.into()));
Ok(Some(target))
}
fn normalize_path_sep(path: PathBuf, context: &str) -> CargoResult<PathBuf> {

View file

@ -34,8 +34,8 @@ const DEFAULT_EXAMPLE_DIR_NAME: &'static str = "examples";
#[tracing::instrument(skip_all)]
pub(super) fn to_targets(
features: &Features,
original_toml: &TomlManifest,
resolved_toml: &TomlManifest,
package_name: &str,
package_root: &Path,
edition: Edition,
metabuild: &Option<StringOrVec>,
@ -44,26 +44,14 @@ pub(super) fn to_targets(
) -> CargoResult<Vec<Target>> {
let mut targets = Vec::new();
let has_lib;
let lib = resolve_lib(
resolved_toml.lib.as_ref(),
package_root,
package_name,
edition,
warnings,
)?;
if let Some(target) = to_lib_target(
original_toml.lib.as_ref(),
resolved_toml.lib.as_ref(),
lib.as_ref(),
package_root,
edition,
warnings,
)? {
targets.push(target);
has_lib = true;
} else {
has_lib = false;
}
let package = resolved_toml
@ -71,52 +59,31 @@ pub(super) fn to_targets(
.as_ref()
.ok_or_else(|| anyhow::format_err!("manifest has no `package` (or `project`)"))?;
let bins = resolve_bins(
resolved_toml.bin.as_ref(),
package_root,
package_name,
edition,
package.autobins,
warnings,
has_lib,
)?;
targets.extend(to_bin_targets(
features,
&bins,
resolved_toml.bin.as_deref().unwrap_or_default(),
package_root,
edition,
errors,
)?);
let toml_examples = resolve_examples(
resolved_toml.example.as_ref(),
targets.extend(to_example_targets(
resolved_toml.example.as_deref().unwrap_or_default(),
package_root,
edition,
package.autoexamples,
warnings,
errors,
)?;
targets.extend(to_example_targets(&toml_examples, package_root, edition)?);
)?);
let toml_tests = resolve_tests(
resolved_toml.test.as_ref(),
targets.extend(to_test_targets(
resolved_toml.test.as_deref().unwrap_or_default(),
package_root,
edition,
package.autotests,
warnings,
errors,
)?;
targets.extend(to_test_targets(&toml_tests, package_root, edition)?);
)?);
let toml_benches = resolve_benches(
resolved_toml.bench.as_ref(),
targets.extend(to_bench_targets(
resolved_toml.bench.as_deref().unwrap_or_default(),
package_root,
edition,
package.autobenches,
warnings,
errors,
)?;
targets.extend(to_bench_targets(&toml_benches, package_root, edition)?);
)?);
// processing the custom build script
if let Some(custom_build) = package.resolved_build().expect("should be resolved") {
@ -158,7 +125,7 @@ pub(super) fn to_targets(
Ok(targets)
}
fn resolve_lib(
pub fn resolve_lib(
original_lib: Option<&TomlLibTarget>,
package_root: &Path,
package_name: &str,
@ -283,7 +250,7 @@ fn to_lib_target(
Ok(Some(target))
}
fn resolve_bins(
pub fn resolve_bins(
toml_bins: Option<&Vec<TomlBinTarget>>,
package_root: &Path,
package_name: &str,
@ -409,7 +376,7 @@ fn legacy_bin_path(package_root: &Path, name: &str, has_lib: bool) -> Option<Pat
None
}
fn resolve_examples(
pub fn resolve_examples(
toml_examples: Option<&Vec<TomlExampleTarget>>,
package_root: &Path,
edition: Edition,
@ -464,7 +431,7 @@ fn to_example_targets(
Ok(result)
}
fn resolve_tests(
pub fn resolve_tests(
toml_tests: Option<&Vec<TomlTestTarget>>,
package_root: &Path,
edition: Edition,
@ -512,7 +479,7 @@ fn to_test_targets(
Ok(result)
}
fn resolve_benches(
pub fn resolve_benches(
toml_benches: Option<&Vec<TomlBenchTarget>>,
package_root: &Path,
edition: Edition,

View file

@ -2215,6 +2215,10 @@ name = "foo"
version = "0.1.0"
authors = []
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
homepage = "foo"
documentation = "foo"
@ -2223,6 +2227,10 @@ license = "MIT"
repository = "foo"
resolver = "2"
[lib]
name = "foo"
path = "src/lib.rs"
[dependencies.bar]
version = "1.0"
artifact = ["bin"]

View file

@ -1704,11 +1704,19 @@ name = "a"
version = "0.1.0"
authors = ["Zzz"]
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
homepage = "https://example.com/"
readme = false
license = "MIT"
resolver = "2"
[lib]
name = "a"
path = "src/lib.rs"
"#,
cargo::core::manifest::MANIFEST_PREAMBLE
);

View file

@ -986,11 +986,19 @@ edition = "2015"
name = "foo"
version = "0.1.0"
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
homepage = "https://example.com/"
readme = false
license = "MIT"
[lib]
name = "foo"
path = "src/lib.rs"
[dependencies.opt-dep1]
version = "1.0"
optional = true
@ -1106,11 +1114,19 @@ edition = "2015"
name = "foo"
version = "0.1.0"
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
homepage = "https://example.com/"
readme = false
license = "MIT"
[lib]
name = "foo"
path = "src/lib.rs"
[dependencies.bar]
version = "1.0"
optional = true

View file

@ -225,6 +225,10 @@ include = [
"Cargo.toml",
]
publish = true
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "This is a crate"
homepage = "https://www.rust-lang.org"
documentation = "https://www.rust-lang.org/learn"
@ -233,6 +237,10 @@ keywords = ["cli"]
categories = ["development-tools"]
license = "MIT"
repository = "https://github.com/example/example"
[[bin]]
name = "foo"
path = "src/main.rs"
"#,
cargo::core::manifest::MANIFEST_PREAMBLE
),
@ -386,8 +394,16 @@ name = "bar"
version = "0.2.0"
authors = []
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
readme = false
[[bin]]
name = "bar"
path = "src/main.rs"
[dependencies.dep]
version = "0.1"
@ -519,8 +535,16 @@ name = "bar"
version = "0.2.0"
authors = []
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
readme = false
[[bin]]
name = "bar"
path = "src/main.rs"
[dependencies.dep]
version = "0.1.2"
features = ["testing"]
@ -771,6 +795,10 @@ include = [
"README.md",
]
publish = true
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "This is a crate"
homepage = "https://www.rust-lang.org"
documentation = "https://www.rust-lang.org/learn"
@ -780,6 +808,10 @@ categories = ["development-tools"]
license = "MIT"
license-file = "LICENSE"
repository = "https://github.com/example/example"
[[bin]]
name = "bar"
path = "src/main.rs"
"#,
cargo::core::manifest::MANIFEST_PREAMBLE
),
@ -935,8 +967,16 @@ name = "bar"
version = "0.2.0"
authors = []
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
readme = false
[[bin]]
name = "bar"
path = "src/main.rs"
[dependencies.dep]
version = "0.1"

View file

@ -1219,6 +1219,10 @@ version = "0.0.1"
authors = []
build = false
exclude = ["*.txt"]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
readme = false
license = "MIT"
@ -1226,6 +1230,10 @@ license = "MIT"
[package.metadata]
foo = "bar"
[[bin]]
name = "foo"
path = "src/main.rs"
[dependencies.abc]
version = "1.0"
@ -1296,7 +1304,15 @@ name = "bar"
version = "0.1.0"
authors = []
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
readme = false
[lib]
name = "bar"
path = "src/lib.rs"
"#,
cargo::core::manifest::MANIFEST_PREAMBLE
);
@ -1365,8 +1381,16 @@ edition = "2015"
name = "foo"
version = "0.0.1"
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
readme = false
[[bin]]
name = "foo"
path = "src/main.rs"
[dependencies.bar]
version = "1.0.0"
@ -1385,8 +1409,16 @@ edition = "2015"
name = "foo"
version = "0.0.1"
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
readme = false
[[bin]]
name = "foo"
path = "src/main.rs"
[dependencies.bar]
version = "1.0.0"
public = true
@ -2864,8 +2896,16 @@ edition = "2021"
name = "bar"
version = "0.1.0"
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
readme = false
resolver = "1"
[lib]
name = "bar"
path = "src/lib.rs"
"#,
cargo::core::manifest::MANIFEST_PREAMBLE
);
@ -2885,7 +2925,15 @@ edition = "2015"
name = "baz"
version = "0.1.0"
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
readme = false
[lib]
name = "baz"
path = "src/lib.rs"
"#,
cargo::core::manifest::MANIFEST_PREAMBLE
);
@ -2949,10 +2997,18 @@ version = "0.0.1"
authors = []
build = false
exclude = ["*.txt"]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
homepage = "https://example.com/"
readme = false
license = "MIT"
[[bin]]
name = "foo"
path = "src/main.rs"
"#,
cargo::core::manifest::MANIFEST_PREAMBLE
);
@ -3045,10 +3101,18 @@ name = "foo"
version = "0.0.1"
authors = []
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
documentation = "https://example.com/"
readme = false
license = "MIT"
[[bin]]
name = "foo"
path = "src/main.rs"
"#,
cargo::core::manifest::MANIFEST_PREAMBLE
);
@ -3154,10 +3218,18 @@ name = "foo"
version = "0.0.1"
authors = []
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
homepage = "https://example.com/"
readme = false
license = "MIT"
[[bin]]
name = "foo"
path = "src/main.rs"
"#,
cargo::core::manifest::MANIFEST_PREAMBLE
);
@ -3277,6 +3349,10 @@ fn normalize_case() {
See [..]
[PACKAGING] foo v0.0.1 ([CWD])
[WARNING] ignoring `package.build` as `build.rs` is not included in the published package
[WARNING] ignoring binary `foo` as `src/main.rs` is not included in the published package
[WARNING] ignoring example `ExampleFoo` as `examples/ExampleFoo.rs` is not included in the published package
[WARNING] ignoring test `explicitpath` as `tests/explicitpath.rs` is not included in the published package
[WARNING] ignoring test `ExplicitPath` as `tests/ExplicitPath.rs` is not included in the published package
[VERIFYING] foo v0.0.1 ([CWD])
[COMPILING] foo v0.0.1 ([CWD][..])
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
@ -3306,6 +3382,10 @@ src/lib.rs
See [..]
[PACKAGING] foo v0.0.1 ([CWD])
[WARNING] ignoring `package.build` as `build.rs` is not included in the published package
[WARNING] ignoring binary `foo` as `src/main.rs` is not included in the published package
[WARNING] ignoring example `ExampleFoo` as `examples/ExampleFoo.rs` is not included in the published package
[WARNING] ignoring test `explicitpath` as `tests/explicitpath.rs` is not included in the published package
[WARNING] ignoring test `ExplicitPath` as `tests/ExplicitPath.rs` is not included in the published package
[VERIFYING] foo v0.0.1 ([CWD])
[COMPILING] foo v0.0.1 ([CWD][..])
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
@ -3339,13 +3419,17 @@ version = "0.0.1"
authors = []
build = false
exclude = ["*.txt"]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
readme = false
license = "MIT"
[[test]]
name = "explicitpath"
path = "tests/explicitpath.rs"
[lib]
name = "foo"
path = "src/lib.rs"
"#,
cargo::core::manifest::MANIFEST_PREAMBLE
),
@ -3750,12 +3834,17 @@ name = "foo"
version = "0.0.1"
authors = []
build = "src/build.rs"
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
documentation = "docs.rs/foo"
readme = "docs/README.md"
license-file = "docs/LICENSE"
[lib]
name = "foo"
path = "src/lib.rs"
[[bin]]
@ -3840,10 +3929,18 @@ include = [
"src/lib.rs",
"build.rs",
]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
documentation = "docs.rs/foo"
readme = false
license = "MIT"
[lib]
name = "foo"
path = "src/lib.rs"
"#,
)],
);
@ -3909,10 +4006,18 @@ version = "0.0.1"
authors = []
build = false
include = ["src/lib.rs"]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
documentation = "docs.rs/foo"
readme = false
license = "MIT"
[lib]
name = "foo"
path = "src/lib.rs"
"#,
)],
);
@ -3981,10 +4086,18 @@ include = [
"src/lib.rs",
"build.rs",
]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
documentation = "docs.rs/foo"
readme = false
license = "MIT"
[lib]
name = "foo"
path = "src/lib.rs"
"#,
)],
);
@ -4051,10 +4164,18 @@ version = "0.0.1"
authors = []
build = false
include = ["src/lib.rs"]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
documentation = "docs.rs/foo"
readme = false
license = "MIT"
[lib]
name = "foo"
path = "src/lib.rs"
"#,
)],
);
@ -4128,10 +4249,22 @@ include = [
"src/main.rs",
"src/lib.rs",
]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
documentation = "docs.rs/foo"
readme = false
license = "MIT"
[lib]
name = "foo"
path = "src/lib.rs"
[[bin]]
name = "foo"
path = "src/main.rs"
"#,
)],
);
@ -4163,6 +4296,7 @@ fn discovery_inferred_lib_excluded() {
.with_stderr(
"\
[PACKAGING] foo v0.0.1 ([CWD])
[WARNING] ignoring library `foo` as `src/lib.rs` is not included in the published package
[VERIFYING] foo v0.0.1 ([CWD])
[COMPILING] foo v0.0.1 ([CWD][..])
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
@ -4196,10 +4330,18 @@ version = "0.0.1"
authors = []
build = false
include = ["src/main.rs"]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
documentation = "docs.rs/foo"
readme = false
license = "MIT"
[[bin]]
name = "foo"
path = "src/main.rs"
"#,
)],
);
@ -4276,13 +4418,22 @@ include = [
"src/main.rs",
"src/lib.rs",
]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
documentation = "docs.rs/foo"
readme = false
license = "MIT"
[lib]
name = "foo"
path = "src/lib.rs"
[[bin]]
name = "foo"
path = "src/main.rs"
"#,
)],
);
@ -4313,20 +4464,59 @@ fn discovery_explicit_lib_excluded() {
.build();
p.cargo("package")
.with_status(101)
.with_stdout("")
.with_stderr(
"\
[PACKAGING] foo v0.0.1 ([CWD])
[WARNING] ignoring library `foo` as `src/lib.rs` is not included in the published package
[VERIFYING] foo v0.0.1 ([CWD])
[COMPILING] foo v0.0.1 ([CWD][..])
[ERROR] couldn't read src/lib.rs: [..]
[ERROR] could not compile `foo` (lib) due to 1 previous error
[ERROR] failed to verify package tarball
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] 4 files, [..] ([..] compressed)
",
)
.run();
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
validate_crate_contents(
f,
"foo-0.0.1.crate",
&["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"],
&[(
"Cargo.toml",
r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2015"
name = "foo"
version = "0.0.1"
authors = []
build = false
include = ["src/main.rs"]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
documentation = "docs.rs/foo"
readme = false
license = "MIT"
[[bin]]
name = "foo"
path = "src/main.rs"
"#,
)],
);
}
#[cargo_test]
@ -4406,10 +4596,34 @@ include = [
"tests/test_foo.rs",
"benches/bench_foo.rs",
]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
documentation = "docs.rs/foo"
readme = false
license = "MIT"
[lib]
name = "foo"
path = "src/lib.rs"
[[bin]]
name = "foo"
path = "src/bin/foo/main.rs"
[[example]]
name = "example_foo"
path = "examples/example_foo.rs"
[[test]]
name = "test_foo"
path = "tests/test_foo.rs"
[[bench]]
name = "bench_foo"
path = "benches/bench_foo.rs"
"#,
)],
);
@ -4444,6 +4658,10 @@ fn discovery_inferred_other_excluded() {
.with_stderr(
"\
[PACKAGING] foo v0.0.1 ([CWD])
[WARNING] ignoring binary `foo` as `src/bin/foo/main.rs` is not included in the published package
[WARNING] ignoring example `example_foo` as `examples/example_foo.rs` is not included in the published package
[WARNING] ignoring test `test_foo` as `tests/test_foo.rs` is not included in the published package
[WARNING] ignoring benchmark `bench_foo` as `benches/bench_foo.rs` is not included in the published package
[VERIFYING] foo v0.0.1 ([CWD])
[COMPILING] foo v0.0.1 ([CWD][..])
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
@ -4477,10 +4695,18 @@ version = "0.0.1"
authors = []
build = false
include = ["src/lib.rs"]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
documentation = "docs.rs/foo"
readme = false
license = "MIT"
[lib]
name = "foo"
path = "src/lib.rs"
"#,
)],
);
@ -4575,22 +4801,34 @@ include = [
"tests/test_foo.rs",
"benches/bench_foo.rs",
]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
documentation = "docs.rs/foo"
readme = false
license = "MIT"
[lib]
name = "foo"
path = "src/lib.rs"
[[bin]]
name = "foo"
path = "src/bin/foo/main.rs"
[[example]]
name = "example_foo"
path = "examples/example_foo.rs"
[[test]]
name = "test_foo"
path = "tests/test_foo.rs"
[[bench]]
name = "bench_foo"
path = "benches/bench_foo.rs"
"#,
)],
);
@ -4633,20 +4871,60 @@ fn discovery_explicit_other_excluded() {
.build();
p.cargo("package")
.with_status(101)
.with_stdout("")
.with_stderr(
"\
[PACKAGING] foo v0.0.1 ([CWD])
[WARNING] ignoring binary `foo` as `src/bin/foo/main.rs` is not included in the published package
[WARNING] ignoring example `example_foo` as `examples/example_foo.rs` is not included in the published package
[WARNING] ignoring test `test_foo` as `tests/test_foo.rs` is not included in the published package
[WARNING] ignoring benchmark `bench_foo` as `benches/bench_foo.rs` is not included in the published package
[VERIFYING] foo v0.0.1 ([CWD])
[ERROR] failed to verify package tarball
Caused by:
failed to parse manifest at `[CWD]/target/package/foo-0.0.1/Cargo.toml`
Caused by:
can't find `example_foo` example at `examples/example_foo.rs` or `examples/example_foo/main.rs`. Please specify example.path if you want to use a non-default path.
[COMPILING] foo v0.0.1 ([CWD][..])
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] 4 files, [..] ([..] compressed)
",
)
.run();
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
validate_crate_contents(
f,
"foo-0.0.1.crate",
&["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
&[(
"Cargo.toml",
r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2015"
name = "foo"
version = "0.0.1"
authors = []
build = false
include = ["src/lib.rs"]
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
documentation = "docs.rs/foo"
readme = false
license = "MIT"
[lib]
name = "foo"
path = "src/lib.rs"
"#,
)],
);
}

View file

@ -1561,10 +1561,18 @@ You may press ctrl-c [..]
version = \"0.1.0\"\n\
authors = []\n\
build = false\n\
autobins = false\n\
autoexamples = false\n\
autotests = false\n\
autobenches = false\n\
description = \"foo\"\n\
readme = false\n\
license = \"MIT\"\n\
\n\
[[bin]]\n\
name = \"foo\"\n\
path = \"src/main.rs\"\n\
\n\
[dependencies.dep1]\n\
version = \"1.0\"\n\
",
@ -1675,6 +1683,10 @@ name = "foo"
version = "0.1.0"
authors = []
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
homepage = "foo"
documentation = "foo"
@ -1682,6 +1694,10 @@ readme = false
license = "MIT"
repository = "foo"
[lib]
name = "foo"
path = "src/lib.rs"
[dev-dependencies]
"#,
cargo::core::manifest::MANIFEST_PREAMBLE
@ -1936,6 +1952,10 @@ name = "foo"
version = "0.1.0"
authors = []
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
homepage = "foo"
documentation = "foo"
@ -1943,6 +1963,10 @@ readme = false
license = "MIT"
repository = "foo"
[[bin]]
name = "foo"
path = "src/main.rs"
[dependencies.normal-and-dev]
version = "1.0"
features = ["cat"]

View file

@ -631,11 +631,19 @@ edition = "2015"
name = "foo"
version = "0.1.0"
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "foo"
homepage = "https://example.com/"
readme = false
license = "MIT"
[lib]
name = "foo"
path = "src/lib.rs"
[dependencies.bar]
version = "1.0"
optional = true