From 253b030ca731d4d126ed19566a59e9de3d5807a1 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Sat, 14 Nov 2026 22:46:14 -0500 Subject: [PATCH] Adding or dropping a strings table is a binary change on Apple platforms --- bake/src/compat.rs | 14 ++++++++++ bake/src/reach_grant_lines_tests.rs | 40 +++++++++++++++++++++++++++++ bake/src/receipt.rs | 4 +++ bake/src/receipt/tests.rs | 16 ++++++++++++ docs/contract-for-agents.md | 4 ++- 5 files changed, 77 insertions(+), 1 deletion(-) diff --git a/bake/src/compat.rs b/bake/src/compat.rs index 66a4f14a2..c0efbf96e 100644 --- a/bake/src/compat.rs +++ b/bake/src/compat.rs @@ -380,6 +380,7 @@ pub fn compatibility_id_pinned( } } crate::reach::derive(app_dir, platform, plan.as_ref(), &mut compat)?; + localizations(platform, &mut compat); if target.contains("android") { crate::channels::derive(app_dir, &manifest.json, &mut compat)?; } @@ -479,6 +480,19 @@ fn source_scopes(compat: &mut Compat, javascript: &str, rust: &str) { compat.id = compatibility_digest(&compat.inputs); } +/// The Apple Info.plist names the app's languages (`localizationKeys` in +/// `host/apple/build.mjs`, from `reach.locales`), so adding or dropping a table +/// is a binary change; a translation's text is not. An app with one table keeps +/// the id it had. +pub(crate) fn localizations(platform: &str, compat: &mut Compat) { + let tables = compat.reach["locales"].as_array().map_or(0, Vec::len); + if tables > 1 && matches!(platform, "ios" | "macos") { + compat.inputs["localizations"] = + serde_json::json!({"base": compat.reach["base"], "locales": compat.reach["locales"]}); + compat.id = compatibility_digest(&compat.inputs); + } +} + pub(crate) fn compatibility_digest(inputs: &serde_json::Value) -> String { let mut canon = String::new(); canonical(inputs, &mut canon); diff --git a/bake/src/reach_grant_lines_tests.rs b/bake/src/reach_grant_lines_tests.rs index 76ae99477..a55776bcf 100644 --- a/bake/src/reach_grant_lines_tests.rs +++ b/bake/src/reach_grant_lines_tests.rs @@ -186,3 +186,43 @@ fn apple_metadata_advice_emits_the_key_on_the_named_bundle() { ); print!("{output}"); } + +/// The languages the Apple Info.plist names move the id where the plist names +/// them; a translation edit does not, nor one table, nor another platform. +#[test] +fn the_plists_languages_are_in_the_id() { + use super::tests::{app, compat}; + let id = |platform: &str, tables: &[(&str, &str)]| { + let mut c = compat("net.fetch https://x/"); + super::derive(&app(tables).0, platform, None, &mut c).unwrap(); + crate::compat::localizations(platform, &mut c); + (c.id, c.inputs.get("localizations").cloned()) + }; + let (two, inputs) = id( + "ios", + &[("en", r#"{"t": "T"}"#), ("fr", r#"{"t": "Titre"}"#)], + ); + assert_eq!( + inputs, + Some(serde_json::json!({"base": "en", "locales": ["en", "fr"]})) + ); + assert_ne!(two, "old"); + assert_eq!( + id( + "ios", + &[("en", r#"{"t": "T"}"#), ("fr", r#"{"t": "Le titre"}"#)] + ) + .0, + two + ); + assert_ne!( + id("ios", &[("en", "{}"), ("fr", "{}"), ("de", "{}")]).0, + two + ); + assert_eq!(id("macos", &[("en", "{}"), ("fr", "{}")]).1, inputs); + assert_eq!( + id("web", &[("en", "{}"), ("fr", "{}")]), + ("old".into(), None) + ); + assert_eq!(id("ios", &[("en", "{}")]), ("old".into(), None)); +} diff --git a/bake/src/receipt.rs b/bake/src/receipt.rs index c63690841..df2982e67 100644 --- a/bake/src/receipt.rs +++ b/bake/src/receipt.rs @@ -701,6 +701,10 @@ fn artifact_graph( if inputs.get("grantPurposes").is_some() { requires.insert("grantPurposes".into(), inputs["grantPurposes"].clone()); } + // The installed Info.plist's languages (`reach.rs`): a bundle that adds or drops one is a binary release. + if inputs.get("localizations").is_some() { + requires.insert("localizations".into(), inputs["localizations"].clone()); + } let rust = assets .iter() .any(|asset| asset["name"] == "rust/app.module.json"); diff --git a/bake/src/receipt/tests.rs b/bake/src/receipt/tests.rs index 0aee4555f..08ac418c1 100644 --- a/bake/src/receipt/tests.rs +++ b/bake/src/receipt/tests.rs @@ -494,6 +494,22 @@ fn a_plan_requires_the_typescript_runtime_its_inputs_carry() { assert_eq!(requires(json!({})), Value::Null); } +/// A plan requires the languages the installed Info.plist names, so a bundle that adds or +/// drops a strings table waits for a binary that declares it. +#[test] +fn a_plan_requires_the_localizations_its_inputs_carry() { + let plan = exact_plan::builder::PlanBuilder::new(0, 0) + .finish() + .unwrap(); + let requires = |inputs: Value| { + let graph = artifact_graph(&plan, &inputs, &[], false, "aarch64-apple-ios").unwrap(); + graph["artifacts"][0]["requires"]["localizations"].clone() + }; + let languages = json!({"base": "en", "locales": ["en", "fr"]}); + assert_eq!(requires(json!({"localizations": languages})), languages); + assert_eq!(requires(json!({})), Value::Null); +} + /// A TypeScript module pair requires exactly the binary's TypeScript grants /// and its prelude's runtime, as a Rust module requires its own. #[test] diff --git a/docs/contract-for-agents.md b/docs/contract-for-agents.md index 43c985c1a..e6b9dc0fa 100644 --- a/docs/contract-for-agents.md +++ b/docs/contract-for-agents.md @@ -4819,7 +4819,9 @@ On Apple platforms the tables are the bundle's localizations, base first, so the system's own words and the direction of the chrome it draws (bars, the Mac's split view, sidebar and toolbar) follow the table it picks. AppKit mirrors a window only on a Mac whose system language is right to left, as it does for any -hand-built app, while the content follows the table everywhere. +hand-built app, while the content follows the table everywhere. Because the +binary names its languages, adding or dropping a table is a new binary there; +editing a translation still ships as an update. #### Folds on iOS