qualify.mjs (3575B)
1 import assert from 'node:assert/strict'; 2 import {spawnSync} from 'node:child_process'; 3 import {createHash} from 'node:crypto'; 4 import {mkdirSync,readFileSync,readdirSync,writeFileSync} from 'node:fs'; 5 import {dirname,join,resolve} from 'node:path'; 6 import {fileURLToPath} from 'node:url'; 7 8 const options=new Map();for(let i=2;i<process.argv.length;i+=2)options.set(process.argv[i],resolve(process.argv[i+1])); 9 for(const name of ['--out','--library','--generator','--kotlinc','--jna','--java'])assert(options.has(name),name); 10 const out=options.get('--out'),fixture=dirname(fileURLToPath(import.meta.url));mkdirSync(out,{recursive:false}); 11 const hash=path=>createHash('sha256').update(readFileSync(path)).digest('hex'); 12 const files=(root,prefix='')=>readdirSync(root,{withFileTypes:true}).flatMap(entry=>entry.isDirectory()?files(join(root,entry.name),join(prefix,entry.name)):[join(prefix,entry.name)]).sort(); 13 const library=options.get('--library'),generator=options.get('--generator'); 14 const report={state:'running',scope:'actual retained native SDK memory/field/lifecycle bridge; no participant, generic factory or application qualification',library:{path:library,sha256:hash(library)},generator:{path:generator,sha256:hash(generator)},commands:[]}; 15 function persist(){writeFileSync(join(out,'report.json'),JSON.stringify(report,null,2)+'\n');} 16 function run(command,args){ 17 const start=performance.now(),result=spawnSync(command,args,{encoding:'utf8',maxBuffer:8*1024*1024,timeout:240000}); 18 const log=join(out,`${report.commands.length}.log`);writeFileSync(log,(result.stdout||'')+(result.stderr||'')); 19 const row={command:[command,...args],exit_code:result.status,signal:result.signal,error:result.error?.message,seconds:(performance.now()-start)/1000,log,sha256:hash(log)}; 20 report.commands.push(row);persist();assert(!result.error&&result.status===0,readFileSync(log,'utf8'));console.log(JSON.stringify(row)); 21 } 22 try{ 23 run(generator,['--version']);run('/usr/bin/swiftc',['--version']);run(options.get('--kotlinc'),['-version']); 24 for(const language of ['swift','kotlin']){ 25 const first=join(out,language),second=first+'_repeat'; 26 for(const target of [first,second])run(generator,['generate','--library',library,'--language',language,'--no-format','--out-dir',target]); 27 assert.deepEqual(files(first),files(second));for(const file of files(first))assert.equal(hash(join(first,file)),hash(join(second,file))); 28 report[language]=Object.fromEntries(files(first).map(file=>[file,hash(join(first,file))])); 29 } 30 const swift=join(out,'swift'),executable=join(out,'swift_smoke'); 31 run('/usr/bin/swiftc',['-swift-version','6','-warnings-as-errors','-parse-as-library','-I',swift,'-Xcc',`-fmodule-map-file=${join(swift,'radroots_sdkFFI.modulemap')}`,join(swift,'radroots_sdk.swift'),join(fixture,'Smoke.swift'),library,'-o',executable]); 32 run(executable,[]); 33 const coroutine=resolve(options.get('--kotlinc'),'../../lib/kotlinx-coroutines-core-jvm.jar'); 34 const classpath=[options.get('--jna'),coroutine].join(':'),jar=join(out,'kotlin_smoke.jar'); 35 report.runtimeJars=Object.fromEntries([options.get('--jna'),coroutine].map(path=>[path,hash(path)])); 36 run(options.get('--kotlinc'),[join(out,'kotlin/uniffi/radroots_sdk/radroots_sdk.kt'),join(fixture,'Smoke.kt'),'-Werror','-jvm-target','21','-classpath',classpath,'-include-runtime','-d',jar]); 37 run(options.get('--java'),[`-Djna.library.path=${dirname(library)}`,'-cp',[jar,classpath].join(':'),'SmokeKt']); 38 report.state='passed'; 39 }finally{persist();}