Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions bake/src/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
Expand Down Expand Up @@ -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);
Expand Down
40 changes: 40 additions & 0 deletions bake/src/reach_grant_lines_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
4 changes: 4 additions & 0 deletions bake/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
16 changes: 16 additions & 0 deletions bake/src/receipt/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 3 additions & 1 deletion docs/contract-for-agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading