Skip to content

Commit 1e525f4

Browse files
committed
refactor(compile): Extract test collection
1 parent e4f7731 commit 1e525f4

File tree

1 file changed

+28
-25
lines changed
  • src/cargo/core/compiler/build_runner

1 file changed

+28
-25
lines changed

src/cargo/core/compiler/build_runner/mod.rs

+28-25
Original file line numberDiff line numberDiff line change
@@ -214,31 +214,7 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
214214

215215
// Collect the result of the build into `self.compilation`.
216216
for unit in &self.bcx.roots {
217-
// Collect tests and executables.
218-
for output in self.outputs(unit)?.iter() {
219-
if output.flavor == FileFlavor::DebugInfo || output.flavor == FileFlavor::Auxiliary
220-
{
221-
continue;
222-
}
223-
224-
let bindst = output.bin_dst();
225-
226-
if unit.mode == CompileMode::Test {
227-
self.compilation
228-
.tests
229-
.push(self.unit_output(unit, &output.path));
230-
} else if unit.target.is_executable() {
231-
self.compilation
232-
.binaries
233-
.push(self.unit_output(unit, bindst));
234-
} else if unit.target.is_cdylib()
235-
&& !self.compilation.cdylibs.iter().any(|uo| uo.unit == *unit)
236-
{
237-
self.compilation
238-
.cdylibs
239-
.push(self.unit_output(unit, bindst));
240-
}
241-
}
217+
self.collect_tests_and_executables(unit)?;
242218

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

286+
fn collect_tests_and_executables(&mut self, unit: &Unit) -> CargoResult<()> {
287+
for output in self.outputs(unit)?.iter() {
288+
if output.flavor == FileFlavor::DebugInfo || output.flavor == FileFlavor::Auxiliary {
289+
continue;
290+
}
291+
292+
let bindst = output.bin_dst();
293+
294+
if unit.mode == CompileMode::Test {
295+
self.compilation
296+
.tests
297+
.push(self.unit_output(unit, &output.path));
298+
} else if unit.target.is_executable() {
299+
self.compilation
300+
.binaries
301+
.push(self.unit_output(unit, bindst));
302+
} else if unit.target.is_cdylib()
303+
&& !self.compilation.cdylibs.iter().any(|uo| uo.unit == *unit)
304+
{
305+
self.compilation
306+
.cdylibs
307+
.push(self.unit_output(unit, bindst));
308+
}
309+
}
310+
Ok(())
311+
}
312+
310313
/// Returns the executable for the specified unit (if any).
311314
pub fn get_executable(&mut self, unit: &Unit) -> CargoResult<Option<PathBuf>> {
312315
let is_binary = unit.target.is_executable();

0 commit comments

Comments
 (0)