Skip to content

Commit

Permalink
Build aux-files just-in-time
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Apr 7, 2024
1 parent ef01174 commit a2d2f87
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/aux_builds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ impl Build for AuxBuilder {
revision: "",
comments: &comments,
path: &self.aux_file,
aux_dir: self.aux_file.parent().unwrap(),
};

config.patch_out_dir();

let mut aux_cmd = config.build_command()?;
let mut aux_cmd = config.build_command(build_manager)?;

let mut extra_args =
config.build_aux_files(self.aux_file.parent().unwrap(), build_manager)?;
Expand Down
3 changes: 2 additions & 1 deletion src/custom_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
process::{Command, Output},
};

use crate::{per_test_config::TestConfig, Config, Errored};
use crate::{build_manager::BuildManager, per_test_config::TestConfig, Config, Errored};

pub mod run;
pub mod rustfix;
Expand All @@ -30,6 +30,7 @@ pub trait Flag: Send + Sync + UnwindSafe + RefUnwindSafe + std::fmt::Debug {
_config: &TestConfig<'_>,
cmd: Command,
_output: &Output,
_build_manager: &BuildManager<'_>,
) -> Result<Option<Command>, Errored> {
Ok(Some(cmd))
}
Expand Down
4 changes: 3 additions & 1 deletion src/custom_flags/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use bstr::ByteSlice;
use std::process::{Command, Output};

use crate::{per_test_config::TestConfig, Error, Errored};
use crate::{build_manager::BuildManager, per_test_config::TestConfig, Error, Errored};

use super::Flag;

