Skip to content

Commit

Permalink
Auto merge of #11445 - willcrichton:refactor-target-generator, r=weih…
Browse files Browse the repository at this point in the history
…anglo

Refactor generate_targets into separate module

### What does this PR try to resolve?

The `generate_targets` function is fairly complicated with an absurd number of parameters. This PR refactors the function into a `TargetGenerator` struct that represents the state of the generator, and reduces the amount of parameter-passing between the relevant functions. Additionally, the `generate_targets` function has been refactored into two smaller functions `create_proposals` and `proposals_to_units`. The docscrape-specific functionality from #11430 has been pulled out into a separate function, as promised.

### How should we test and review this PR?

This PR does not change any functionality, so no new tests are added. It should be reviewed for code style.

r? `@weihanglo`
  • Loading branch information
bors committed Dec 2, 2022
2 parents 324a935 + ad201bc commit f6e737b
Show file tree
Hide file tree
Showing 5 changed files with 739 additions and 722 deletions.
8 changes: 4 additions & 4 deletions src/cargo/ops/cargo_compile/compile_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ pub enum FilterRule {
/// Filter to apply to the root package to select which Cargo targets will be built.
/// (examples, bins, benches, tests, ...)
///
/// The actual filter process happens inside [`generate_targets`].
/// The actual filter process happens inside [`generate_units`].
///
/// Not to be confused with [`Packages`], which opts in packages to be built.
///
/// [`generate_targets`]: super::generate_targets
/// [`generate_units`]: super::UnitGenerator::generate_units
/// [`Packages`]: crate::ops::Packages
#[derive(Debug)]
pub enum CompileFilter {
Expand Down Expand Up @@ -176,7 +176,7 @@ impl CompileFilter {
/// may include additional example targets to ensure they can be compiled.
///
/// Note that the actual behavior is subject to `filter_default_targets`
/// and `generate_targets` though.
/// and `generate_units` though.
pub fn all_test_targets() -> Self {
Self::Only {
all_targets: false,
Expand Down Expand Up @@ -234,7 +234,7 @@ impl CompileFilter {
}

/// Selects targets for "cargo run". for logic to select targets for other
/// subcommands, see `generate_targets` and `filter_default_targets`.
/// subcommands, see `generate_units` and `filter_default_targets`.
pub fn target_run(&self, target: &Target) -> bool {
match *self {
CompileFilter::Default { .. } => true,
Expand Down
Loading

0 comments on commit f6e737b

Please sign in to comment.