Reuse Android compiler outputs and remove old build artifacts
Sync changed files to Google Drive / sync (push) Successful in 2m27s

This commit is contained in:
admin_d committed 2026-10-10 02:05:20 +05:00
1 parent 29df541ea1
commit d6676896d4
70 files changed
+225 -2828

No files matched your search

+14 -4
View File
@@ -1,6 +1,6 @@
"""One-command Android-only compile, full native link, APK and evidence pipeline."""
from __future__ import annotations
import argparse, json, os, re, shutil, subprocess, sys, uuid, zipfile
import argparse, fcntl, json, os, re, shutil, subprocess, sys, uuid, zipfile
from pathlib import Path
from common import (ROOT, COMMIT, CPUS, ProbeError, stamp, sha256, write_json, run_command,
first_errors, CURRENT_OUTPUT_DIR, CURRENT_BUILD_METADATA,
@@ -12,6 +12,7 @@ from source_resolution import load_source_contract, validate_source_contract, bu
from generate import android_service_roots, materialize_application_project
from artifacts import inspect_elf, inspect_apk
from resource_staging import stage_runtime_resources
from build_cache import cached_project
IMAGE_TAG='kambi/castle-engine-cloud-builds-tools:cge-stable'
BUILD_EVIDENCE_DIR=ROOT/'build-evidence'
@@ -152,9 +153,11 @@ def build_local(a:argparse.Namespace,build_id:str)->int:
audited=inventory(vendor_root)
validated=validate_source_contract(load_source_contract(),vendor_root,receipt,audited)
resolution=build_source_resolution(validated,vendor_root,ROOT/'code')
descriptor=materialize_application_project(work/'application',resolution);app=_application(descriptor)
descriptor=materialize_application_project(cached_project(a.cpu,resolution,logs),resolution);app=_application(descriptor)
resources=stage_runtime_resources(descriptor['data_root'])
stage_android_services(descriptor['project_dir'],logs)
for pattern in (f"lib{descriptor['name']}_android_{a.cpu}.so",'*.apk'):
for output in descriptor['project_dir'].rglob(pattern):output.unlink()
except (ProbeError,OSError,ValueError,KeyError) as error:
return _finish(_record(build_id,a.cpu,'BLOCKED',app,None,compile,package,error=str(error)))
if not shutil.which('castle-engine'):
@@ -219,7 +222,8 @@ def docker_build(a:argparse.Namespace,build_id:str)->int:
if image is None:raise ProbeError('Image has no immutable RepoDigest')
write_json(lock,{'image':image,'image_id':info['Id'],'resolved_from':IMAGE_TAG,'locked_at':stamp(),'note':'Subsequent runs use this digest, never silently advance the tag.'})
cmd=['docker','run','--rm','--platform=linux/amd64','--user','0:0','-e','HOME=/work/.cache/home',
'-e','KAM_BUILD_ID='+build_id,'-e','KAM_CONTAINER_BUILD=1','-v',str(ROOT)+':/work','-w','/work']
'-e','KAM_BUILD_ID='+build_id,'-e','KAM_CONTAINER_BUILD=1',
'-e','KAM_TOOLCHAIN_IMAGE='+image,'-v',str(ROOT)+':/work','-w','/work']
if os.environ.get('GITHUB_TOKEN'):cmd+=['-e','GITHUB_TOKEN']
cmd+=['--entrypoint','python3',image,'tools/runner.py','--local','--cpu',a.cpu,'--timeout',str(a.timeout)]
if a.no_fetch:cmd+=['--no-fetch']
@@ -242,7 +246,13 @@ def main()->int:
inherited=os.environ.get('KAM_BUILD_ID')
if inherited and not re.fullmatch(r'\d{8}T\d{6}Z-[0-9a-f]{8}',inherited):ap.error('Invalid KAM_BUILD_ID')
build_id=inherited or stamp()+'-'+uuid.uuid4().hex[:8]
result=build_local(a,build_id) if a.local else docker_build(a,build_id)
if os.environ.get('KAM_CONTAINER_BUILD')=='1':
result=build_local(a,build_id) if a.local else docker_build(a,build_id)
else:
(ROOT/'build').mkdir(exist_ok=True)
with (ROOT/'build/runner.lock').open('a') as lock:
fcntl.flock(lock,fcntl.LOCK_EX)
result=build_local(a,build_id) if a.local else docker_build(a,build_id)
if result==0 and os.environ.get('KAM_CONTAINER_BUILD')!='1':
subprocess.run([sys.executable,str(ROOT/'tools/device.py')],cwd=ROOT,check=False)
return result