Skip to content

Commit 54ace8a

Browse files
committed
Merge -Zpackage-features2 and -Zpackage-features.
1 parent c17bfcb commit 54ace8a

File tree

7 files changed

+79
-112
lines changed

7 files changed

+79
-112
lines changed

src/cargo/core/features.rs

-2
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ pub struct CliUnstable {
330330
pub avoid_dev_deps: bool,
331331
pub minimal_versions: bool,
332332
pub package_features: bool,
333-
pub package_features2: bool,
334333
pub advanced_env: bool,
335334
pub config_include: bool,
336335
pub dual_proc_macros: bool,
@@ -405,7 +404,6 @@ impl CliUnstable {
405404
"avoid-dev-deps" => self.avoid_dev_deps = parse_empty(k, v)?,
406405
"minimal-versions" => self.minimal_versions = parse_empty(k, v)?,
407406
"package-features" => self.package_features = parse_empty(k, v)?,
408-
"package-features2" => self.package_features2 = parse_empty(k, v)?,
409407
"advanced-env" => self.advanced_env = parse_empty(k, v)?,
410408
"config-include" => self.config_include = parse_empty(k, v)?,
411409
"dual-proc-macros" => self.dual_proc_macros = parse_empty(k, v)?,

src/cargo/core/workspace.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -878,36 +878,26 @@ impl<'cfg> Workspace<'cfg> {
878878
.map(|m| (m, RequestedFeatures::new_all(true)))
879879
.collect());
880880
}
881-
if self.config().cli_unstable().package_features
882-
|| self.config().cli_unstable().package_features2
883-
{
881+
if self.config().cli_unstable().package_features {
884882
self.members_with_features_pf(specs, requested_features)
885883
} else {
886884
self.members_with_features_stable(specs, requested_features)
887885
}
888886
}
889887

890-
/// New command-line feature selection with -Zpackage-features or -Zpackage-features2.
888+
/// New command-line feature selection with -Zpackage-features.
891889
fn members_with_features_pf(
892890
&self,
893891
specs: &[PackageIdSpec],
894892
requested_features: &RequestedFeatures,
895893
) -> CargoResult<Vec<(&Package, RequestedFeatures)>> {
896-
let pf2 = self.config().cli_unstable().package_features2;
897-
if specs.len() > 1 && !requested_features.features.is_empty() && !pf2 {
898-
anyhow::bail!("cannot specify features for more than one package");
899-
}
900894
// Keep track of which features matched *any* member, to produce an error
901895
// if any of them did not match anywhere.
902896
let mut found: BTreeSet<InternedString> = BTreeSet::new();
903897

904898
// Returns the requested features for the given member.
905899
// This filters out any named features that the member does not have.
906900
let mut matching_features = |member: &Package| -> RequestedFeatures {
907-
// This new behavior is only enabled for -Zpackage-features2
908-
if !pf2 {
909-
return requested_features.clone();
910-
}
911901
if requested_features.features.is_empty() || requested_features.all_features {
912902
return requested_features.clone();
913903
}
@@ -979,7 +969,7 @@ impl<'cfg> Workspace<'cfg> {
979969
.map(|m| (m, RequestedFeatures::new_all(false)))
980970
.collect());
981971
}
982-
if pf2 && *requested_features.features != found {
972+
if *requested_features.features != found {
983973
let missing: Vec<_> = requested_features
984974
.features
985975
.difference(&found)

src/cargo/util/command_prelude.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,7 @@ pub trait ArgMatchesExt {
288288
if config.cli_unstable().avoid_dev_deps {
289289
ws.set_require_optional_deps(false);
290290
}
291-
let unstable =
292-
config.cli_unstable().package_features || config.cli_unstable().package_features2;
293-
if ws.is_virtual() && !unstable {
291+
if ws.is_virtual() && !config.cli_unstable().package_features {
294292
// --all-features is actually honored. In general, workspaces and
295293
// feature flags are a bit of a mess right now.
296294
for flag in &["features", "no-default-features"] {

src/doc/src/reference/unstable.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -549,14 +549,14 @@ The available options are:
549549
* `compare` — This option compares the resolved features to the old resolver,
550550
and will print any differences.
551551

552-
### package-features2
553-
* Tracking Issue: TODO
552+
### package-features
553+
* Tracking Issue: [#5364](https://github.com/rust-lang/cargo/issues/5364)
554554

555-
The `-Zpackage-features2` flag changes the way features can be passed on the
555+
The `-Zpackage-features` flag changes the way features can be passed on the
556556
command-line for a workspace. The normal behavior can be confusing, as the
557557
features passed are always enabled on the package in the current directory,
558558
even if that package is not selected with a `-p` flag. Feature flags also do
559-
not work in the root of a virtual workspace. `-Zpackage-features2` tries to
559+
not work in the root of a virtual workspace. `-Zpackage-features` tries to
560560
make feature flags behave in a more intuitive manner.
561561

562562
* `cargo build -p other_member --features …` — This now only enables the given

tests/testsuite/features.rs

-74
Original file line numberDiff line numberDiff line change
@@ -1358,80 +1358,6 @@ fn many_cli_features_comma_and_space_delimited() {
13581358
.run();
13591359
}
13601360

1361-
#[cargo_test]
1362-
fn combining_features_and_package() {
1363-
Package::new("dep", "1.0.0").publish();
1364-
1365-
let p = project()
1366-
.file(
1367-
"Cargo.toml",
1368-
r#"
1369-
[project]
1370-
name = "foo"
1371-
version = "0.0.1"
1372-
authors = []
1373-
1374-
[workspace]
1375-
members = ["bar"]
1376-
1377-
[dependencies]
1378-
dep = "1"
1379-
"#,
1380-
)
1381-
.file("src/lib.rs", "")
1382-
.file(
1383-
"bar/Cargo.toml",
1384-
r#"
1385-
[package]
1386-
name = "bar"
1387-
version = "0.0.1"
1388-
authors = []
1389-
[features]
1390-
main = []
1391-
"#,
1392-
)
1393-
.file(
1394-
"bar/src/main.rs",
1395-
r#"
1396-
#[cfg(feature = "main")]
1397-
fn main() {}
1398-
"#,
1399-
)
1400-
.build();
1401-
1402-
p.cargo("build -Z package-features --workspace --features main")
1403-
.masquerade_as_nightly_cargo()
1404-
.with_status(101)
1405-
.with_stderr_contains("[ERROR] cannot specify features for more than one package")
1406-
.run();
1407-
1408-
p.cargo("build -Z package-features --package dep --features main")
1409-
.masquerade_as_nightly_cargo()
1410-
.with_status(101)
1411-
.with_stderr_contains("[ERROR] cannot specify features for packages outside of workspace")
1412-
.run();
1413-
p.cargo("build -Z package-features --package dep --all-features")
1414-
.masquerade_as_nightly_cargo()
1415-
.with_status(101)
1416-
.with_stderr_contains("[ERROR] cannot specify features for packages outside of workspace")
1417-
.run();
1418-
p.cargo("build -Z package-features --package dep --no-default-features")
1419-
.masquerade_as_nightly_cargo()
1420-
.with_status(101)
1421-
.with_stderr_contains("[ERROR] cannot specify features for packages outside of workspace")
1422-
.run();
1423-
1424-
p.cargo("build -Z package-features --workspace --all-features")
1425-
.masquerade_as_nightly_cargo()
1426-
.run();
1427-
p.cargo("run -Z package-features --package bar --features main")
1428-
.masquerade_as_nightly_cargo()
1429-
.run();
1430-
p.cargo("build -Z package-features --package dep")
1431-
.masquerade_as_nightly_cargo()
1432-
.run();
1433-
}
1434-
14351361
#[cargo_test]
14361362
fn namespaced_invalid_feature() {
14371363
let p = project()

tests/testsuite/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ mod offline;
7373
mod out_dir;
7474
mod owner;
7575
mod package;
76-
mod package_features2;
76+
mod package_features;
7777
mod patch;
7878
mod path;
7979
mod paths;

tests/testsuite/package_features2.rs renamed to tests/testsuite/package_features.rs

+70-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Tests for -Zpackage-features2
1+
//! Tests for -Zpackage-features
22
33
use cargo_test_support::registry::Package;
44
use cargo_test_support::{basic_manifest, project};
@@ -61,7 +61,7 @@ fn virtual_no_default_features() {
6161
)
6262
.run();
6363

64-
p.cargo("check --no-default-features -Zpackage-features2")
64+
p.cargo("check --no-default-features -Zpackage-features")
6565
.masquerade_as_nightly_cargo()
6666
.with_stderr_unordered(
6767
"\
@@ -73,13 +73,13 @@ fn virtual_no_default_features() {
7373
)
7474
.run();
7575

76-
p.cargo("check --features foo -Zpackage-features2")
76+
p.cargo("check --features foo -Zpackage-features")
7777
.masquerade_as_nightly_cargo()
7878
.with_status(101)
7979
.with_stderr("[ERROR] none of the selected packages contains these features: foo")
8080
.run();
8181

82-
p.cargo("check --features a/dep1,b/f1,b/f2,f2 -Zpackage-features2")
82+
p.cargo("check --features a/dep1,b/f1,b/f2,f2 -Zpackage-features")
8383
.masquerade_as_nightly_cargo()
8484
.with_status(101)
8585
.with_stderr("[ERROR] none of the selected packages contains these features: b/f2, f2")
@@ -129,7 +129,7 @@ fn virtual_features() {
129129
)
130130
.run();
131131

132-
p.cargo("check --features f1 -Zpackage-features2")
132+
p.cargo("check --features f1 -Zpackage-features")
133133
.masquerade_as_nightly_cargo()
134134
.with_stderr_unordered(
135135
"\
@@ -206,7 +206,7 @@ fn virtual_with_specific() {
206206
)
207207
.run();
208208

209-
p.cargo("check -p a -p b --features f1,f2,f3 -Zpackage-features2")
209+
p.cargo("check -p a -p b --features f1,f2,f3 -Zpackage-features")
210210
.masquerade_as_nightly_cargo()
211211
.with_stderr_unordered(
212212
"\
@@ -280,7 +280,7 @@ fn other_member_from_current() {
280280
.with_stdout("f3f4")
281281
.run();
282282

283-
p.cargo("run -p bar --features f1 -Zpackage-features2")
283+
p.cargo("run -p bar --features f1 -Zpackage-features")
284284
.masquerade_as_nightly_cargo()
285285
.with_stdout("f1")
286286
.run();
@@ -290,7 +290,7 @@ fn other_member_from_current() {
290290
.with_stderr("[ERROR] Package `foo[..]` does not have these features: `f2`")
291291
.run();
292292

293-
p.cargo("run -p bar --features f1,f2 -Zpackage-features2")
293+
p.cargo("run -p bar --features f1,f2 -Zpackage-features")
294294
.masquerade_as_nightly_cargo()
295295
.with_stdout("f1f2")
296296
.run();
@@ -299,7 +299,7 @@ fn other_member_from_current() {
299299
.with_stdout("f1f3")
300300
.run();
301301

302-
p.cargo("run -p bar --features bar/f1 -Zpackage-features2")
302+
p.cargo("run -p bar --features bar/f1 -Zpackage-features")
303303
.masquerade_as_nightly_cargo()
304304
.with_stdout("f1")
305305
.run();
@@ -375,43 +375,98 @@ fn virtual_member_slash() {
375375
)
376376
.run();
377377

378-
p.cargo("check -p a -Zpackage-features2")
378+
p.cargo("check -p a -Zpackage-features")
379379
.masquerade_as_nightly_cargo()
380380
.with_status(101)
381381
.with_stderr_contains("[..]f1 is set[..]")
382382
.with_stderr_does_not_contain("[..]f2 is set[..]")
383383
.with_stderr_does_not_contain("[..]b is set[..]")
384384
.run();
385385

386-
p.cargo("check -p a --features a/f1 -Zpackage-features2")
386+
p.cargo("check -p a --features a/f1 -Zpackage-features")
387387
.masquerade_as_nightly_cargo()
388388
.with_status(101)
389389
.with_stderr_contains("[..]f1 is set[..]")
390390
.with_stderr_does_not_contain("[..]f2 is set[..]")
391391
.with_stderr_does_not_contain("[..]b is set[..]")
392392
.run();
393393

394-
p.cargo("check -p a --features a/f2 -Zpackage-features2")
394+
p.cargo("check -p a --features a/f2 -Zpackage-features")
395395
.masquerade_as_nightly_cargo()
396396
.with_status(101)
397397
.with_stderr_contains("[..]f1 is set[..]")
398398
.with_stderr_contains("[..]f2 is set[..]")
399399
.with_stderr_does_not_contain("[..]b is set[..]")
400400
.run();
401401

402-
p.cargo("check -p a --features b/bfeat -Zpackage-features2")
402+
p.cargo("check -p a --features b/bfeat -Zpackage-features")
403403
.masquerade_as_nightly_cargo()
404404
.with_status(101)
405405
.with_stderr_contains("[..]bfeat is set[..]")
406406
.run();
407407

408-
p.cargo("check -p a --no-default-features -Zpackage-features2")
408+
p.cargo("check -p a --no-default-features -Zpackage-features")
409409
.masquerade_as_nightly_cargo()
410410
.run();
411411

412-
p.cargo("check -p a --no-default-features --features b -Zpackage-features2")
412+
p.cargo("check -p a --no-default-features --features b -Zpackage-features")
413413
.masquerade_as_nightly_cargo()
414414
.with_status(101)
415415
.with_stderr_contains("[..]b is set[..]")
416416
.run();
417417
}
418+
419+
#[cargo_test]
420+
fn non_member() {
421+
// -p for a non-member
422+
Package::new("dep", "1.0.0").publish();
423+
let p = project()
424+
.file(
425+
"Cargo.toml",
426+
r#"
427+
[package]
428+
name = "foo"
429+
version = "0.1.0"
430+
431+
[dependencies]
432+
dep = "1.0"
433+
434+
[features]
435+
f1 = []
436+
"#,
437+
)
438+
.file("src/lib.rs", "")
439+
.build();
440+
441+
p.cargo("build -Zpackage-features -p dep --features f1")
442+
.masquerade_as_nightly_cargo()
443+
.with_status(101)
444+
.with_stderr(
445+
"[UPDATING][..]\n[ERROR] cannot specify features for packages outside of workspace",
446+
)
447+
.run();
448+
449+
p.cargo("build -Zpackage-features -p dep --all-features")
450+
.masquerade_as_nightly_cargo()
451+
.with_status(101)
452+
.with_stderr("[ERROR] cannot specify features for packages outside of workspace")
453+
.run();
454+
455+
p.cargo("build -Zpackage-features -p dep --no-default-features")
456+
.masquerade_as_nightly_cargo()
457+
.with_status(101)
458+
.with_stderr("[ERROR] cannot specify features for packages outside of workspace")
459+
.run();
460+
461+
p.cargo("build -Zpackage-features -p dep")
462+
.masquerade_as_nightly_cargo()
463+
.with_stderr(
464+
"\
465+
[DOWNLOADING] [..]
466+
[DOWNLOADED] [..]
467+
[COMPILING] dep [..]
468+
[FINISHED] [..]
469+
",
470+
)
471+
.run();
472+
}

0 commit comments

Comments
 (0)