Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move revision-specific args to a custom flag #291

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -115,7 +115,7 @@
+ | - unclosed delimiter
+4 |
+ | ^
+

Check failure on line 118 in tests/integrations/basic-fail/Cargo.stdout

View workflow job for this annotation

GitHub Actions / tests (macos-latest, x86_64-apple-darwin)

actual output differs from expected

this line was expected to be `+ | ^`
+error: aborting due to 1 previous error
+

Expand All @@ -128,7 +128,7 @@
| - unclosed delimiter
4 |
| ^

Check failure on line 131 in tests/integrations/basic-fail/Cargo.stdout

View workflow job for this annotation

GitHub Actions / tests (macos-latest, x86_64-apple-darwin)

actual output differs from expected

this line was expected to be ` | ^`
error: aborting due to 1 previous error


Expand Down Expand Up @@ -826,7 +826,7 @@


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 Expand Up @@ -1245,7 +1245,7 @@
+ | - unclosed delimiter
+4 |
+ | ^
+

Check failure on line 1248 in tests/integrations/basic-fail/Cargo.stdout

View workflow job for this annotation

GitHub Actions / tests (macos-latest, x86_64-apple-darwin)

actual output differs from expected

this line was expected to be `+ | ^`
+error: aborting due to 1 previous error
+

Expand Down
Loading