summaryrefslogtreecommitdiff
path: root/tests/helpers/package_cocoa_tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/helpers/package_cocoa_tests.py')
-rw-r--r--tests/helpers/package_cocoa_tests.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/helpers/package_cocoa_tests.py b/tests/helpers/package_cocoa_tests.py
new file mode 100644
index 0000000..8f801f8
--- /dev/null
+++ b/tests/helpers/package_cocoa_tests.py
@@ -0,0 +1,70 @@
+#!/usr/bin/env python3
+"""Package compiled Cocoa tests for execution on a matching macOS desktop."""
+
+import argparse
+import hashlib
+import json
+from pathlib import Path
+import shutil
+import tarfile
+import tempfile
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('build', type=Path)
+ parser.add_argument('output', type=Path)
+ args = parser.parse_args()
+ build = args.build.resolve()
+ info = build / 'meson-info'
+ host = json.loads((info / 'intro-machines.json').read_text())['host']
+ if host['system'] != 'darwin':
+ parser.error('Use a configured and compiled Cocoa build.')
+ tests = json.loads((info / 'intro-tests.json').read_text())
+ required = {'native', 'native-ownership', 'keyboard-cocoa', 'tablet-cocoa',
+ 'cursor-cocoa', 'hello-cocoa-window', 'tablet-cocoa-window'}
+ missing = required - {test['name'] for test in tests}
+ if missing:
+ parser.error('Enable integration_tests; missing: ' + ', '.join(sorted(missing)))
+ options = json.loads((info / 'intro-buildoptions.json').read_text())
+ sanitizer = next(option['value'] for option in options if option['name'] == 'b_sanitize')
+ if sanitizer not in ('none', [], ['none']):
+ parser.error('Use an unsanitized build; sanitizer runtimes are not bundled.')
+
+ with tempfile.TemporaryDirectory(prefix='yasl-cocoa-bundle-') as directory:
+ root = Path(directory) / 'yasl-cocoa-tests'
+ root.mkdir()
+ files = {}
+
+ def copy(source, relative):
+ destination = root / relative
+ destination.parent.mkdir(parents=True, exist_ok=True)
+ shutil.copy2(source, destination)
+ files[str(relative)] = hashlib.sha256(destination.read_bytes()).hexdigest()
+
+ copy(build / 'libyasl.dylib', Path('libyasl.dylib'))
+ source_root = Path(__file__).resolve().parents[2]
+ copy(source_root / 'LICENSE', Path('LICENSE'))
+ copy(Path(__file__).with_name('run_cocoa_bundle.py'), Path('run.py'))
+ commands = []
+ for test in tests:
+ if test['name'] == 'public-exports':
+ continue # Check the dylib with nm on the build machine first.
+ executable = Path(test['cmd'][0]).resolve()
+ try:
+ relative = executable.relative_to(build)
+ except ValueError:
+ parser.error('Unexpected external test command: ' + str(executable))
+ copy(executable, relative)
+ commands.append({'name': test['name'], 'cmd': [str(relative), *test['cmd'][1:]],
+ 'timeout': test['timeout']})
+ manifest = {'architecture': host['cpu_family'], 'minimum_macos': 14,
+ 'tests': commands, 'sha256': files}
+ (root / 'manifest.json').write_text(json.dumps(manifest, indent=2) + '\n')
+ with tarfile.open(args.output, 'w:gz') as archive:
+ archive.add(root, arcname=root.name)
+ print(f'Packaged {len(commands)} runtime tests for {host["cpu_family"]}: {args.output}')
+
+
+if __name__ == '__main__':
+ main()