#!/usr/bin/env python3 # SPDX-License-Identifier: MPL-2.0 """Build the Nokia CameraService worker and its fixed-command broker.""" import hashlib import json from pathlib import Path import subprocess ROOT = Path(__file__).resolve().parents[2] ENGINE = ROOT / 'tundra/out/beatles/gecko-156.0.1' BUILD = ENGINE / 'camera-broker-build' NDK = BUILD / 'android-ndk-r27d' HEADERS = BUILD / 'android-headers-api23/android-headers-23/23' AOSP = BUILD / 'aosp/include' LIBS = ENGINE / 'camera-probe-runtime' OUT = BUILD def digest(path): return hashlib.sha256(path.read_bytes()).hexdigest() def build(name, source, command): target = OUT / name stamp = target.with_suffix('.build.json') record = {'source': digest(source), 'command': command} if target.is_file() and stamp.is_file(): try: if json.loads(stamp.read_text()) == record: print('Using cached camera tool:', name) return target except (OSError, ValueError): pass subprocess.run(command, check=True) target.chmod(0o755) stamp.write_text(json.dumps(record, sort_keys=True) + '\n') return target def main(): required = [NDK / 'toolchains/llvm/prebuilt/linux-x86_64/bin/clang++', NDK / 'toolchains/llvm/prebuilt/linux-x86_64/bin/clang', HEADERS / 'linux/binder.h', AOSP / 'camera/Camera.h', LIBS / 'libc++_shared.so', LIBS / 'beatles-camera-permission-bridge'] missing = [str(path) for path in required if not path.exists()] if missing: raise SystemExit('Private API-23 Camera1 build inputs missing:\n ' + '\n '.join(missing)) sysroot = NDK / 'toolchains/llvm/prebuilt/linux-x86_64/sysroot' cxx = str(NDK / 'toolchains/llvm/prebuilt/linux-x86_64/bin/clang++') cc = str(NDK / 'toolchains/llvm/prebuilt/linux-x86_64/bin/clang') common = ['--target=armv7a-linux-androideabi23', '--sysroot=' + str(sysroot)] worker_source = ROOT / 'tundra/probes/beatles-camera-worker.cpp' worker_command = [cxx, *common, '-fno-rtti', '-I', str(HEADERS), '-I', str(AOSP), str(worker_source), '-L', str(LIBS), '-Wl,-rpath,/data/local/tmp', '-Wl,--allow-shlib-undefined', '-lcamera_client', '-lbinder', '-lgui', '-lutils', '-lcutils', '-llog', '-lui', '-lhardware', '-lmedia', '-lcamera_metadata', '-lsync', '-lbase', '-lc++_shared', '-o'] build('beatles-camera-worker', worker_source, worker_command + [str(OUT / 'beatles-camera-worker')]) broker_source = ROOT / 'tundra/probes/beatles-camera-broker.c' broker_command = [cc, *common, '-Wall', '-Wextra', '-Werror', str(broker_source), '-o'] build('beatles-camera-broker', broker_source, broker_command + [str(OUT / 'beatles-camera-broker')]) print('Android Camera1 worker and broker are ready.') if __name__ == '__main__': main()