mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
fix(embedded): Ensure we don't auto-discover any targets
This commit is contained in:
parent
575b9ac934
commit
5ed07925cc
@ -8,6 +8,7 @@ const DEFAULT_EDITION: crate::core::features::Edition =
|
||||
crate::core::features::Edition::LATEST_STABLE;
|
||||
const DEFAULT_VERSION: &str = "0.0.0";
|
||||
const DEFAULT_PUBLISH: bool = false;
|
||||
const AUTO_FIELDS: &[&str] = &["autobins", "autoexamples", "autotests", "autobenches"];
|
||||
|
||||
pub fn expand_manifest(
|
||||
content: &str,
|
||||
@ -57,8 +58,11 @@ fn expand_manifest_(
|
||||
.or_insert_with(|| toml::Table::new().into())
|
||||
.as_table_mut()
|
||||
.ok_or_else(|| anyhow::format_err!("`package` must be a table"))?;
|
||||
for key in ["workspace", "build", "links"] {
|
||||
if package.contains_key(key) {
|
||||
for key in ["workspace", "build", "links"]
|
||||
.iter()
|
||||
.chain(AUTO_FIELDS.iter())
|
||||
{
|
||||
if package.contains_key(*key) {
|
||||
anyhow::bail!("`package.{key}` is not allowed in embedded manifests")
|
||||
}
|
||||
}
|
||||
@ -88,6 +92,11 @@ fn expand_manifest_(
|
||||
package
|
||||
.entry("publish".to_owned())
|
||||
.or_insert_with(|| toml::Value::Boolean(DEFAULT_PUBLISH));
|
||||
for field in AUTO_FIELDS {
|
||||
package
|
||||
.entry(field.to_owned())
|
||||
.or_insert_with(|| toml::Value::Boolean(false));
|
||||
}
|
||||
|
||||
let mut bin = toml::Table::new();
|
||||
bin.insert("name".to_owned(), toml::Value::String(bin_name));
|
||||
@ -363,6 +372,10 @@ name = "test-"
|
||||
path = "test.rs"
|
||||
|
||||
[package]
|
||||
autobenches = false
|
||||
autobins = false
|
||||
autoexamples = false
|
||||
autotests = false
|
||||
edition = "2021"
|
||||
name = "test-"
|
||||
publish = false
|
||||
@ -388,6 +401,10 @@ path = "test.rs"
|
||||
time = "0.1.25"
|
||||
|
||||
[package]
|
||||
autobenches = false
|
||||
autobins = false
|
||||
autoexamples = false
|
||||
autotests = false
|
||||
edition = "2021"
|
||||
name = "test-"
|
||||
publish = false
|
||||
|
@ -523,12 +523,16 @@ fn main() {
|
||||
|
||||
p.cargo("-Zscript script.rs --help")
|
||||
.masquerade_as_nightly_cargo(&["script"])
|
||||
.with_status(101)
|
||||
.with_stdout(
|
||||
r#"Hello world!
|
||||
"#,
|
||||
)
|
||||
.with_stderr(
|
||||
"\
|
||||
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
|
||||
[ERROR] `cargo run` could not determine which binary to run. Use the `--bin` option to specify a binary, or the `default-run` manifest key.
|
||||
available binaries: not-script, script
|
||||
[COMPILING] script v0.0.0 ([ROOT]/foo)
|
||||
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
|
||||
[RUNNING] `[..]/debug/script[EXE] --help`
|
||||
",
|
||||
)
|
||||
.run();
|
||||
|
Loading…
x
Reference in New Issue
Block a user