Skip to content

Commit

Permalink
Merge pull request #291 from DaniPopes/revision-args
Browse files Browse the repository at this point in the history
Move revision-specific args to a custom flag
  • Loading branch information
oli-obk authored Oct 31, 2024
2 parents 6bffd73 + 31ad36c commit a2a7d13
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 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
2 changes: 1 addition & 1 deletion tests/integrations/basic-fail/Cargo.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ full stdout:


FAILED TEST: tests/actual_tests_bless/revisions_bad.rs (revision `bar`)
command: "rustc" "--error-format=json" "--out-dir" "$TMP "tests/actual_tests_bless/revisions_bad.rs" "--cfg=bar" "-Cextra-filename=bar" "--extern" "basic_fail=$DIR/tests/integrations/basic-fail/../../../target/$TMP/$TRIPLE/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/tests/integrations/basic-fail/../../../target/$TMP/$TRIPLE/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/tests/integrations/basic-fail/../../../target/$TMP/$TRIPLE/debug" "-L" "$DIR/tests/integrations/basic-fail/../../../target/$TMP/$TRIPLE/debug" "--edition" "2021"
command: "rustc" "--error-format=json" "--out-dir" "$TMP "tests/actual_tests_bless/revisions_bad.rs" "--extern" "basic_fail=$DIR/tests/integrations/basic-fail/../../../target/$TMP/$TRIPLE/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/tests/integrations/basic-fail/../../../target/$TMP/$TRIPLE/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/tests/integrations/basic-fail/../../../target/$TMP/$TRIPLE/debug" "-L" "$DIR/tests/integrations/basic-fail/../../../target/$TMP/$TRIPLE/debug" "--edition" "2021" "--cfg=bar" "-Cextra-filename=bar"

error: ``main` function not found in crate `revisions_bad`` not found in diagnostics outside the testfile
--> tests/actual_tests_bless/revisions_bad.rs:4:31
Expand Down

0 comments on commit a2a7d13

Please sign in to comment.