From 3c16d9485a95fd6edd983c1b705cfbb4d83b3bb6 Mon Sep 17 00:00:00 2001 From: admin_d Date: Mon, 14 Sep 2026 21:13:00 +0500 Subject: [PATCH] Fix Task 2 resource and native contracts --- config/runtime-resources.json | 1 + tools/device.py | 1 + tools/runner.py | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/config/runtime-resources.json b/config/runtime-resources.json index 8a86663..0fb22e6 100644 --- a/config/runtime-resources.json +++ b/config/runtime-resources.json @@ -2,6 +2,7 @@ "schema": "kam-runtime-resources/1", "entries": [ {"kind": "directory", "path": "data"}, + {"kind": "directory", "path": "SpriteResource"}, {"kind": "directory", "path": "Maps"}, {"kind": "directory", "path": "MapsMP"}, {"kind": "directory", "path": "Campaigns"}, diff --git a/tools/device.py b/tools/device.py index 251f8fb..ebcc535 100644 --- a/tools/device.py +++ b/tools/device.py @@ -46,6 +46,7 @@ def current_package() -> tuple[dict, str]: apk=package.get('apk') if not isinstance(apk,dict) or set(apk)!={'file','sha256','size','native_library_path_in_apk'} or apk.get('file')!='out/current/kam-mobile.apk': fail('Package APK locator mismatch') if package['cpu'] not in CPUS or package['abi']!=CPUS[package['cpu']][0]: fail('Invalid package ABI') + if apk.get('native_library_path_in_apk')!=f"lib/{package['abi']}/libkam_mobile.so": fail('Package native library path does not match selected ABI') if not CURRENT_APK.is_file() or apk.get('sha256')!=sha256(CURRENT_APK): fail('Current APK missing or changed') return package, identity['package'] diff --git a/tools/runner.py b/tools/runner.py index 0187440..e15dcb0 100755 --- a/tools/runner.py +++ b/tools/runner.py @@ -92,6 +92,16 @@ def _error(log:Path)->str: text=log.read_text(errors='replace') if log.exists() else '' return (first_errors(text) or [text[-1500:] or 'Build command failed'])[0] +def _native_library_path(cpu:str)->str: + return f'lib/{CPUS[cpu][0]}/libkam_mobile.so' + +def _select_native_library(project:Path, name:str, cpu:str)->Path: + candidates=sorted(project.rglob(f'lib{name}_android_{cpu}.so'),key=lambda path:str(path)) + if not candidates:raise ProbeError('Compiler exited 0 but expected native library is missing') + hashes={sha256(path) for path in candidates} + if len(hashes)!=1:raise ProbeError('Ambiguous native library outputs for '+CPUS[cpu][0]+': '+', '.join(str(path) for path in candidates)) + return candidates[0] + def _prepare(build_id:str, diagnostics:bool=True)->tuple[Path,Path]: work=ROOT/'build'/build_id; logs=work/'logs' logs.mkdir(parents=True,exist_ok=True) @@ -118,9 +128,7 @@ def build_local(a:argparse.Namespace,build_id:str)->int: if compile['status']!='PASS': return _finish(_record(build_id,a.cpu,compile['status'],app,len(resources),compile,package,error=_error(logs/'compile.log'))) try: - candidates=list(project.rglob(f"lib{descriptor['name']}_android_{a.cpu}.so")) - if len(candidates)!=1:raise ProbeError('Compiler exited 0 but expected exactly one native library') - library=candidates[0]; inspect_elf(library.read_bytes(),a.cpu) + library=_select_native_library(project,descriptor['name'],a.cpu); inspect_elf(library.read_bytes(),a.cpu) except (ProbeError,OSError,ValueError) as error: compile['status']='FAIL' return _finish(_record(build_id,a.cpu,'FAIL',app,len(resources),compile,package,error=str(error))) @@ -133,6 +141,7 @@ def build_local(a:argparse.Namespace,build_id:str)->int: if not candidates:raise ProbeError('Packaging exited 0 but no APK') if len({sha256(path) for path in candidates})!=1:raise ProbeError('Multiple different APK outputs') apk=candidates[0]; apk_info=inspect_apk(apk,a.cpu,library.name,sha256(library),library.read_bytes()) + if apk_info['main_library_path']!=_native_library_path(a.cpu):raise ProbeError('APK native library path does not match selected ABI and libkam_mobile.so') signer=signature_tool() if signer: signed=run_command([signer,'verify','--verbose',str(apk)],project,logs/'signature.log',a.timeout)