diff --git a/CHANGELOG.md b/CHANGELOG.md index b4939b7..9822766 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +* moved rustc revision-specific arguments (`--cfg=`...) to a custom flag (`custom_flags::revision_args`) + ## [0.27.0] - 2024-10-07 ### Added diff --git a/src/config.rs b/src/config.rs index be1b3b4..b765168 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,7 @@ #[cfg(feature = "rustc")] use crate::{ - aux_builds::AuxBuilder, custom_flags::edition::Edition, custom_flags::run::Run, + aux_builds::AuxBuilder, custom_flags::edition::Edition, + custom_flags::revision_args::RustcRevisionArgs, custom_flags::run::Run, custom_flags::rustfix::RustfixMode, custom_flags::Flag, filter::Match, }; use crate::{ @@ -129,6 +130,9 @@ impl Config { } } + comment_defaults + .base() + .add_custom("rustc-revision-args", RustcRevisionArgs); comment_defaults .base() .add_custom("edition", Edition("2021".into())); diff --git a/src/custom_flags.rs b/src/custom_flags.rs index 3b97bc9..51a3ce7 100644 --- a/src/custom_flags.rs +++ b/src/custom_flags.rs @@ -11,6 +11,8 @@ use std::{ #[cfg(feature = "rustc")] pub mod edition; #[cfg(feature = "rustc")] +pub mod revision_args; +#[cfg(feature = "rustc")] pub mod run; pub mod rustfix; diff --git a/src/custom_flags/revision_args.rs b/src/custom_flags/revision_args.rs new file mode 100644 index 0000000..95bfd7b --- /dev/null +++ b/src/custom_flags/revision_args.rs @@ -0,0 +1,32 @@ +//! Custom flag for setting rustc revision-specific args. + +use super::Flag; +use crate::{build_manager::BuildManager, per_test_config::TestConfig, Errored}; + +/// Set rustc revision-specific args. +#[derive(Clone, Debug)] +pub struct RustcRevisionArgs; + +impl Flag for RustcRevisionArgs { + fn clone_inner(&self) -> Box { + Box::new(self.clone()) + } + + fn must_be_unique(&self) -> bool { + true + } + + fn apply( + &self, + cmd: &mut std::process::Command, + config: &TestConfig, + _build_manager: &BuildManager, + ) -> Result<(), Errored> { + let revision = config.status.revision(); + if !revision.is_empty() { + cmd.arg(format!("--cfg={revision}")); + cmd.arg(format!("-Cextra-filename={revision}")); + } + Ok(()) + } +} diff --git a/src/per_test_config.rs b/src/per_test_config.rs index 649075b..01aa06f 100644 --- a/src/per_test_config.rs +++ b/src/per_test_config.rs @@ -133,10 +133,6 @@ impl TestConfig { pub fn build_command(&self, build_manager: &BuildManager) -> Result { let mut cmd = self.config.program.build(&self.config.out_dir); cmd.arg(self.status.path()); - if !self.status.revision().is_empty() { - cmd.arg(format!("--cfg={}", self.status.revision())); - cmd.arg(format!("-Cextra-filename={}", self.status.revision())); - } for r in self.comments() { cmd.args(&r.compile_flags); } diff --git a/tests/integrations/dep-fail/Cargo.lock b/tests/integrations/dep-fail/Cargo.lock index 8439c43..048e985 100644 --- a/tests/integrations/dep-fail/Cargo.lock +++ b/tests/integrations/dep-fail/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -565,7 +565,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.27.0" +version = "0.27.1" dependencies = [ "annotate-snippets", "anyhow", diff --git a/tests/integrations/ui_test_dep_bug/Cargo.lock b/tests/integrations/ui_test_dep_bug/Cargo.lock index 5ec2750..db234bb 100644 --- a/tests/integrations/ui_test_dep_bug/Cargo.lock +++ b/tests/integrations/ui_test_dep_bug/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -570,7 +570,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.27.0" +version = "0.27.1" dependencies = [ "annotate-snippets", "anyhow",