Files
bun.sh/src/codegen/create-hash-table.ts
Mike Dotty e1489d4fe3 Stop swallowing errors from create_hash_table during the build (#7086)
If src/codegen/create_hash_table can't be run due to some reason
(e.g. due to missing Math::BigInt Perl module) the build continues
but fails later, during bindings compilation, because the generated
files are empty.

Fix it by handling the failure to run create_hash_table properly.

Closes #7074
2023-11-13 13:46:20 -08:00

28 lines
872 B
TypeScript

import { spawn } from "bun";
import path from "path";
import { writeIfNotChanged } from "./helpers";
const input = process.argv[2];
const output = process.argv[3];
const create_hash_table = path.join(import.meta.dir, "./create_hash_table");
const { stdout, exited } = spawn({
cmd: [create_hash_table, input],
stdout: "pipe",
stderr: "inherit",
});
const procResult = await exited;
if (procResult.exitCode !== 0) {
console.log("Failed to generate " + output + ", create_hash_table exited with " + procResult);
process.exit(1);
}
let str = await new Response(stdout).text();
str = str.replaceAll(/^\/\/.*$/gm, "");
str = str.replaceAll(/^#include.*$/gm, "");
str = str.replaceAll(`namespace JSC {`, "");
str = str.replaceAll(`} // namespace JSC`, "");
str = "// File generated via `static-hash-table.ts`\n" + str.trim() + "\n";
writeIfNotChanged(output, str);