mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
refactor(compile): Extract test collection
This commit is contained in:
parent
8424b5f3f4
commit
874a8a04bf
@ -214,31 +214,7 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
|
|||||||
|
|
||||||
// Collect the result of the build into `self.compilation`.
|
// Collect the result of the build into `self.compilation`.
|
||||||
for unit in &self.bcx.roots {
|
for unit in &self.bcx.roots {
|
||||||
// Collect tests and executables.
|
self.collect_tests_and_executables(unit)?;
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect information for `rustdoc --test`.
|
// Collect information for `rustdoc --test`.
|
||||||
if unit.mode.is_doc_test() {
|
if unit.mode.is_doc_test() {
|
||||||
@ -307,6 +283,33 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
|
|||||||
Ok(self.compilation)
|
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).
|
/// Returns the executable for the specified unit (if any).
|
||||||
pub fn get_executable(&mut self, unit: &Unit) -> CargoResult<Option<PathBuf>> {
|
pub fn get_executable(&mut self, unit: &Unit) -> CargoResult<Option<PathBuf>> {
|
||||||
let is_binary = unit.target.is_executable();
|
let is_binary = unit.target.is_executable();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user