Files
bun.sh/src/codegen/create-hash-table.ts
Mike Dotty 3eb086f5fa fix(dx): Stop swallowing errors from create_hash_table during the build (#7110)
* Stop swallowing errors from create_hash_table during the build

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

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2023-11-17 13:45:32 -08:00

34 lines
913 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 proc = spawn({
cmd: [create_hash_table, input],
stdout: "pipe",
stderr: "inherit",
});
await proc.exited;
if (proc.exitCode !== 0) {
console.log(
"Failed to generate " +
output +
", create_hash_table exited with " +
(proc.exitCode || "") +
(proc.signalCode || ""),
);
process.exit(1);
}
let str = await new Response(proc.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);