Expand All @@ -22,6 +22,7 @@ impl Flag for Run {
config: &TestConfig<'_>,
cmd: Command,
_output: &Output,
_build_manager: &BuildManager<'_>,
) -> Result<Option<Command>, Errored> {
let mut cmd = cmd;
let exit_code = self.exit_code;
Expand All @@ -31,6 +32,7 @@ impl Flag for Run {
revision: &revision,
comments: config.comments,
path: config.path,
aux_dir: config.aux_dir,
};
cmd.arg("--print").arg("file-names");
let output = cmd.output().unwrap();
Expand Down
6 changes: 5 additions & 1 deletion src/custom_flags/rustfix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::{
use spanned::Span;

use crate::{
build_manager::BuildManager,
parser::OptWithLine,
per_test_config::{Comments, Revisioned, TestConfig},
rustc_stderr, Error, Errored, Mode,
Expand Down Expand Up @@ -41,6 +42,7 @@ impl Flag for RustfixMode {
config: &TestConfig<'_>,
cmd: Command,
output: &Output,
build_manager: &BuildManager<'_>,
) -> Result<Option<Command>, Errored> {
let global_rustfix = match *config.mode()? {
Mode::Pass | Mode::Panic => RustfixMode::Disabled,
Expand Down Expand Up @@ -132,6 +134,7 @@ impl Flag for RustfixMode {
revision: config.revision,
comments: &rustfix_comments,
path: config.path,
aux_dir: config.aux_dir,
};

let run = fixed_code.is_some();
Expand All @@ -157,6 +160,7 @@ impl Flag for RustfixMode {
revision: config.revision,
comments: &rustfix_comments,
path: &rustfix_path,
aux_dir: config.aux_dir,
};
if !errors.is_empty() {
return Err(Errored {
Expand All @@ -171,7 +175,7 @@ impl Flag for RustfixMode {
return Ok(Some(cmd));
}

let mut cmd = config.build_command()?;
let mut cmd = config.build_command(build_manager)?;
cmd.arg("--crate-name").arg(crate_name);
let output = cmd.output().unwrap();
if output.status.success() {
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ pub fn test_command(mut config: Config, path: &Path) -> Result<Command> {
config,
revision: "",
comments: &comments,
aux_dir: &path.parent().unwrap().join("auxiliary"),
path,
};
let mut result = config.build_command().unwrap();
let build_manager = BuildManager::new(&(), config.config.clone());
let mut result = config.build_command(&build_manager).unwrap();
result.args(extra_args);

Ok(result)
Expand Down Expand Up @@ -349,6 +351,7 @@ fn parse_and_test_file(
revision,
comments: &comments,
path: status.path(),
aux_dir: &status.path().parent().unwrap().join("auxiliary"),
};

let result = test_config.run_test(build_manager);
Expand Down
25 changes: 15 additions & 10 deletions src/per_test_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub struct TestConfig<'a> {
pub(crate) comments: &'a Comments,
/// The path to the current file
pub path: &'a Path,
/// The path to the folder where to look for aux files
pub aux_dir: &'a Path,
}

impl TestConfig<'_> {
Expand Down Expand Up @@ -83,14 +85,20 @@ impl TestConfig<'_> {
}
}

pub(crate) fn build_command(&self) -> Result<Command, Errored> {
pub(crate) fn build_command(
&self,
build_manager: &BuildManager<'_>,
) -> Result<Command, Errored> {
let TestConfig {
config,
revision,
comments,
path,
aux_dir,
} = self;
let mut cmd = config.program.build(&config.out_dir);
let extra_args = self.build_aux_files(aux_dir, build_manager)?;
cmd.args(extra_args);
cmd.arg(path);
if !revision.is_empty() {
cmd.arg(format!("--cfg={revision}"));
Expand Down Expand Up @@ -393,16 +401,9 @@ impl TestConfig<'_> {
}

pub(crate) fn run_test(mut self, build_manager: &BuildManager<'_>) -> TestResult {
let extra_args = self.build_aux_files(
&self.path.parent().unwrap().join("auxiliary"),
build_manager,
)?;

self.patch_out_dir();

self.config.program.args.extend(extra_args);

let mut cmd = self.build_command()?;
let mut cmd = self.build_command(build_manager)?;
let stdin = self.path.with_extension(self.extension("stdin"));
if stdin.exists() {
cmd.stdin(std::fs::File::open(stdin).unwrap());
Expand All @@ -414,7 +415,11 @@ impl TestConfig<'_> {

for rev in self.comments() {
for custom in rev.custom.values() {
if let Some(c) = custom.content.post_test_action(&self, cmd, &output)? {
if let Some(c) =
custom
.content
.post_test_action(&self, cmd, &output, build_manager)?
{
cmd = c;
} else {
return Ok(TestOk::Ok);
Expand Down
54 changes: 54 additions & 0 deletions src/status_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,62 @@ pub trait Summary {
fn test_failure(&mut self, _status: &dyn TestStatus, _errors: &Errors) {}
}

/// Report no summary
impl Summary for () {}

/// Emit nothing
impl StatusEmitter for () {
fn register_test(&self, path: PathBuf) -> Box<dyn TestStatus> {
Box::new(SilentStatus {
path,
revision: String::new(),
})
}

fn finalize(
&self,
_failed: usize,
_succeeded: usize,
_ignored: usize,
_filtered: usize,
) -> Box<dyn Summary> {
Box::new(())
}
}

struct SilentStatus {
revision: String,
path: PathBuf,
}

impl TestStatus for SilentStatus {
fn for_revision(&self, revision: &str) -> Box<dyn TestStatus> {
Box::new(SilentStatus {
revision: revision.into(),
path: self.path.clone(),
})
}

fn failed_test<'a>(
&'a self,
_cmd: &'a Command,
_stderr: &'a [u8],
_stdout: &'a [u8],
) -> Box<dyn Debug + 'a> {
Box::new(())
}

fn update_status(&self, _msg: String) {}

fn path(&self) -> &Path {
&self.path
}

fn revision(&self) -> &str {
&self.revision
}
}

/// A human readable output emitter.
#[derive(Clone)]
pub struct Text {
Expand Down
1 change: 1 addition & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ macro_rules! config {
path,
comments: &comments,
revision: "",
aux_dir: Path::new("unused_doesnt_exist"),
};
};
}
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 @@ -519,7 +519,7 @@ full stdout:


FAILED TEST: tests/actual_tests_bless/aux_proc_macro_no_main.rs
command: "rustc" "--error-format=json" "--crate-type=lib" "--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" "--extern" "the_proc_macro=$DIR/tests/integrations/basic-fail/../../../target/$TMP/tests/actual_tests_bless/auxiliary/libthe_proc_macro.so" "-L" "$DIR/tests/integrations/basic-fail/../../../target/$TMP/tests/actual_tests_bless/auxiliary" "--out-dir" "$TMP "tests/actual_tests_bless/aux_proc_macro_no_main.rs" "--edition" "2021"
command: "rustc" "--error-format=json" "--crate-type=lib" "--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" "--out-dir" "$TMP "--extern" "the_proc_macro=$DIR/tests/integrations/basic-fail/../../../target/$TMP/tests/actual_tests_bless/auxiliary/libthe_proc_macro.so" "-L" "$DIR/tests/integrations/basic-fail/../../../target/$TMP/tests/actual_tests_bless/auxiliary" "tests/actual_tests_bless/aux_proc_macro_no_main.rs" "--edition" "2021"

error: there were 1 unmatched diagnostics
--> tests/actual_tests_bless/aux_proc_macro_no_main.rs:7:8
Expand Down

0 comments on commit a2d2f87

Please sign in to comment.