mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Adjust -Zcheck-cfg for new rustc syntax and behavior
This commit removes all the -Zcheck-cfg options (features, names, values, output), as they don't make much sense now since features, names and values are all combine together for upstream rustc and the output option was only here because the other were. Now the new behavior from cargo is to always pass one `--check-cfg` argument to rustc for the `feature`s which implicitly enables well known names and values.
This commit is contained in:
parent
a275529de2
commit
4b93690c9d
@ -403,10 +403,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
|
|||||||
paths::create_dir_all(&script_out_dir)?;
|
paths::create_dir_all(&script_out_dir)?;
|
||||||
|
|
||||||
let nightly_features_allowed = cx.bcx.config.nightly_features_allowed;
|
let nightly_features_allowed = cx.bcx.config.nightly_features_allowed;
|
||||||
let extra_check_cfg = match cx.bcx.config.cli_unstable().check_cfg {
|
let extra_check_cfg = cx.bcx.config.cli_unstable().check_cfg;
|
||||||
Some((_, _, _, output)) => output,
|
|
||||||
None => false,
|
|
||||||
};
|
|
||||||
let targets: Vec<Target> = unit.pkg.targets().to_vec();
|
let targets: Vec<Target> = unit.pkg.targets().to_vec();
|
||||||
// Need a separate copy for the fresh closure.
|
// Need a separate copy for the fresh closure.
|
||||||
let targets_fresh = targets.clone();
|
let targets_fresh = targets.clone();
|
||||||
@ -1126,10 +1123,7 @@ fn prev_build_output(cx: &mut Context<'_, '_>, unit: &Unit) -> (Option<BuildOutp
|
|||||||
&unit.pkg.to_string(),
|
&unit.pkg.to_string(),
|
||||||
&prev_script_out_dir,
|
&prev_script_out_dir,
|
||||||
&script_out_dir,
|
&script_out_dir,
|
||||||
match cx.bcx.config.cli_unstable().check_cfg {
|
cx.bcx.config.cli_unstable().check_cfg,
|
||||||
Some((_, _, _, output)) => output,
|
|
||||||
None => false,
|
|
||||||
},
|
|
||||||
cx.bcx.config.nightly_features_allowed,
|
cx.bcx.config.nightly_features_allowed,
|
||||||
unit.pkg.targets(),
|
unit.pkg.targets(),
|
||||||
)
|
)
|
||||||
|
@ -1167,39 +1167,32 @@ fn features_args(unit: &Unit) -> Vec<OsString> {
|
|||||||
///
|
///
|
||||||
/// [`check-cfg`]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg
|
/// [`check-cfg`]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg
|
||||||
fn check_cfg_args(cx: &Context<'_, '_>, unit: &Unit) -> Vec<OsString> {
|
fn check_cfg_args(cx: &Context<'_, '_>, unit: &Unit) -> Vec<OsString> {
|
||||||
if let Some((features, well_known_names, well_known_values, _output)) =
|
if cx.bcx.config.cli_unstable().check_cfg {
|
||||||
cx.bcx.config.cli_unstable().check_cfg
|
|
||||||
{
|
|
||||||
let mut args = Vec::with_capacity(unit.pkg.summary().features().len() * 2 + 4);
|
|
||||||
args.push(OsString::from("-Zunstable-options"));
|
|
||||||
|
|
||||||
if features {
|
|
||||||
// This generate something like this:
|
// This generate something like this:
|
||||||
// - values(feature)
|
// - cfg(feature, values())
|
||||||
// - values(feature, "foo", "bar")
|
// - cfg(feature, values("foo", "bar"))
|
||||||
let mut arg = OsString::from("values(feature");
|
//
|
||||||
for (&feat, _) in unit.pkg.summary().features() {
|
// NOTE: Despite only explicitly specifying `feature`, well known names and values
|
||||||
arg.push(", \"");
|
// are implicitly enabled when one or more `--check-cfg` argument is passed.
|
||||||
arg.push(&feat);
|
|
||||||
arg.push("\"");
|
|
||||||
}
|
|
||||||
arg.push(")");
|
|
||||||
|
|
||||||
args.push(OsString::from("--check-cfg"));
|
let gross_cap_estimation = unit.pkg.summary().features().len() * 7 + 25;
|
||||||
args.push(arg);
|
let mut arg_feature = OsString::with_capacity(gross_cap_estimation);
|
||||||
|
arg_feature.push("cfg(feature, values(");
|
||||||
|
for (i, feature) in unit.pkg.summary().features().keys().enumerate() {
|
||||||
|
if i != 0 {
|
||||||
|
arg_feature.push(", ");
|
||||||
}
|
}
|
||||||
|
arg_feature.push("\"");
|
||||||
if well_known_names {
|
arg_feature.push(feature);
|
||||||
args.push(OsString::from("--check-cfg"));
|
arg_feature.push("\"");
|
||||||
args.push(OsString::from("names()"));
|
|
||||||
}
|
}
|
||||||
|
arg_feature.push("))");
|
||||||
|
|
||||||
if well_known_values {
|
vec![
|
||||||
args.push(OsString::from("--check-cfg"));
|
OsString::from("-Zunstable-options"),
|
||||||
args.push(OsString::from("values()"));
|
OsString::from("--check-cfg"),
|
||||||
}
|
arg_feature,
|
||||||
|
]
|
||||||
args
|
|
||||||
} else {
|
} else {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
}
|
}
|
||||||
|
@ -731,8 +731,7 @@ unstable_cli_options!(
|
|||||||
#[serde(deserialize_with = "deserialize_build_std")]
|
#[serde(deserialize_with = "deserialize_build_std")]
|
||||||
build_std: Option<Vec<String>> = ("Enable Cargo to compile the standard library itself as part of a crate graph compilation"),
|
build_std: Option<Vec<String>> = ("Enable Cargo to compile the standard library itself as part of a crate graph compilation"),
|
||||||
build_std_features: Option<Vec<String>> = ("Configure features enabled for the standard library itself when building the standard library"),
|
build_std_features: Option<Vec<String>> = ("Configure features enabled for the standard library itself when building the standard library"),
|
||||||
#[serde(deserialize_with = "deserialize_check_cfg")]
|
check_cfg: bool = ("Enable compile-time checking of `cfg` names/values/features"),
|
||||||
check_cfg: Option<(/*features:*/ bool, /*well_known_names:*/ bool, /*well_known_values:*/ bool, /*output:*/ bool)> = ("Specify scope of compile-time checking of `cfg` names/values"),
|
|
||||||
codegen_backend: bool = ("Enable the `codegen-backend` option in profiles in .cargo/config.toml file"),
|
codegen_backend: bool = ("Enable the `codegen-backend` option in profiles in .cargo/config.toml file"),
|
||||||
config_include: bool = ("Enable the `include` key in config files"),
|
config_include: bool = ("Enable the `include` key in config files"),
|
||||||
direct_minimal_versions: bool = ("Resolve minimal dependency versions instead of maximum (direct dependencies only)"),
|
direct_minimal_versions: bool = ("Resolve minimal dependency versions instead of maximum (direct dependencies only)"),
|
||||||
@ -842,20 +841,6 @@ where
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_check_cfg<'de, D>(
|
|
||||||
deserializer: D,
|
|
||||||
) -> Result<Option<(bool, bool, bool, bool)>, D::Error>
|
|
||||||
where
|
|
||||||
D: serde::Deserializer<'de>,
|
|
||||||
{
|
|
||||||
use serde::de::Error;
|
|
||||||
let Some(crates) = <Option<Vec<String>>>::deserialize(deserializer)? else {
|
|
||||||
return Ok(None);
|
|
||||||
};
|
|
||||||
|
|
||||||
parse_check_cfg(crates.into_iter()).map_err(D::Error::custom)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Default, Deserialize)]
|
#[derive(Debug, Copy, Clone, Default, Deserialize)]
|
||||||
pub struct GitoxideFeatures {
|
pub struct GitoxideFeatures {
|
||||||
/// All fetches are done with `gitoxide`, which includes git dependencies as well as the crates index.
|
/// All fetches are done with `gitoxide`, which includes git dependencies as well as the crates index.
|
||||||
@ -924,32 +909,6 @@ fn parse_gitoxide(
|
|||||||
Ok(Some(out))
|
Ok(Some(out))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_check_cfg(
|
|
||||||
it: impl Iterator<Item = impl AsRef<str>>,
|
|
||||||
) -> CargoResult<Option<(bool, bool, bool, bool)>> {
|
|
||||||
let mut features = false;
|
|
||||||
let mut well_known_names = false;
|
|
||||||
let mut well_known_values = false;
|
|
||||||
let mut output = false;
|
|
||||||
|
|
||||||
for e in it {
|
|
||||||
match e.as_ref() {
|
|
||||||
"features" => features = true,
|
|
||||||
"names" => well_known_names = true,
|
|
||||||
"values" => well_known_values = true,
|
|
||||||
"output" => output = true,
|
|
||||||
_ => bail!("unstable check-cfg only takes `features`, `names`, `values` or `output` as valid inputs"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Some((
|
|
||||||
features,
|
|
||||||
well_known_names,
|
|
||||||
well_known_values,
|
|
||||||
output,
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CliUnstable {
|
impl CliUnstable {
|
||||||
pub fn parse(
|
pub fn parse(
|
||||||
&mut self,
|
&mut self,
|
||||||
@ -1107,7 +1066,7 @@ impl CliUnstable {
|
|||||||
}
|
}
|
||||||
"build-std-features" => self.build_std_features = Some(parse_features(v)),
|
"build-std-features" => self.build_std_features = Some(parse_features(v)),
|
||||||
"check-cfg" => {
|
"check-cfg" => {
|
||||||
self.check_cfg = v.map_or(Ok(None), |v| parse_check_cfg(v.split(',')))?
|
self.check_cfg = parse_empty(k, v)?;
|
||||||
}
|
}
|
||||||
"codegen-backend" => self.codegen_backend = parse_empty(k, v)?,
|
"codegen-backend" => self.codegen_backend = parse_empty(k, v)?,
|
||||||
"config-include" => self.config_include = parse_empty(k, v)?,
|
"config-include" => self.config_include = parse_empty(k, v)?,
|
||||||
|
@ -137,10 +137,6 @@ fn parse_links_overrides(
|
|||||||
config: &Config,
|
config: &Config,
|
||||||
) -> CargoResult<BTreeMap<String, BuildOutput>> {
|
) -> CargoResult<BTreeMap<String, BuildOutput>> {
|
||||||
let mut links_overrides = BTreeMap::new();
|
let mut links_overrides = BTreeMap::new();
|
||||||
let extra_check_cfg = match config.cli_unstable().check_cfg {
|
|
||||||
Some((_, _, _, output)) => output,
|
|
||||||
None => false,
|
|
||||||
};
|
|
||||||
|
|
||||||
for (lib_name, value) in links {
|
for (lib_name, value) in links {
|
||||||
// Skip these keys, it shares the namespace with `TargetConfig`.
|
// Skip these keys, it shares the namespace with `TargetConfig`.
|
||||||
@ -207,7 +203,7 @@ fn parse_links_overrides(
|
|||||||
output.cfgs.extend(list.iter().map(|v| v.0.clone()));
|
output.cfgs.extend(list.iter().map(|v| v.0.clone()));
|
||||||
}
|
}
|
||||||
"rustc-check-cfg" => {
|
"rustc-check-cfg" => {
|
||||||
if extra_check_cfg {
|
if config.cli_unstable().check_cfg {
|
||||||
let list = value.list(key)?;
|
let list = value.list(key)?;
|
||||||
output.check_cfgs.extend(list.iter().map(|v| v.0.clone()));
|
output.check_cfgs.extend(list.iter().map(|v| v.0.clone()));
|
||||||
} else {
|
} else {
|
||||||
|
@ -15,16 +15,16 @@ macro_rules! x {
|
|||||||
$what, '(', $($who,)* ')', "'", "[..]")
|
$what, '(', $($who,)* ')', "'", "[..]")
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
($tool:tt => $what:tt of $who:tt with $($values:tt)*) => {{
|
($tool:tt => $what:tt of $who:tt with $($first_value:tt $($other_values:tt)*)?) => {{
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
concat!("[RUNNING] [..]", $tool, "[..] --check-cfg \"",
|
concat!("[RUNNING] [..]", $tool, "[..] --check-cfg \"",
|
||||||
$what, '(', $who, $(", ", "/\"", $values, "/\"",)* ")", '"', "[..]")
|
$what, '(', $who, ", values(", $("/\"", $first_value, "/\"", $(", ", "/\"", $other_values, "/\"",)*)* "))", '"', "[..]")
|
||||||
}
|
}
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
{
|
{
|
||||||
concat!("[RUNNING] [..]", $tool, "[..] --check-cfg '",
|
concat!("[RUNNING] [..]", $tool, "[..] --check-cfg '",
|
||||||
$what, '(', $who, $(", ", "\"", $values, "\"",)* ")", "'", "[..]")
|
$what, '(', $who, ", values(", $("\"", $first_value, "\"", $(", ", "\"", $other_values, "\"",)*)* "))", "'", "[..]")
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
@ -47,9 +47,9 @@ fn features() {
|
|||||||
.file("src/main.rs", "fn main() {}")
|
.file("src/main.rs", "fn main() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg=features")
|
p.cargo("check -v -Zcheck-cfg")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||||
.with_stderr_contains(x!("rustc" => "values" of "feature" with "f_a" "f_b"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,10 +76,9 @@ fn features_with_deps() {
|
|||||||
.file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}")
|
.file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg=features")
|
p.cargo("check -v -Zcheck-cfg")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||||
.with_stderr_contains(x!("rustc" => "values" of "feature"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
||||||
.with_stderr_contains(x!("rustc" => "values" of "feature" with "f_a" "f_b"))
|
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,10 +106,9 @@ fn features_with_opt_deps() {
|
|||||||
.file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}")
|
.file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg=features")
|
p.cargo("check -v -Zcheck-cfg")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||||
.with_stderr_contains(x!("rustc" => "values" of "feature"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "bar" "default" "f_a" "f_b"))
|
||||||
.with_stderr_contains(x!("rustc" => "values" of "feature" with "bar" "default" "f_a" "f_b"))
|
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,111 +135,22 @@ fn features_with_namespaced_features() {
|
|||||||
.file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}")
|
.file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg=features")
|
p.cargo("check -v -Zcheck-cfg")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||||
.with_stderr_contains(x!("rustc" => "values" of "feature" with "f_a" "f_b"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
||||||
fn well_known_names() {
|
fn well_known_names_values() {
|
||||||
let p = project()
|
let p = project()
|
||||||
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
||||||
.file("src/main.rs", "fn main() {}")
|
.file("src/main.rs", "fn main() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg=names")
|
p.cargo("check -v -Zcheck-cfg")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||||
.with_stderr_contains(x!("rustc" => "names"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
|
||||||
.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
|
||||||
fn well_known_values() {
|
|
||||||
let p = project()
|
|
||||||
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
|
||||||
.file("src/main.rs", "fn main() {}")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg=values")
|
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_contains(x!("rustc" => "values"))
|
|
||||||
.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
|
||||||
fn cli_all_options() {
|
|
||||||
let p = project()
|
|
||||||
.file(
|
|
||||||
"Cargo.toml",
|
|
||||||
r#"
|
|
||||||
[package]
|
|
||||||
name = "foo"
|
|
||||||
version = "0.1.0"
|
|
||||||
|
|
||||||
[features]
|
|
||||||
f_a = []
|
|
||||||
f_b = []
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.file("src/main.rs", "fn main() {}")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg=features,names,values")
|
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_contains(x!("rustc" => "names"))
|
|
||||||
.with_stderr_contains(x!("rustc" => "values"))
|
|
||||||
.with_stderr_contains(x!("rustc" => "values" of "feature" with "f_a" "f_b"))
|
|
||||||
.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
|
||||||
fn features_with_cargo_check() {
|
|
||||||
let p = project()
|
|
||||||
.file(
|
|
||||||
"Cargo.toml",
|
|
||||||
r#"
|
|
||||||
[package]
|
|
||||||
name = "foo"
|
|
||||||
version = "0.1.0"
|
|
||||||
|
|
||||||
[features]
|
|
||||||
f_a = []
|
|
||||||
f_b = []
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.file("src/main.rs", "fn main() {}")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg=features")
|
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_contains(x!("rustc" => "values" of "feature" with "f_a" "f_b"))
|
|
||||||
.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
|
||||||
fn well_known_names_with_check() {
|
|
||||||
let p = project()
|
|
||||||
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
|
||||||
.file("src/main.rs", "fn main() {}")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg=names")
|
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_contains(x!("rustc" => "names"))
|
|
||||||
.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
|
||||||
fn well_known_values_with_check() {
|
|
||||||
let p = project()
|
|
||||||
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
|
||||||
.file("src/main.rs", "fn main() {}")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg=values")
|
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_contains(x!("rustc" => "values"))
|
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,9 +172,9 @@ fn features_test() {
|
|||||||
.file("src/main.rs", "fn main() {}")
|
.file("src/main.rs", "fn main() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("test -v -Zcheck-cfg=features")
|
p.cargo("test -v -Zcheck-cfg")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||||
.with_stderr_contains(x!("rustc" => "values" of "feature" with "f_a" "f_b"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,64 +197,37 @@ fn features_doctest() {
|
|||||||
.file("src/lib.rs", "#[allow(dead_code)] fn foo() {}")
|
.file("src/lib.rs", "#[allow(dead_code)] fn foo() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("test -v --doc -Zcheck-cfg=features")
|
p.cargo("test -v --doc -Zcheck-cfg")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||||
.with_stderr_contains(x!("rustc" => "values" of "feature" with "default" "f_a" "f_b"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "default" "f_a" "f_b"))
|
||||||
.with_stderr_contains(x!("rustdoc" => "values" of "feature" with "default" "f_a" "f_b"))
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b"))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
||||||
fn well_known_names_test() {
|
fn well_known_names_values_test() {
|
||||||
let p = project()
|
let p = project()
|
||||||
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
||||||
.file("src/main.rs", "fn main() {}")
|
.file("src/main.rs", "fn main() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("test -v -Zcheck-cfg=names")
|
p.cargo("test -v -Zcheck-cfg")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||||
.with_stderr_contains(x!("rustc" => "names"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
||||||
fn well_known_values_test() {
|
fn well_known_names_values_doctest() {
|
||||||
let p = project()
|
|
||||||
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
|
||||||
.file("src/main.rs", "fn main() {}")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
p.cargo("test -v -Zcheck-cfg=values")
|
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_contains(x!("rustc" => "values"))
|
|
||||||
.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
|
||||||
fn well_known_names_doctest() {
|
|
||||||
let p = project()
|
let p = project()
|
||||||
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
||||||
.file("src/lib.rs", "#[allow(dead_code)] fn foo() {}")
|
.file("src/lib.rs", "#[allow(dead_code)] fn foo() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("test -v --doc -Zcheck-cfg=names")
|
p.cargo("test -v --doc -Zcheck-cfg")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||||
.with_stderr_contains(x!("rustc" => "names"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
|
||||||
.with_stderr_contains(x!("rustdoc" => "names"))
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with))
|
||||||
.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
|
||||||
fn well_known_values_doctest() {
|
|
||||||
let p = project()
|
|
||||||
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
|
||||||
.file("src/lib.rs", "#[allow(dead_code)] fn foo() {}")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
p.cargo("test -v --doc -Zcheck-cfg=values")
|
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_contains(x!("rustc" => "values"))
|
|
||||||
.with_stderr_contains(x!("rustdoc" => "values"))
|
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,9 +250,9 @@ fn features_doc() {
|
|||||||
.file("src/lib.rs", "#[allow(dead_code)] fn foo() {}")
|
.file("src/lib.rs", "#[allow(dead_code)] fn foo() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("doc -v -Zcheck-cfg=features")
|
p.cargo("doc -v -Zcheck-cfg")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||||
.with_stderr_contains(x!("rustdoc" => "values" of "feature" with "default" "f_a" "f_b"))
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b"))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,13 +272,13 @@ fn build_script_feedback() {
|
|||||||
.file("src/main.rs", "fn main() {}")
|
.file("src/main.rs", "fn main() {}")
|
||||||
.file(
|
.file(
|
||||||
"build.rs",
|
"build.rs",
|
||||||
r#"fn main() { println!("cargo:rustc-check-cfg=names(foo)"); }"#,
|
r#"fn main() { println!("cargo:rustc-check-cfg=cfg(foo)"); }"#,
|
||||||
)
|
)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg=output")
|
p.cargo("check -v -Zcheck-cfg")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||||
.with_stderr_contains(x!("rustc" => "names" of "foo"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,12 +298,13 @@ fn build_script_doc() {
|
|||||||
.file("src/main.rs", "fn main() {}")
|
.file("src/main.rs", "fn main() {}")
|
||||||
.file(
|
.file(
|
||||||
"build.rs",
|
"build.rs",
|
||||||
r#"fn main() { println!("cargo:rustc-check-cfg=names(foo)"); }"#,
|
r#"fn main() { println!("cargo:rustc-check-cfg=cfg(foo)"); }"#,
|
||||||
)
|
)
|
||||||
.build();
|
.build();
|
||||||
p.cargo("doc -v -Zcheck-cfg=output")
|
|
||||||
|
p.cargo("doc -v -Zcheck-cfg")
|
||||||
.with_stderr_does_not_contain("rustc [..] --check-cfg [..]")
|
.with_stderr_does_not_contain("rustc [..] --check-cfg [..]")
|
||||||
.with_stderr_contains(x!("rustdoc" => "names" of "foo"))
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "foo"))
|
||||||
.with_stderr(
|
.with_stderr(
|
||||||
"\
|
"\
|
||||||
[COMPILING] foo v0.0.1 ([CWD])
|
[COMPILING] foo v0.0.1 ([CWD])
|
||||||
@ -458,15 +341,15 @@ fn build_script_override() {
|
|||||||
&format!(
|
&format!(
|
||||||
r#"
|
r#"
|
||||||
[target.{}.a]
|
[target.{}.a]
|
||||||
rustc-check-cfg = ["names(foo)"]
|
rustc-check-cfg = ["cfg(foo)"]
|
||||||
"#,
|
"#,
|
||||||
target
|
target
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg=output")
|
p.cargo("check -v -Zcheck-cfg")
|
||||||
.with_stderr_contains(x!("rustc" => "names" of "foo"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
@ -487,7 +370,7 @@ fn build_script_test() {
|
|||||||
.file(
|
.file(
|
||||||
"build.rs",
|
"build.rs",
|
||||||
r#"fn main() {
|
r#"fn main() {
|
||||||
println!("cargo:rustc-check-cfg=names(foo)");
|
println!("cargo:rustc-check-cfg=cfg(foo)");
|
||||||
println!("cargo:rustc-cfg=foo");
|
println!("cargo:rustc-cfg=foo");
|
||||||
}"#,
|
}"#,
|
||||||
)
|
)
|
||||||
@ -516,9 +399,9 @@ fn build_script_test() {
|
|||||||
.file("tests/test.rs", "#[cfg(foo)] #[test] fn test_bar() {}")
|
.file("tests/test.rs", "#[cfg(foo)] #[test] fn test_bar() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("test -v -Zcheck-cfg=output")
|
p.cargo("test -v -Zcheck-cfg")
|
||||||
.with_stderr_contains(x!("rustc" => "names" of "foo"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
|
||||||
.with_stderr_contains(x!("rustdoc" => "names" of "foo"))
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "foo"))
|
||||||
.with_stdout_contains("test test_foo ... ok")
|
.with_stdout_contains("test test_foo ... ok")
|
||||||
.with_stdout_contains("test test_bar ... ok")
|
.with_stdout_contains("test test_bar ... ok")
|
||||||
.with_stdout_contains_n("test [..] ... ok", 3)
|
.with_stdout_contains_n("test [..] ... ok", 3)
|
||||||
@ -546,16 +429,14 @@ fn config_valid() {
|
|||||||
".cargo/config.toml",
|
".cargo/config.toml",
|
||||||
r#"
|
r#"
|
||||||
[unstable]
|
[unstable]
|
||||||
check-cfg = ["features", "names", "values"]
|
check-cfg = true
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg=features,names,values")
|
p.cargo("check -v")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||||
.with_stderr_contains(x!("rustc" => "names"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
||||||
.with_stderr_contains(x!("rustc" => "values"))
|
|
||||||
.with_stderr_contains(x!("rustc" => "values" of "feature" with "f_a" "f_b"))
|
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -582,7 +463,7 @@ fn config_invalid() {
|
|||||||
|
|
||||||
p.cargo("check")
|
p.cargo("check")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||||
.with_stderr_contains("error: unstable check-cfg only takes `features`, `names`, `values` or `output` as valid inputs")
|
.with_stderr_contains("error:[..]`unstable.check-cfg` expected true/false[..]")
|
||||||
.with_status(101)
|
.with_status(101)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user