#!/usr/bin/env python3 """Explicitly authorized temporary Debug install; preserve the notarized rollback.""" import argparse, datetime, hashlib, json, os, plistlib, shutil, subprocess, sys, uuid from pathlib import Path import deliver as delivery from template_payload import template_files ROOT=Path(__file__).resolve().parent.parent CACHE=delivery.CACHE DEST=delivery.DEST PLUGIN=delivery.PLUGIN APP=CACHE/'DerivedData/Build/Products/Debug/大鱼调色.app' LOOSE=CACHE/'DerivedData/Build/Products/Debug/大鱼调色 XPC Service.pluginkit' def main(): parser=argparse.ArgumentParser(description=__doc__) parser.add_argument('--source',required=True,type=Path) args=parser.parse_args();source=args.source.resolve() commit=subprocess.check_output(['git','rev-parse','HEAD'],cwd=source,text=True).strip() assert not subprocess.check_output(['git','status','--porcelain','--untracked-files=no'],cwd=source), '调试编译源须为干净的可恢复节点' delivery.hosts_closed() assert not any(line.endswith('/Contents/MacOS/大鱼调色') for line in delivery.run('ps','-axo','comm=').splitlines()),'请先正常退出大鱼调色主 APP' lock=delivery.LOCK;lock.mkdir() (lock/'owner.json').write_text(json.dumps(dict(PID=os.getpid(),cwd=str(ROOT),product='大鱼调色',mode='user-authorized-debug',started=datetime.datetime.now(datetime.timezone.utc).isoformat()))) backup=None;stage=None try: print('Building explicitly authorized Debug configuration',flush=True) with (CACHE/'debug-local-build.log').open('w') as log: subprocess.run(['xcodebuild','-project','大鱼调色.xcodeproj','-scheme','Wrapper Application','-configuration','Debug','-enableAddressSanitizer','NO','-derivedDataPath',str(CACHE/'DerivedData'),'build'],cwd=source,stdout=log,stderr=subprocess.STDOUT,check=True) for reference,bundled,_ in template_files(): target=APP/delivery.BUNDLED_TEMPLATES/bundled;target.parent.mkdir(parents=True,exist_ok=True);shutil.copyfile(source/'template'/reference,target);target.chmod(0o644) (APP/'Contents/Resources/Basis_balanceWheel.png').chmod(0o644) info=plistlib.loads((APP/'Contents/Info.plist').read_bytes());info['DYLocalDebugBuild']=True;(APP/'Contents/Info.plist').write_bytes(plistlib.dumps(info)) delivery.identity(APP,'com.dayu.color');delivery.identity(APP/PLUGIN,'com.dayu.color.XPC') delivery.unregister(APP/PLUGIN);delivery.unregister(LOOSE) for name in ['FxPlug','PluginManager']: delivery.run('codesign','--force','--timestamp','--options','runtime','--sign',delivery.IDENTITY,str(APP/PLUGIN/'Contents/Frameworks'/(name+'.framework'))) delivery.run('codesign','--force','--timestamp','--options','runtime','--sign',delivery.IDENTITY,str(APP/PLUGIN)) delivery.run('codesign','--force','--timestamp','--options','runtime','--entitlements',str(source/'大鱼调色/Wrapper Application/SandboxEntitlements.entitlements'),'--sign',delivery.IDENTITY,str(APP)) delivery.run('codesign','--verify','--deep','--strict',str(APP)) stage=DEST.parent/('.dayu-color-debug-stage-'+uuid.uuid4().hex+'.app');delivery.run('ditto',str(APP),str(stage)) delivery.identity(DEST,'com.dayu.color') backup=DEST.parent/('.dayu-color-formal-before-debug-'+uuid.uuid4().hex+'.app');os.replace(DEST,backup);os.replace(stage,DEST);stage=None try: delivery.run('codesign','--verify','--deep','--strict',str(DEST));delivery.identity(DEST,'com.dayu.color') delivery.unregister(backup/PLUGIN) for path in [APP,LOOSE]: if path.exists():delivery.unregister(path/PLUGIN if path==APP else path);shutil.rmtree(path) delivery.run('pluginkit','-a',str(DEST/PLUGIN)) registry=delivery.run('pluginkit','-m','-A','-D','-v','-i','com.dayu.color.XPC') entries=[line for line in registry.splitlines() if 'com.dayu.color.XPC(' in line] assert len(entries)==1 and entries[0].rstrip().endswith('\t'+str(DEST/PLUGIN)),registry delivery.run('open',str(DEST)) assert str(DEST/'Contents/MacOS/大鱼调色') in delivery.run('ps','-axo','comm=').splitlines(),'调试 APP 未从固定位置启动' except BaseException: failed=DEST.parent/('.dayu-color-debug-failed-'+uuid.uuid4().hex+'.app');os.replace(DEST,failed);os.replace(backup,DEST);backup=None;delivery.run('pluginkit','-a',str(DEST/PLUGIN));raise record=dict(status='temporary-debug-awaiting-host-verification',authorization='User explicitly requested local Debug testing while Apple notarization is pending.',configuration='Debug',notarized=False,bundleID='com.dayu.color',version=info['CFBundleShortVersionString'],build=info['CFBundleVersion'],sourceCommit=commit,path=str(DEST),formalRollback=str(backup),pendingReleaseNotary='0a1d2d49-1a03-4cd4-acbe-ba37f1fee42d',signatureVerified=True,pluginKitUniquePath=True,cleanup='Remove this temporary Debug APP when user testing ends or replace with the notarized Release; preserve the formal rollback until then.') report=ROOT/'verification/DebugDelivery1.22.1.json';report.write_text(json.dumps(record,ensure_ascii=False,indent=2)+'\n') print('DEBUG_INSTALLED. Verify FCP from the fixed path, then type keep to leave it for user testing.',flush=True) for decision in sys.stdin: if decision.strip()=='keep': record['status']='temporary-debug-installed-for-user-testing';report.write_text(json.dumps(record,ensure_ascii=False,indent=2)+'\n');break finally: if stage and stage.exists():shutil.rmtree(stage) (lock/'owner.json').unlink();lock.rmdir() if __name__=='__main__':main()