From bdefd588e4ccb67aaa04a37521a8fde91564c92f Mon Sep 17 00:00:00 2001 From: Inokentiy Babushkin Date: Sat, 15 Jun 2019 19:38:26 +0000 Subject: [PATCH] Implemented feature flag support. We now support `--features`, `--all-features` in addition to `--no-default-features`. This closes #91. --- src/bin/cargo_semver.rs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/bin/cargo_semver.rs b/src/bin/cargo_semver.rs index 267654f2b8f1d..60e99ac522402 100644 --- a/src/bin/cargo_semver.rs +++ b/src/bin/cargo_semver.rs @@ -121,10 +121,6 @@ fn run(config: &cargo::Config, matches: &getopts::Matches) -> Result<()> { child.args(&["--target", &target]); } - if !matches.opt_present("no-default-features") { - child.args(&["--cfg", "feature=\"default\""]); - } - let mut child = child .arg("-") .stdin(Stdio::piped()) @@ -207,10 +203,6 @@ fn run(config: &cargo::Config, matches: &getopts::Matches) -> Result<()> { child.args(&["--target", &target]); } - if !matches.opt_present("no-default-features") { - child.args(&["--cfg", "feature=\"default\""]); - } - let child = child .arg("-") .stdin(Stdio::piped()) @@ -284,6 +276,17 @@ mod cli { "api-guidelines", "report only changes that are breaking according to the API-guidelines", ); + opts.optopt( + "", + "features", + "Space-separated list of features to activate", + "FEATURES", + ); + opts.optflag( + "", + "all-features", + "Activate all available features", + ); opts.optflag( "", "no-default-features", @@ -458,9 +461,13 @@ impl<'a> WorkInfo<'a> { if let Some(target) = matches.opt_str("target") { opts.build_config.requested_target = Some(target); } - opts.no_default_features = matches.opt_present("no-default-features"); - // TODO: this is where we could insert feature flag builds (or using the CLI mechanisms) + if let Some(s) = matches.opt_str("features") { + opts.features = s.split(" ").map(str::to_owned).collect(); + } + + opts.all_features = matches.opt_present("all-features"); + opts.no_default_features = matches.opt_present("no-default-features"); env::set_var( "RUSTFLAGS",