#!/usr/bin/env python3 """Run sibling hash partitions in one lease, retaining compiled artifacts.""" from pathlib import Path import re import subprocess import sys def main(arguments): if (len(arguments) < 8 or arguments[:6] != [ 'nextest', 'run', '--profile', 'fast', '--no-fail-fast', '--partition']): print('paired shards require a fast, non-fail-fast hash partition', file=sys.stderr) return 2 part = re.fullmatch(r'hash:([1-9][0-9]*)/([1-9][0-9]*)', arguments[6]) if not part: return 2 number, total = map(int, part.groups()) if number > total: return 2 wrapper = Path(__file__).with_name('cargo-test-with-one-retry.sh') status = 0 passed = False empty = False for index in (2 * number - 1, 2 * number): command = [*arguments[:6], f'hash:{index}/{2 * total}', *arguments[7:]] print('[cargo-paired-shard] ' + ' '.join(command), flush=True) result = subprocess.run(['bash', str(wrapper), *command]).returncode # Complete both original partitions after a real failure. The retry # wrapper still retries only a missing binary, never a failed case. if result == 4: empty = True elif result and not status: status = result elif result == 0: passed = True return status or (4 if empty and not passed else 0) if __name__ == '__main__': sys.exit(main(sys.argv[1:]))