Skip to content

Commit

Permalink
refactor(compile): Extract test collection
Browse files Browse the repository at this point in the history
  • Loading branch information
epage authored and Flowrey committed Sep 20, 2024
1 parent 8424b5f commit 874a8a0
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions src/cargo/core/compiler/build_runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,31 +214,7 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {

// Collect the result of the build into `self.compilation`.
for unit in &self.bcx.roots {
// Collect tests and executables.
for output in self.outputs(unit)?.iter() {
if output.flavor == FileFlavor::DebugInfo || output.flavor == FileFlavor::Auxiliary
{
continue;
}

let bindst = output.bin_dst();

if unit.mode == CompileMode::Test {
self.compilation
.tests
.push(self.unit_output(unit, &output.path));
} else if unit.target.is_executable() {
self.compilation
.binaries
.push(self.unit_output(unit, bindst));
} else if unit.target.is_cdylib()
&& !self.compilation.cdylibs.iter().any(|uo| uo.unit == *unit)
{
self.compilation
.cdylibs
.push(self.unit_output(unit, bindst));
}
}
self.collect_tests_and_executables(unit)?;

// Collect information for `rustdoc --test`.
if unit.mode.is_doc_test() {
Expand Down Expand Up @@ -307,6 +283,33 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
Ok(self.compilation)
}

fn collect_tests_and_executables(&mut self, unit: &Unit) -> CargoResult<()> {
for output in self.outputs(unit)?.iter() {
if output.flavor == FileFlavor::DebugInfo || output.flavor == FileFlavor::Auxiliary {
continue;
}

let bindst = output.bin_dst();

if unit.mode == CompileMode::Test {
self.compilation
.tests
.push(self.unit_output(unit, &output.path));
} else if unit.target.is_executable() {
self.compilation
.binaries
.push(self.unit_output(unit, bindst));
} else if unit.target.is_cdylib()
&& !self.compilation.cdylibs.iter().any(|uo| uo.unit == *unit)
{
self.compilation
.cdylibs
.push(self.unit_output(unit, bindst));
}
}
Ok(())
}

/// Returns the executable for the specified unit (if any).
pub fn get_executable(&mut self, unit: &Unit) -> CargoResult<Option<PathBuf>> {
let is_binary = unit.target.is_executable();
Expand Down

0 comments on commit 874a8a0

Please sign in to comment.