Skip to content

Commit 74dc25f

Browse files
David Tolnayfacebook-github-bot
authored andcommitted
Account for 'cfgs' fixups when evaluating conditional dependencies
Summary: I need this for the `windows-targets` crate. Version 0.53.3 in microsoft/windows-rs#3670 introduced the following conditional dependency: ```lang=toml [target.'cfg(windows_raw_dylib)'.dependencies] windows-link = { version = "0.1.3", default-features = false } ``` If a project were to use a fixup like this: ```lang=toml # fixups/windows-targets/fixups.toml cfgs = ["windows_raw_dylib"] ``` then Reindeer needs to know that the `windows-link` dependency applies. Previously, the `cfg(…)` predicate in conditional dependencies was only evaluated based on the cfgs of the platform according to reindeer.toml. Reviewed By: diliop Differential Revision: D80892198 fbshipit-source-id: a0567e99fb97fd8f3cb3fce21334743aacc75381
1 parent 5c31da0 commit 74dc25f

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

src/fixups.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ impl<'meta> Fixups<'meta> {
148148
if fixup.platform.eval(
149149
&self.config.platform[platform_name],
150150
Some(&self.package.version),
151+
&BTreeSet::new(),
151152
) {
152153
configs.push(fixup);
153154
}

src/index.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,11 @@ impl<'a, 'meta> FeatureResolver<'a, 'meta> {
422422
DepKind::Dev => false,
423423
}
424424
&& match &manifest_dep.target {
425-
Some(platform_expr) => {
426-
platform_expr.eval(&self.config.platform[platform_name], None)
427-
}
425+
Some(platform_expr) => platform_expr.eval(
426+
&self.config.platform[platform_name],
427+
None,
428+
&fixups.compute_rustc_cfg(platform_name),
429+
),
428430
None => true,
429431
}
430432
&& !fixups.omit_dep(
@@ -514,8 +516,11 @@ impl<'a, 'meta> FeatureResolver<'a, 'meta> {
514516
DepKind::Dev => false,
515517
}
516518
&& match &manifest_dep.target {
517-
Some(platform_expr) => platform_expr
518-
.eval(&self.config.platform[platform_name], None),
519+
Some(platform_expr) => platform_expr.eval(
520+
&self.config.platform[platform_name],
521+
None,
522+
&fixups.compute_rustc_cfg(platform_name),
523+
),
519524
None => true,
520525
}
521526
{
@@ -597,9 +602,11 @@ impl<'a, 'meta> FeatureResolver<'a, 'meta> {
597602
DepKind::Dev => false,
598603
}
599604
&& match &manifest_dep.target {
600-
Some(platform_expr) => {
601-
platform_expr.eval(&self.config.platform[platform_name], None)
602-
}
605+
Some(platform_expr) => platform_expr.eval(
606+
&self.config.platform[platform_name],
607+
None,
608+
&fixups.compute_rustc_cfg(platform_name),
609+
),
603610
None => true,
604611
}
605612
{

src/platform.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,14 @@ impl PlatformExpr {
275275
Err(anyhow::Error::new(err).context(format!("Bad platform expression `{input}`")))
276276
}
277277

278-
pub fn eval(&self, config: &PlatformConfig, version: Option<&Version>) -> bool {
278+
pub fn eval(
279+
&self,
280+
config: &PlatformConfig,
281+
version: Option<&Version>,
282+
extra_cfg: &BTreeSet<String>,
283+
) -> bool {
279284
match self {
280-
PlatformExpr::Bool { key } => config.cfg.contains_key(key),
285+
PlatformExpr::Bool { key } => config.cfg.contains_key(key) || extra_cfg.contains(key),
281286
PlatformExpr::Value { key, value } => {
282287
if key == "feature" {
283288
// [target.'cfg(feature = "...")'.dependencies] never get applied by Cargo
@@ -291,19 +296,23 @@ impl PlatformExpr {
291296
Some(version) => req.matches(version),
292297
},
293298
PlatformExpr::Target(target) => config.target.as_ref() == Some(target),
294-
PlatformExpr::Not(pred) => !pred.eval(config, version),
295-
PlatformExpr::Any(preds) => preds.iter().any(|pred| pred.eval(config, version)),
296-
PlatformExpr::All(preds) => preds.iter().all(|pred| pred.eval(config, version)),
299+
PlatformExpr::Not(pred) => !pred.eval(config, version, extra_cfg),
300+
PlatformExpr::Any(preds) => preds
301+
.iter()
302+
.any(|pred| pred.eval(config, version, extra_cfg)),
303+
PlatformExpr::All(preds) => preds
304+
.iter()
305+
.all(|pred| pred.eval(config, version, extra_cfg)),
297306
PlatformExpr::Unix => PlatformExpr::Value {
298307
key: "target_family".to_owned(),
299308
value: "unix".to_owned(),
300309
}
301-
.eval(config, version),
310+
.eval(config, version, extra_cfg),
302311
PlatformExpr::Windows => PlatformExpr::Value {
303312
key: "target_family".to_owned(),
304313
value: "windows".to_owned(),
305314
}
306-
.eval(config, version),
315+
.eval(config, version, extra_cfg),
307316
}
308317
}
309318
}

0 commit comments

Comments
 (0)