Skip to content

Commit

Permalink
Fix possible windows bugs in incremental compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
fhammerschmidt committed Nov 21, 2024
1 parent 2837e08 commit 816b945
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions server/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export let rescriptJsonPartialPath = "rescript.json";
export let compilerDirPartialPath = path.join("lib", "bs");
export let compilerLogPartialPath = path.join("lib", "bs", ".compiler.log");
export let buildNinjaPartialPath = path.join("lib", "bs", "build.ninja");
export let rewatchLockPartialPath = path.join("lib", "rewatch.lock");
export let resExt = ".res";
export let resiExt = ".resi";
export let cmiExt = ".cmi";
Expand Down
22 changes: 17 additions & 5 deletions server/src/incrementalCompilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ function getBscArgs(
): Promise<Array<string> | RewatchCompilerArgs | null> {
const buildNinjaPath = path.resolve(
entry.project.rootPath,
"lib/bs/build.ninja"
c.buildNinjaPartialPath
);
const rewatchLockfile = path.resolve(
entry.project.workspaceRootPath,
"lib/rewatch.lock"
c.rewatchLockPartialPath
);
let buildSystem: "bsb" | "rewatch" | null = null;

Expand Down Expand Up @@ -246,7 +246,13 @@ function getBscArgs(
}

if (buildSystem === "bsb") {
const fileStream = fs.createReadStream(buildNinjaPath);
const fileStream = fs.createReadStream(buildNinjaPath, {
encoding: "utf8",
});
fileStream.on("error", (err) => {
console.error("File stream error:", err);
resolveResult([]);
});
const rl = readline.createInterface({
input: fileStream,
crlfDelay: Infinity,
Expand All @@ -256,6 +262,7 @@ function getBscArgs(
let stopped = false;
const captured: Array<string> = [];
rl.on("line", (line) => {
line = line.trim(); // Normalize line endings
if (stopped) {
return;
}
Expand All @@ -264,7 +271,8 @@ function getBscArgs(
captureNextLine = false;
}
if (done) {
fileStream.destroy();
// Not sure if fileStream.destroy is necessary, rl.close() will handle it gracefully.
// fileStream.destroy();
rl.close();
resolveResult(captured);
stopped = true;
Expand All @@ -278,6 +286,10 @@ function getBscArgs(
done = true;
}
});
rl.on("error", (err) => {
console.error("Readline error:", err);
resolveResult([]);
});
rl.on("close", () => {
resolveResult(captured);
});
Expand Down Expand Up @@ -399,7 +411,7 @@ function triggerIncrementalCompilationOfFile(

let originalTypeFileLocation = path.resolve(
projectRootPath,
"lib/bs",
c.compilerDirPartialPath,
path.relative(projectRootPath, filePath)
);

Expand Down

0 comments on commit 816b945

Please sign in to comment.