Skip to content

Commit

Permalink
Move revision-specific args to a custom flag
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Oct 30, 2024
1 parent fb3c75b commit 561c298
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<revision>`...) to a custom flag (`custom_flags::revision_args`)

## [0.27.0] - 2024-10-07

### Added
Expand Down
6 changes: 5 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -129,6 +130,9 @@ impl Config {
}
}

comment_defaults
.base()
.add_custom("rustc-revision-args", RustcRevisionArgs);
comment_defaults
.base()
.add_custom("edition", Edition("2021".into()));
Expand Down
2 changes: 2 additions & 0 deletions src/custom_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
32 changes: 32 additions & 0 deletions src/custom_flags/revision_args.rs
Original file line number Diff line number Diff line change
@@ -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<dyn Flag> {
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(())
}
}
4 changes: 0 additions & 4 deletions src/per_test_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@ impl TestConfig {
pub fn build_command(&self, build_manager: &BuildManager) -> Result<Command, Errored> {
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);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/dep-fail/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/integrations/ui_test_dep_bug/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 561c298

Please sign in to comment.