Files
WoW-Hybrid-gateway/ops/windows_client_package.py
2026-11-23 03:28:32 +02:00

294 lines
23 KiB
Python

"""Assemble native Windows client on the authorized VM from the final Linux content."""
import argparse,hashlib,json,os,shutil,subprocess,sys
from pathlib import Path
def digest(p):return hashlib.sha256(Path(p).read_bytes()).hexdigest()
def read_json(path):return json.loads(Path(path).read_text(encoding='utf-8-sig'))
def check_backend_runtime(folder):
"""Use a clean Windows process so modules already loaded by packaging do not mask errors."""
probe = Path(__file__).with_name('windows_backend_runtime_check.py')
result = subprocess.run([sys.executable, '-I', '-S', str(probe), str(folder)],
capture_output=True, text=True, timeout=30)
if result.returncode:
raise ValueError(f'Windows backend runtime check failed ({result.returncode}): {result.stderr.strip()}')
def artifact_inputs(modules,module_profile,backend_transport=None,module_profile_sha256=None):
"""Bind transport and every copied module to an existing artifact profile."""
if modules is None or module_profile is None:
raise ValueError('Frozen module directory and pinned Windows module profile required')
if module_profile_sha256 is None or digest(module_profile)!=module_profile_sha256:
raise ValueError('Pinned module profile identity differs or is missing')
modules=Path(modules);profile=read_json(module_profile)
transport=profile.get('backend_transport')
if transport!='owned-stdio-ipc-v1' or backend_transport not in (None,transport):
raise ValueError('Artifact transport missing, unsupported or differs from requested transport')
rows={}
for role,name in [('bridge','GWNativeBridge.dll'),('wire','GWNativeWire.dll'),('backend','GWNativeBackend.dll'),('codec','forever_codec.dll'),('backend_host','windows-backend-host.exe')]:
row=profile.get(role,{})
if (not isinstance(row,dict) or Path(row.get('path','')).name!=name
or not isinstance(row.get('sha256'),str) or len(row['sha256'])!=64
or not(modules/name).is_file() or digest(modules/name)!=row['sha256']):
raise ValueError('Artifact profile or matching module missing: '+role)
rows[name]=row['sha256']
# Dependencies are copied with the selected artifacts and join the same resume
# identity; no scan or hashing of the preserved CASC payload is performed.
for path in modules.glob('*.dll'):
if path.name!='forever_codec.new.dll' and path.name not in rows:rows[path.name]=digest(path)
return transport,rows
def artifact_profile_from_provenance(parent_profile,provenance):
"""Adapt the existing R6 build handoff to the same explicit module profile."""
if provenance.get('new_matching_canonical_IPC_frontend')is not True:
raise ValueError('Matching IPC build provenance required')
profile=json.loads(json.dumps(parent_profile))
if profile.get('backend_transport')!='owned-stdio-ipc-v1':
raise ValueError('Pinned IPC parent profile required')
for role,name in [('bridge','GWNativeBridge.dll'),('wire','GWNativeWire.dll'),('backend','GWNativeBackend.dll'),('codec','forever_codec.dll'),('backend_host','windows-backend-host.exe')]:
row=profile.get(role)
if not isinstance(row,dict) or row.get('path','').replace('\\','/').split('/')[-1]!=name:
raise ValueError('Parent module role missing: '+role)
changed=provenance.get('changed_modules',{}).get(name)
if changed is not None:
if changed.get('path','').replace('\\','/').split('/')[-1]!=name:raise ValueError('Build module role differs')
row['sha256']=changed.get('sha256')
if role=='codec':
codec=provenance.get('codec_provenance',{})
if codec.get('codec','').replace('\\','/').split('/')[-1]!=name:raise ValueError('Codec build role missing')
if changed is not None and row['sha256']!=codec.get('codec_sha256'):raise ValueError('Codec provenance differs')
row['sha256']=codec.get('codec_sha256')
if not isinstance(row.get('sha256'),str)or len(row['sha256'])!=64:raise ValueError('Module identity missing: '+role)
return profile
def package_inputs(linux,source,output,revision,base_client,delta_plan,modules,module_profile,backend_transport,module_profile_sha256=None):
transport,artifacts=artifact_inputs(modules,module_profile,backend_transport,module_profile_sha256)
files={}
def pin(path):
path=Path(path);files[str(path.resolve())]=digest(path)
for folder in [*(Path(linux)/name for name in ('ops','docs','compat')),Path(linux)/'runtime/native-handler-code']:
for path in sorted(folder.rglob('*')):
if path.is_file():pin(path)
for path in sorted((Path(source)/'ops').glob('*.py')):pin(path)
for path in (Path(source)/'launcher/launcher.py',Path(source)/'native/windows_launcher_entry.c',Path(linux)/'linux-release.json',Path(linux)/'BUILD-NOTES.txt',Path(linux)/'runtime/native-client/.build.info',Path(linux)/'runtime/native-client/_classic_beta_/WTF/Config.wtf',Path(module_profile)):
pin(path)
if base_client is not None:pin(Path(base_client).parent.parent/'windows-release.json');pin(Path(base_client)/'.build.info')
# The original owner remains a live metadata dependency of a retained copy.
# Bind its small receipt/validation files too, never the immutable Data tree.
for root,name in [(Path(linux),'linux-release.json')]+([(Path(base_client).parent.parent,'windows-release.json')]if base_client is not None else []):
release=read_json(root/name)
retained=release.get('retained_asset_publication')
if retained is not None:
manifest=Path(retained['source_manifest']);pin(manifest)
if files[str(manifest.resolve())]!=retained.get('source_manifest_sha256'):raise ValueError('Retained publication source identity differs')
release=read_json(manifest)
declared=release.get('private_asset_publication')
if declared is not None:
receipt=Path(declared['receipt_path']);pin(receipt);pin(receipt.parent/'changed-validation.json')
if delta_plan is not None:pin(delta_plan)
identity=dict(schema=1,source_git_revision=revision,linux=str(Path(linux).resolve()),source=str(Path(source).resolve()),output=str(Path(output).resolve()),base_client=str(Path(base_client).resolve())if base_client is not None else None,modules=str(Path(modules).resolve()),backend_transport=transport,files=files,artifacts=artifacts)
identity['sha256']=hashlib.sha256(json.dumps(identity,sort_keys=True,separators=(',',':')).encode()).hexdigest()
return identity
def require_resume(saved,identity):
if (saved.get('output')!=identity['output'] or saved.get('content_copy_complete')is not True
or saved.get('input_identity')!=identity):
raise ValueError('Existing candidate input fingerprint differs or has no completed owned copy receipt')
def reviewed_package_publication(client,release_name):
"""Reuse an owning publication for an immutable copy without claiming apply."""
from published_client_assets import _publication_proof
root=Path(client).parent.parent;manifest=root/release_name;release=read_json(manifest)
retained=release.get('retained_asset_publication')
if retained is not None:
manifest=Path(retained['source_manifest'])
if digest(manifest)!=retained.get('source_manifest_sha256'):
raise ValueError('Retained publication source identity differs')
release=read_json(manifest)
if release.get('retained_asset_publication') is not None:
raise ValueError('Retained publication must point directly to owning source')
declared=release.get('private_asset_publication')
proof=_publication_proof(manifest.parent,declared)
if digest(Path(client)/'.build.info')!=proof['build_info_sha256']:
raise ValueError('Copied publication build identity differs')
owner=dict(source_manifest=str(manifest.resolve()),source_manifest_sha256=digest(manifest))
return proof,read_json(declared['receipt_path']),owner
def reviewed_asset_copy(client,base_client,plan,delta_plan):
"""Consume genericv4 lineage proofs, not a whitelist of historical ROOTs."""
proofs=[];receipts=[];owner=None
for path,release_name in ((base_client,'windows-release.json'),(client,'linux-release.json')):
proof,receipt,owner=reviewed_package_publication(path,release_name)
proofs.append(proof);receipts.append(receipt)
parent,current=proofs;parent_receipt,current_receipt=receipts
if (plan.get('required_parent_ROOT')!=parent['composed_root'] or plan.get('new_ROOT')!=current['composed_root']):
raise ValueError('Copy plan ROOTs differ from reviewed publications')
if parent['composed_root']==current['composed_root']:
if (plan.get('files')!=[] or parent['registered_assets']!=current['registered_assets']
or parent_receipt.get('framing_manifest_sha256')!=current_receipt.get('framing_manifest_sha256')
or parent['build_info_sha256']!=current['build_info_sha256']):
raise ValueError('Same-ROOT copy differs from reviewed asset generation')
else:
reference=current_receipt.get('inputs',{}).get('delta_plan',{})
if (current_receipt.get('kind')not in ('closed-private-asset-lineage-publication-v4','closed-private-equipment-delta-publication-v4')
or reference.get('sha256')!=digest(delta_plan)
or Path(reference.get('path','')).resolve()!=Path(delta_plan).resolve()
or current_receipt.get('old_root')!=parent['composed_root']
or current_receipt.get('parent_registered_assets')!=parent['registered_assets']
or current_receipt.get('inputs',{}).get('parent_frames',{}).get('sha256')!=parent_receipt.get('framing_manifest_sha256')):
raise ValueError('Copy delta is not the pinned genericv4 child of this parent')
# Validate all paths before creating a candidate or touching a linked file.
seen=set()
for row in plan['files']:
relative=Path(row.get('relative_path',row.get('relative','')))
if (not relative.parts or relative.is_absolute() or '..'in relative.parts or '\\'in row.get('relative_path',row.get('relative',''))
or not(relative.parts[0]=='Data' or relative.as_posix()=='.build.info') or relative.as_posix()in seen):
raise ValueError('Asset delta escapes public client or repeats a path')
seen.add(relative.as_posix())
if not(client/relative).is_file() or (client/relative).is_symlink():raise ValueError('Regular delta source required')
if parent['composed_root']!=current['composed_root'] and '.build.info'not in seen:raise ValueError('Changed ROOT requires final build-info activation')
return dict(parent=parent,source=current,retained_asset_publication=owner)
def original_control_parent(client,base_client,plan):
"""Reuse one accepted data generation for an independent no-hybrid control."""
root='2ed14fe112a8f061e07eabc80b2ac128'
proof_path=Path(plan['installed_boundary']);proof=json.loads(proof_path.read_text())
release=base_client.parent.parent/'windows-release.json'
parent=json.loads(release.read_text(encoding='utf-8-sig'))
publication=parent.get('private_asset_publication',{})
if (plan.get('required_parent_ROOT')!=root or plan.get('new_ROOT')!=root or plan.get('files')!=[]
or plan.get('registered_assets')!=23139
or digest(proof_path)!=plan.get('installed_boundary_sha256')
or proof.get('status')!='PASS_COMBINED_INSTALLED_WINDOWS_R18_R19_84026_23139_BOUNDARY'
or Path(proof.get('target','')).resolve()!=base_client.parent.parent.resolve()
or proof.get('composed_root')!=root or proof.get('registered_assets')!=23139
or digest(release)!=proof.get('windows_release_sha256')
or parent.get('internal_startup_candidate')is not True
or publication.get('composed_root')!=root or publication.get('registered_assets')!=23139
or client.resolve()!=base_client.resolve()
or (base_client/'.build.info').read_bytes()!=(client/'.build.info').read_bytes()):
raise ValueError('Original control requires pinned accepted23139 same-ROOT parent')
receipt_path=Path(publication['receipt_path'])
receipt=json.loads(receipt_path.read_text())
if (digest(receipt_path)!=plan.get('publication_receipt_sha256')
or digest(base_client/'.build.info')!=receipt.get('published_build_info_sha256')):
raise ValueError('Original control parent build info differs from accepted publication')
def copy_public_client(client,target,base_client=None,delta_plan=None):
from linux_client_package import PRODUCT_FILES,DATA_TREES,GAME_FILES,GAME_TREES,safe_config
if base_client is not None:
# Reuse immutable NTFS assets; every changed delta file is replaced by rename
# below, never written through a hard link into the preserved r1 client.
base_client=Path(base_client);plan=json.loads(Path(delta_plan).read_text())
original_control=plan.get('kind')=='reviewed-original-nohybrid-control-same-root-v1'
asset_copy=None
if original_control:
original_control_parent(Path(client),base_client,plan)
else:
asset_copy=reviewed_asset_copy(Path(client),base_client,plan,delta_plan)
target.mkdir();(target/'Data').mkdir();game=target/'_classic_beta_';game.mkdir()
for name in PRODUCT_FILES:shutil.copyfile(client/name,target/name)
def immutable_asset(source,dest):
if Path(source).name=='shmem':return shutil.copy2(source,dest) # Native mutable storage cache is never shared.
return os.link(source,dest)
for name in DATA_TREES:shutil.copytree(base_client/'Data'/name,target/'Data'/name,copy_function=immutable_asset)
for name in GAME_FILES:shutil.copyfile(base_client/'_classic_beta_'/name,game/name)
for name in GAME_TREES:
if original_control and name=='Interface':continue # No loose hybrid addon/control in this independent client.
if name=='Interface' and (client/'_classic_beta_'/name).exists():shutil.copytree(client/'_classic_beta_'/name,game/name)
elif(base_client/'_classic_beta_'/name).exists():shutil.copytree(base_client/'_classic_beta_'/name,game/name,copy_function=os.link)
for row in sorted(plan['files'],key=lambda row:row.get('relative_path',row.get('relative'))=='.build.info'):
relative=Path(row.get('relative_path',row.get('relative','')))
if relative.is_absolute()or '..'in relative.parts or not(relative.parts[0]=='Data' or relative.as_posix()=='.build.info'):raise ValueError('Asset delta escapes public client')
source=client/relative;dest=target/relative;dest.parent.mkdir(parents=True,exist_ok=True)
temporary=dest.with_name(dest.name+'.windows-delta-new');shutil.copyfile(source,temporary);os.replace(temporary,dest)
marker='warrior-action-bar-casc.json'
if not original_control and(client/marker).exists():shutil.copyfile(client/marker,target/marker)
(game/'WTF').mkdir();(game/'WTF/Config.wtf').write_text(safe_config((client/'_classic_beta_/WTF/Config.wtf').read_text()))
return asset_copy
source_release=Path(client).parent.parent/'linux-release.json'
asset_copy=None
if source_release.is_file() and (read_json(source_release).get('private_asset_publication')is not None or read_json(source_release).get('retained_asset_publication')is not None):
proof,receipt,owner=reviewed_package_publication(Path(client),'linux-release.json')
asset_copy=dict(source=proof,retained_asset_publication=owner)
target.mkdir()
for name in PRODUCT_FILES:shutil.copyfile(client/name,target/name)
(target/'Data').mkdir()
for name in DATA_TREES:shutil.copytree(client/'Data'/name,target/'Data'/name)
game=target/'_classic_beta_';game.mkdir()
for name in GAME_FILES:shutil.copyfile(client/'_classic_beta_'/name,game/name)
for name in GAME_TREES:
if(client/'_classic_beta_'/name).exists():shutil.copytree(client/'_classic_beta_'/name,game/name)
(game/'WTF').mkdir();(game/'WTF/Config.wtf').write_text(safe_config((client/'_classic_beta_/WTF/Config.wtf').read_text()))
return asset_copy
def publish(linux,source,output,revision,base_client=None,delta_plan=None,modules=None,work_directory=None,backend_transport=None,module_profile=None,module_profile_sha256=None):
if os.name!='nt':raise RuntimeError('Run packaging on the authorized Windows VM')
linux=Path(linux);source=Path(source);output=Path(output)
from ui_release_guard import verify_inherited_ui_lineage
ui_fix_lineage=verify_inherited_ui_lineage(linux/'runtime/native-client',None,read_json(linux/'linux-release.json'))
identity=package_inputs(linux,source,output,revision,base_client,delta_plan,modules,module_profile,backend_transport,module_profile_sha256)
backend_transport=identity['backend_transport']
work=Path(work_directory)if work_directory is not None else output.parent/('windows-native-build-20261024-r2' if modules is not None else 'windows-native-build-20261022')
work.mkdir(parents=True,exist_ok=True)
receipt=work/'package-content-copied.json'
resumed=output.exists()
if resumed:
saved=json.loads(receipt.read_text())if receipt.exists()else {}
require_resume(saved,identity)
check_backend_runtime(output/'build')
asset_copy=saved.get('asset_copy')
else:
check_backend_runtime(modules)
output.mkdir();(output/'runtime').mkdir();(output/'build').mkdir();(output/'bin').mkdir()
(work/'package-progress.json').write_text(json.dumps({'phase':'copy-final-content','output':str(output)}))
asset_copy=copy_public_client(linux/'runtime/native-client',output/'runtime/native-client',base_client,delta_plan)
for name in ('ops','docs','compat'):shutil.copytree(linux/name,output/name)
for name in ('native-handler-code',):shutil.copytree(linux/'runtime'/name,output/'runtime'/name)
for file in (source/'ops').glob('*.py'):shutil.copyfile(file,output/'ops'/file.name)
python_source=(Path(base_client).parent.parent/'python') if base_client is not None else output.parent/'windows-python-runtime-20261022'
shutil.copytree(python_source,output/'python')
system=output/'runtime/native-wine-prefix/drive_c/windows/system32';system.mkdir(parents=True)
shutil.copyfile((Path(modules)/'GWNativeBridge.dll') if modules is not None else linux/'runtime/native-wine-prefix/drive_c/windows/system32/GWNativeBridge.dll',system/'GWNativeBridge.dll')
shutil.copyfile((Path(modules)/'GWNativeWire.dll') if modules is not None else output.parent/'windows-native-bridge-build-20261022/GWNativeWire.dll',system/'GWNativeWire.dll')
for folder in ([Path(modules)] if modules is not None else [output.parent/'windows-backend-build-20261022',output.parent/'windows-codec-clang-build-20261022']):
for file in folder.glob('*.dll'):
if file.name not in ('forever_codec.new.dll','GWNativeWire.dll','GWNativeBridge.dll'):shutil.copyfile(file,output/'build'/file.name)
if backend_transport=='owned-stdio-ipc-v1':
if modules is None or not(Path(modules)/'windows-backend-host.exe').is_file():raise ValueError('Explicit IPC transport requires the actual owned backend worker')
shutil.copyfile(Path(modules)/'windows-backend-host.exe',output/'build/windows-backend-host.exe')
for name,expected in identity['artifacts'].items():
dest=system/name if name in ('GWNativeBridge.dll','GWNativeWire.dll') else output/'build'/name
if digest(dest)!=expected:raise ValueError('Copied module identity differs: '+name)
shutil.copyfile(source/'launcher/launcher.py',output/'launcher.py')
(work/'package-content-copied.json').write_text(json.dumps({'output':str(output.resolve()),'content_copy_complete':True,'input_identity':identity,'asset_copy':asset_copy}))
os.environ['PATH']=r'C:\msys64\ucrt64\bin'+os.pathsep+os.environ.get('PATH','')
compiler=r'C:/msys64/ucrt64/bin/gcc.exe';cfile=source/'native/windows_launcher_entry.c'
if not resumed or not (output/'bin/ForeverBootstrap.exe').exists():
subprocess.run([compiler,'-O2','-Wall','-Wextra','-Werror','-municode','-DGW_BACKEND_ENTRY',str(cfile),'-o',str(output/'bin/ForeverBootstrap.exe')],check=True)
subprocess.run([compiler,'-O2','-Wall','-Wextra','-Werror','-municode','-mwindows',str(cfile),'-lshell32','-o',str(output/'Play-OctoWoW.exe')],check=True)
from windows_image_profile import prepare
image_profile=prepare(output/'runtime/native-client/_classic_beta_/WowB.exe')
template_path=output/'compat/native-engine-template.json';template=json.loads(template_path.read_text());template.update(image_profile);template_path.write_text(json.dumps(template,indent=2)+'\n')
(output/'compat/windows-image-profile.json').write_text(json.dumps(image_profile,indent=2)+'\n')
rows={}
for name,relative in [('client','runtime/native-client/_classic_beta_/WowB.exe'),('bridge','runtime/native-wine-prefix/drive_c/windows/system32/GWNativeBridge.dll'),('wire','runtime/native-wine-prefix/drive_c/windows/system32/GWNativeWire.dll'),('backend','build/GWNativeBackend.dll'),('codec','build/forever_codec.dll')]:rows[name]={'path':relative,'sha256':digest(output/relative)}
verify_inherited_ui_lineage(linux/'runtime/native-client',output/'runtime/native-client',{'ui_fix_lineage':ui_fix_lineage})
native_profile=dict(schema=1,**rows)
if backend_transport=='owned-stdio-ipc-v1':
rows['backend_host']={'path':'build/windows-backend-host.exe','sha256':digest(output/'build/windows-backend-host.exe')}
native_profile.update(backend_transport='owned-stdio-ipc-v1',backend_host=rows['backend_host'])
(output/'compat/windows-native.json').write_text(json.dumps(native_profile,indent=2)+'\n')
(output/'compat/launcher.json').write_text(json.dumps({'schema':1,'runtime_root':'..','platforms':{'windows':{'status':'available','backend':'bin/ForeverBootstrap.exe','sha256':digest(output/'bin/ForeverBootstrap.exe')}}},indent=2)+'\n')
notes=(linux/'BUILD-NOTES.txt').read_text();notes+='\nWindows native backend, bridge and codec built on the VM. Native DLL/ABI packet fixtures passed. Native Windows login and gameplay acceptance remain pending.\n'
(output/'BUILD-NOTES.txt').write_text(notes)
manifest={'schema_version':1,'kind':'native-Windows-client-preview','source_git_revision':revision,'package_input_identity':identity,'credentials_included':False,'source_linux_content':str(linux),'native_dlls':rows,'frontend_sha256':digest(output/'Play-OctoWoW.exe'),'known_issues':json.loads((linux/'linux-release.json').read_text()).get('known_issues',[]),'actual_windows_gameplay_verified':False}
manifest['ui_fix_lineage']=ui_fix_lineage
if asset_copy is not None:manifest['retained_asset_publication']=asset_copy['retained_asset_publication']
(output/'windows-release.json').write_text(json.dumps(manifest,indent=2)+'\n')
python=output/'python/python.exe'
if base_client is None:
subprocess.run([str(python),'-m','pip','install','--disable-pip-version-check','--no-input','capstone==5.0.9'],check=True) # New base only; retained r1 already passed this dependency.
check=subprocess.run([str(output/'Play-OctoWoW.exe'),'--check'],capture_output=True,text=True,timeout=30)
(work/'package-launcher-check.log').write_text(check.stdout+'\n'+check.stderr)
if check.returncode:raise RuntimeError('Packaged Windows launcher check failed')
(work/'package-progress.json').write_text(json.dumps({'phase':'complete','output':str(output),'launcher_check':True,'actual_gameplay_verified':False},indent=2)+'\n')
return manifest
if __name__=='__main__':
p=argparse.ArgumentParser();p.add_argument('--linux',required=True);p.add_argument('--source',required=True);p.add_argument('--output',required=True);p.add_argument('--revision',required=True);p.add_argument('--base-client');p.add_argument('--delta-plan');p.add_argument('--modules');p.add_argument('--work-directory');p.add_argument('--backend-transport',choices=['owned-stdio-ipc-v1']);p.add_argument('--module-profile',required=True);p.add_argument('--module-profile-sha256',required=True);a=p.parse_args();publish(a.linux,a.source,a.output,a.revision,a.base_client,a.delta_plan,a.modules,a.work_directory,a.backend_transport,a.module_profile,a.module_profile_sha256);print('Windows native client package and offline launcher check completed.')