aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


tools/client/export_game.py (1845B)


      1 """Export the verified game sources for editing and building from client/."""
      2 
      3 import json
      4 import pathlib
      5 import shutil
      6 
      7 
      8 root = pathlib.Path(__file__).resolve().parents[2]
      9 work = root / 'local/client/game-14.9.1'
     10 destination = root / 'local/client/source-export-14.9.1'
     11 scope = json.loads((work / 'scope.json').read_text())
     12 assert scope == json.loads((root / 'client/scope.json').read_text())
     13 
     14 # Never regenerate over the editable source tree.
     15 for name in ('game', 'runtime', 'data'):
     16     assert not (destination / name).exists(), f'{destination / name} already exists'
     17 for name in ('game', 'runtime', 'data'):
     18     (destination / name).mkdir(parents=True)
     19 
     20 # Export only active compilation units, excluding obsolete experimental batches.
     21 for module in scope['game']:
     22     directory = work / module['name']
     23     completed = json.loads((directory / 'completed.json').read_text())
     24     (destination / 'game' / module['name']).mkdir()
     25     for obj in completed['objects']:
     26         source = pathlib.Path(obj).with_suffix('.c')
     27         shutil.copy2(source, destination / 'game' / module['name'] / source.name)
     28 for name in ('dispatch.c', 'game-modules.h'):
     29     shutil.copy2(work / name, destination / 'game' / name)
     30 for name in ('scope.json', 'translation.json', 'completion-audit.json'):
     31     shutil.copy2(work / name, destination / name)
     32 
     33 # Keep the standalone runtime and extracted source initializers with the game C.
     34 for name in ('runtime', 'data'):
     35     shutil.copytree(root / 'client' / name, destination / name, dirs_exist_ok=True)
     36 
     37 # Reuse the maintained build files when staging a fresh generated snapshot.
     38 for name in ('Makefile', 'Makefile.windows', 'Makefile.linux', '.gitignore', '.gitattributes', 'README.md'):
     39     shutil.copy2(root / 'client' / name, destination / name)
     40 print(f'Exported {len(scope["game"])} game modules to {destination}')