Skip to content

Commit

Permalink
Do not ignore --features when --all-features is present
Browse files Browse the repository at this point in the history
This allows to specify dependency features when using `--all-features`,
for example:
```shell
$ cargo run --package a --example example --all-features --features="tracing/log"
```
  • Loading branch information
WaffleLapkin committed Jan 27, 2022
1 parent 8906474 commit 3d74ad8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 26 deletions.
12 changes: 6 additions & 6 deletions src/cargo/core/resolver/dep_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,14 @@ fn build_requirements<'a, 'b: 'a>(
return Err(e.into_activate_error(parent, s));
}
}
} else {
for fv in features.iter() {
if let Err(e) = reqs.require_value(fv) {
return Err(e.into_activate_error(parent, s));
}
}

for fv in features.iter() {
if let Err(e) = reqs.require_value(fv) {
return Err(e.into_activate_error(parent, s));
}
handle_default(*uses_default_features, &mut reqs)?;
}
handle_default(*uses_default_features, &mut reqs)?;
}
RequestedFeatures::DepFeatures {
features,
Expand Down
21 changes: 10 additions & 11 deletions src/cargo/core/resolver/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,19 +680,18 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
) -> Vec<FeatureValue> {
let summary = self.resolve.summary(pkg_id);
let feature_map = summary.features();

let mut result: Vec<FeatureValue> = cli_features.features.iter().cloned().collect();
let default = InternedString::new("default");
if cli_features.uses_default_features && feature_map.contains_key(&default) {
result.push(FeatureValue::Feature(default));
}

if cli_features.all_features {
feature_map
.keys()
.map(|k| FeatureValue::Feature(*k))
.collect()
} else {
let mut result: Vec<FeatureValue> = cli_features.features.iter().cloned().collect();
let default = InternedString::new("default");
if cli_features.uses_default_features && feature_map.contains_key(&default) {
result.push(FeatureValue::Feature(default));
}
result
result.extend(feature_map.keys().map(|k| FeatureValue::Feature(*k)))
}

result
}

/// Returns the dependencies for a package, filtering out inactive targets.
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ impl<'cfg> Workspace<'cfg> {
cli_features: &CliFeatures,
found_features: &mut BTreeSet<FeatureValue>,
) -> CliFeatures {
if cli_features.features.is_empty() || cli_features.all_features {
if cli_features.features.is_empty() {
return cli_features.clone();
}

Expand Down Expand Up @@ -1185,7 +1185,7 @@ impl<'cfg> Workspace<'cfg> {
}
CliFeatures {
features: Rc::new(features),
all_features: false,
all_features: cli_features.all_features,
uses_default_features: cli_features.uses_default_features,
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/cargo/ops/tree/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,12 @@ fn add_cli_features(
let mut to_add: HashSet<FeatureValue> = HashSet::new();
if cli_features.all_features {
to_add.extend(feature_map.keys().map(|feat| FeatureValue::Feature(*feat)));
} else {
if cli_features.uses_default_features {
to_add.insert(FeatureValue::Feature(InternedString::new("default")));
}
to_add.extend(cli_features.features.iter().cloned());
};
}

if cli_features.uses_default_features {
to_add.insert(FeatureValue::Feature(InternedString::new("default")));
}
to_add.extend(cli_features.features.iter().cloned());

// Add each feature as a node, and mark as "from command-line" in graph.cli_features.
for fv in to_add {
Expand Down
3 changes: 2 additions & 1 deletion tests/testsuite/features_namespaced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,8 @@ foo v0.1.0 ([ROOT]/foo)
bar v1.0.0
└── bar feature \"default\"
└── foo v0.1.0 ([ROOT]/foo)
└── foo feature \"a\" (command-line)
├── foo feature \"a\" (command-line)
└── foo feature \"default\" (command-line)
",
)
.run();
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/tree_graph_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ foo v0.1.0 ([..]/foo)
opt2 v1.0.0
└── opt2 feature \"default\"
└── foo v0.1.0 ([..]/foo)
├── foo feature \"default\" (command-line)
├── foo feature \"f1\" (command-line)
│ └── foo feature \"f2\" (command-line)
├── foo feature \"f2\" (command-line)
Expand Down

0 comments on commit 3d74ad8

Please sign in to comment.