Skip to content

Commit 9651f4f

Browse files
Merge pull request #1057 from fhammerschmidt/incremental-path-handling
Fix possible windows bugs in incremental compilation
2 parents 2837e08 + b70de44 commit 9651f4f

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

analysis/src/Cmt.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ let fullForCmt ~moduleName ~package ~uri cmt =
88
let extra = ProcessExtra.getExtra ~file ~infos in
99
Some {file; extra; package}
1010

11+
let ( /+ ) = Filename.concat
12+
1113
let fullFromUri ~uri =
1214
let path = Uri.toPath uri in
1315
match Packages.getPackage ~uri with
@@ -19,7 +21,7 @@ let fullFromUri ~uri =
1921
let incremental =
2022
if !Cfg.inIncrementalTypecheckingMode then
2123
let incrementalCmtPath =
22-
package.rootPath ^ "/lib/bs/___incremental" ^ "/" ^ moduleName
24+
(package.rootPath /+ "lib" /+ "bs" /+ "___incremental" /+ moduleName)
2325
^
2426
match Files.classifySourceFile path with
2527
| Resi -> ".cmti"

server/src/constants.ts

+2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ export let bsbLock = ".bsb.lock";
4343
export let bsconfigPartialPath = "bsconfig.json";
4444
export let rescriptJsonPartialPath = "rescript.json";
4545
export let compilerDirPartialPath = path.join("lib", "bs");
46+
export let compilerOcamlDirPartialPath = path.join("lib", "ocaml");
4647
export let compilerLogPartialPath = path.join("lib", "bs", ".compiler.log");
4748
export let buildNinjaPartialPath = path.join("lib", "bs", "build.ninja");
49+
export let rewatchLockPartialPath = path.join("lib", "rewatch.lock");
4850
export let resExt = ".res";
4951
export let resiExt = ".resi";
5052
export let cmiExt = ".cmi";

server/src/incrementalCompilation.ts

+23-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ function debug() {
1919
}
2020

2121
const INCREMENTAL_FOLDER_NAME = "___incremental";
22-
const INCREMENTAL_FILE_FOLDER_LOCATION = `lib/bs/${INCREMENTAL_FOLDER_NAME}`;
22+
const INCREMENTAL_FILE_FOLDER_LOCATION = path.join(
23+
c.compilerDirPartialPath,
24+
INCREMENTAL_FOLDER_NAME
25+
);
2326

2427
type RewatchCompilerArgs = {
2528
compiler_args: Array<string>;
@@ -190,11 +193,11 @@ function getBscArgs(
190193
): Promise<Array<string> | RewatchCompilerArgs | null> {
191194
const buildNinjaPath = path.resolve(
192195
entry.project.rootPath,
193-
"lib/bs/build.ninja"
196+
c.buildNinjaPartialPath
194197
);
195198
const rewatchLockfile = path.resolve(
196199
entry.project.workspaceRootPath,
197-
"lib/rewatch.lock"
200+
c.rewatchLockPartialPath
198201
);
199202
let buildSystem: "bsb" | "rewatch" | null = null;
200203

@@ -246,7 +249,13 @@ function getBscArgs(
246249
}
247250

248251
if (buildSystem === "bsb") {
249-
const fileStream = fs.createReadStream(buildNinjaPath);
252+
const fileStream = fs.createReadStream(buildNinjaPath, {
253+
encoding: "utf8",
254+
});
255+
fileStream.on("error", (err) => {
256+
console.error("File stream error:", err);
257+
resolveResult([]);
258+
});
250259
const rl = readline.createInterface({
251260
input: fileStream,
252261
crlfDelay: Infinity,
@@ -256,6 +265,7 @@ function getBscArgs(
256265
let stopped = false;
257266
const captured: Array<string> = [];
258267
rl.on("line", (line) => {
268+
line = line.trim(); // Normalize line endings
259269
if (stopped) {
260270
return;
261271
}
@@ -264,7 +274,8 @@ function getBscArgs(
264274
captureNextLine = false;
265275
}
266276
if (done) {
267-
fileStream.destroy();
277+
// Not sure if fileStream.destroy is necessary, rl.close() will handle it gracefully.
278+
// fileStream.destroy();
268279
rl.close();
269280
resolveResult(captured);
270281
stopped = true;
@@ -278,6 +289,10 @@ function getBscArgs(
278289
done = true;
279290
}
280291
});
292+
rl.on("error", (err) => {
293+
console.error("Readline error:", err);
294+
resolveResult([]);
295+
});
281296
rl.on("close", () => {
282297
resolveResult(captured);
283298
});
@@ -399,7 +414,7 @@ function triggerIncrementalCompilationOfFile(
399414

400415
let originalTypeFileLocation = path.resolve(
401416
projectRootPath,
402-
"lib/bs",
417+
c.compilerDirPartialPath,
403418
path.relative(projectRootPath, filePath)
404419
);
405420

@@ -512,13 +527,13 @@ async function figureOutBscArgs(entry: IncrementallyCompiledFileInfo) {
512527
if (isBsb) {
513528
callArgs.push(
514529
"-I",
515-
path.resolve(entry.project.rootPath, "lib/bs", value)
530+
path.resolve(entry.project.rootPath, c.compilerDirPartialPath, value)
516531
);
517532
} else {
518533
if (value === ".") {
519534
callArgs.push(
520535
"-I",
521-
path.resolve(entry.project.rootPath, "lib/ocaml")
536+
path.resolve(entry.project.rootPath, c.compilerOcamlDirPartialPath)
522537
);
523538
} else {
524539
callArgs.push("-I", value);

0 commit comments

Comments
 (0)