1
0

build-test-oracle.mjs 1.2 KB

1234567891011121314151617181920212223
  1. /** Build the independent POSIX flock oracle used by native behavior tests. */
  2. import fs from 'node:fs';
  3. import path from 'node:path';
  4. import { fileURLToPath } from 'node:url';
  5. import { spawnSync } from 'node:child_process';
  6. const root = fileURLToPath(new URL('..', import.meta.url));
  7. if (process.platform !== 'linux' && process.platform !== 'darwin') {
  8. throw new Error('The flock oracle is a POSIX test fixture');
  9. }
  10. const variants = process.platform === 'linux' ? ['glibc', 'musl'] : [''];
  11. for (const variant of variants) {
  12. const compiler = variant === 'musl' ? 'musl-gcc' : 'cc';
  13. const output = path.join(root, 'test/bin', variant, 'flock-oracle');
  14. fs.mkdirSync(path.dirname(output), { recursive: true });
  15. const args = ['-std=c11', '-O2', '-Wall', '-Wextra', '-Werror'];
  16. if (process.platform === 'darwin') args.push('-mmacosx-version-min=11.0');
  17. if (variant === 'musl') args.push('-static');
  18. const result = spawnSync(compiler, [...args, path.join(root, 'test/fixtures/flock-oracle.c'), '-o', output], { stdio: 'inherit' });
  19. if (result.error) throw result.error;
  20. if (result.status !== 0) throw new Error(`${compiler} failed to build the flock oracle`);
  21. console.log(`Built test oracle ${path.relative(root, output)}`);
  22. }