Skip to content

Commit 4d8f976

Browse files
committed
fix: route global mod_device through props_global json
1 parent 22e8945 commit 4d8f976

3 files changed

Lines changed: 90 additions & 1 deletion

File tree

devices/common/props_global.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
"ro.product.mod_device": "{base_code}_xiaomieu_global",
3131
"ro.build.host": "xiaomi.eu"
3232
},
33+
"global_rom": {
34+
"ro.product.mod_device": "{global_mod_device}",
35+
"ro.build.host": "{build_host}"
36+
},
3337
"cn_rom": {
3438
"ro.product.mod_device": "{base_code}",
3539
"ro.build.host": "{build_host}"

src/core/props.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,22 @@ def _update_general_info(self):
290290
# 1. Common
291291
replacements = config.get("common", {})
292292

293-
# 2. EU vs CN
293+
# 2. EU vs Global vs CN
294294
is_eu = getattr(self.ctx, "is_port_eu_rom", False)
295+
is_global = getattr(self.ctx, "is_port_global_rom", False) and not is_eu
295296
if is_eu:
296297
replacements.update(config.get("eu_rom", {}))
298+
elif is_global:
299+
replacements.update(config.get("global_rom", {}))
297300
else:
298301
replacements.update(config.get("cn_rom", {}))
299302

303+
global_region = (getattr(self.ctx, "port_global_region", "") or "").strip().lower()
304+
if global_region and global_region != "global":
305+
global_mod_device = f"{base_code}_{global_region}_global"
306+
else:
307+
global_mod_device = f"{base_code}_global"
308+
300309
# Format values (Placeholder replacement)
301310
fmt_map = {
302311
"build_date": build_date,
@@ -305,6 +314,8 @@ def _update_general_info(self):
305314
"rom_version": rom_version,
306315
"build_user": self.build_user,
307316
"build_host": self.build_host,
317+
"global_region": global_region,
318+
"global_mod_device": global_mod_device,
308319
}
309320

310321
# Build final key-value map for processing
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import logging
2+
from types import SimpleNamespace
3+
4+
import src.core.modifiers # noqa: F401
5+
from src.core.props import PropertyModifier
6+
7+
8+
def _write_minimal_props_global_json(tmp_path):
9+
config_dir = tmp_path / "devices" / "common"
10+
config_dir.mkdir(parents=True, exist_ok=True)
11+
(config_dir / "props_global.json").write_text(
12+
"""{
13+
"common": {},
14+
"eu_rom": {
15+
"ro.product.mod_device": "{base_code}_xiaomieu_global"
16+
},
17+
"global_rom": {
18+
"ro.product.mod_device": "{global_mod_device}"
19+
},
20+
"cn_rom": {
21+
"ro.product.mod_device": "{base_code}"
22+
}
23+
}
24+
""",
25+
encoding="utf-8",
26+
)
27+
28+
29+
def _build_ctx(tmp_path, *, is_port_eu_rom, is_port_global_rom, port_global_region):
30+
target_dir = tmp_path / "target"
31+
target_dir.mkdir(parents=True, exist_ok=True)
32+
return SimpleNamespace(
33+
target_dir=target_dir,
34+
stock_rom_code="pudding",
35+
target_rom_version="OS2.0.0.TEST",
36+
is_port_eu_rom=is_port_eu_rom,
37+
is_port_global_rom=is_port_global_rom,
38+
port_global_region=port_global_region,
39+
)
40+
41+
42+
def _run_update_and_get_mod_device(ctx):
43+
prop_file = ctx.target_dir / "build.prop"
44+
prop_file.write_text("ro.product.mod_device=old_value\n", encoding="utf-8")
45+
modifier = PropertyModifier(ctx, logger=logging.getLogger("test.props.global.json"))
46+
modifier._update_general_info()
47+
for line in prop_file.read_text(encoding="utf-8").splitlines():
48+
if line.startswith("ro.product.mod_device="):
49+
return line.split("=", 1)[1]
50+
raise AssertionError("ro.product.mod_device not found")
51+
52+
53+
def test_global_rom_branch_uses_region_suffix(tmp_path, monkeypatch):
54+
_write_minimal_props_global_json(tmp_path)
55+
monkeypatch.chdir(tmp_path)
56+
ctx = _build_ctx(
57+
tmp_path,
58+
is_port_eu_rom=False,
59+
is_port_global_rom=True,
60+
port_global_region="tw",
61+
)
62+
assert _run_update_and_get_mod_device(ctx) == "pudding_tw_global"
63+
64+
65+
def test_global_rom_branch_uses_generic_global_suffix_when_region_missing(tmp_path, monkeypatch):
66+
_write_minimal_props_global_json(tmp_path)
67+
monkeypatch.chdir(tmp_path)
68+
ctx = _build_ctx(
69+
tmp_path,
70+
is_port_eu_rom=False,
71+
is_port_global_rom=True,
72+
port_global_region="",
73+
)
74+
assert _run_update_and_get_mod_device(ctx) == "pudding_global"

0 commit comments

Comments
 (0)