From eab5985674a956a4230f290c817fefe4cdfae406 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 14 Jun 2023 12:07:48 -0500 Subject: [PATCH] fix(embedded): Ensure we don't auto-discover any targets --- src/cargo/util/toml/embedded.rs | 21 +++++++++++++++++++-- tests/testsuite/script.rs | 10 +++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/cargo/util/toml/embedded.rs b/src/cargo/util/toml/embedded.rs index 90e042d9c439..a6f1db20541a 100644 --- a/src/cargo/util/toml/embedded.rs +++ b/src/cargo/util/toml/embedded.rs @@ -7,6 +7,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, @@ -56,8 +57,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)); @@ -355,6 +364,10 @@ name = "test" path = "test.rs" [package] +autobenches = false +autobins = false +autoexamples = false +autotests = false edition = "2021" name = "test" publish = false @@ -380,6 +393,10 @@ path = "test.rs" time = "0.1.25" [package] +autobenches = false +autobins = false +autoexamples = false +autotests = false edition = "2021" name = "test" publish = false diff --git a/tests/testsuite/script.rs b/tests/testsuite/script.rs index bf654debb74b..c03400de48bf 100644 --- a/tests/testsuite/script.rs +++ b/tests/testsuite/script.rs @@ -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();