#!/usr/bin/env python3 """Host-side Kotlin smoke tests. Uses kotlinc if present; does not require Android SDK.""" from pathlib import Path import shutil, subprocess, tempfile, textwrap, os ROOT=Path(__file__).resolve().parents[1] K=ROOT/'android/app/src/main/java/com/qft/optical' kotlinc=shutil.which('kotlinc') if not kotlinc: print('SKIP Kotlin host smoke: kotlinc not installed (Android Gradle tests still cover these files on a dev host)') raise SystemExit(0) def run(args): env=os.environ.copy(); env.setdefault('TERM','xterm') p=subprocess.run(args, text=True, capture_output=True, env=env) if p.returncode: print(p.stdout); print(p.stderr); raise SystemExit(p.returncode) with tempfile.TemporaryDirectory() as td: td=Path(td) smoke=td/'Smoke.kt' smoke.write_text(textwrap.dedent(r''' package com.qft.optical import java.nio.ByteBuffer import java.nio.ByteOrder import java.util.zip.CRC32 fun b45e(data: ByteArray): String { val a="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"; val o=StringBuilder(); var i=0; while(i+1; val imageInfo:ImageInfo; fun close(); interface PlaneProxy { val buffer:ByteBuffer; val rowStride:Int; val pixelStride:Int }; interface ImageInfo { val rotationDegrees:Int } } ''')) (td/'com/google/zxing/Zxing.kt').write_text('package com.google.zxing\nopen class LuminanceSource(val width:Int,val height:Int)\nclass PlanarYUVLuminanceSource(data:ByteArray,dataWidth:Int,dataHeight:Int,left:Int,top:Int,width:Int,height:Int,reverseHorizontal:Boolean):LuminanceSource(width,height)\nclass BinaryBitmap(val binarizer:Any)\ndata class ResultPoint(val x:Float,val y:Float)\nclass Result(val text:String?="",val rawBytes:ByteArray?=null,val resultPoints:Array?=null)\n') (td/'com/google/zxing/common/Common.kt').write_text('package com.google.zxing.common\nimport com.google.zxing.LuminanceSource\nclass GlobalHistogramBinarizer(source:LuminanceSource)\nclass HybridBinarizer(source:LuminanceSource)\n') (td/'com/google/zxing/qrcode/QRCodeReader.kt').write_text('package com.google.zxing.qrcode\nimport com.google.zxing.BinaryBitmap\nimport com.google.zxing.Result\nclass QRCodeReader { fun decode(bitmap:BinaryBitmap):Result=Result(); fun reset(){} }\n') out=td/'analyzer.jar' sources=[td/'android/os/SystemClock.kt',td/'androidx/camera/core/Core.kt',td/'com/google/zxing/Zxing.kt',td/'com/google/zxing/common/Common.kt',td/'com/google/zxing/qrcode/QRCodeReader.kt',K/'LockRect.kt',K/'ScannerLockState.kt',K/'GrayFrame.kt',K/'QrAnalyzer.kt'] run([kotlinc,*map(str,sources),'-d',str(out)]) print('PASS Kotlin QrAnalyzer compile smoke with CameraX/ZXing-shaped stubs')