Skip to content

Commit 0e6a978

Browse files
committed
Run bsc from lib/bs
1 parent 87a5982 commit 0e6a978

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

server/src/incrementalCompilation.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type IncrementallyCompiledFileInfo = {
4646
/** Location of the original type file. */
4747
originalTypeFileLocation: string;
4848
};
49+
buildSystem: "bsb" | "rewatch";
4950
/** Cache for build.ninja assets. */
5051
buildNinja: {
5152
/** When build.ninja was last modified. Used as a cache key. */
@@ -226,11 +227,13 @@ function getBscArgs(
226227
return new Promise(async(resolve, _reject) => {
227228
function resolveResult(result: Array<string> | RewatchCompilerArgs) {
228229
if (stat != null && Array.isArray(result)) {
230+
entry.buildSystem = "bsb";
229231
entry.buildNinja = {
230232
fileMtime: stat.mtimeMs,
231233
rawExtracted: result,
232234
};
233235
} else if (!Array.isArray(result)) {
236+
entry.buildSystem = "rewatch";
234237
entry.buildRewatch = {
235238
lastFile: entry.file.sourceFilePath,
236239
compilerArgs: result,
@@ -459,6 +462,7 @@ function triggerIncrementalCompilationOfFile(
459462
bscBinaryLocation,
460463
incrementalFolderPath,
461464
},
465+
buildSystem: foundRewatchLockfileInProjectRoot ? "rewatch" : "bsb",
462466
buildRewatch: null,
463467
buildNinja: null,
464468
compilation: null,
@@ -545,15 +549,12 @@ async function figureOutBscArgs(entry: IncrementallyCompiledFileInfo) {
545549
path.resolve(entry.project.rootPath, c.compilerDirPartialPath, value)
546550
);
547551
} else {
552+
// TODO: once ReScript v12 is out we can remove this check for `.`
548553
if (value === ".") {
549554
callArgs.push(
550555
"-I",
551556
path.resolve(entry.project.rootPath, c.compilerOcamlDirPartialPath)
552557
);
553-
} else if (value.startsWith("..") && value.endsWith("ocaml")) {
554-
// This should be the lib/ocaml folder of the project
555-
// This is a hack to support incremental compilation in monorepos
556-
callArgs.push("-I", path.resolve(entry.project.incrementalFolderPath, "..", "..", "ocaml"));
557558
} else {
558559
callArgs.push("-I", value);
559560
}
@@ -622,11 +623,15 @@ async function compileContents(
622623

623624
try {
624625
fs.writeFileSync(entry.file.incrementalFilePath, fileContent);
625-
626+
let cwd = entry.buildSystem === "bsb" ? entry.project.rootPath : path.resolve(entry.project.rootPath, c.compilerDirPartialPath)
627+
if (debug()) {
628+
console.log(`About to invoke bsc from \"${cwd}\", used ${entry.buildSystem}`);
629+
console.log(`${entry.project.bscBinaryLocation} ${callArgs.map(c => `"${c}"`).join(" ")}`);
630+
}
626631
const process = cp.execFile(
627632
entry.project.bscBinaryLocation,
628633
callArgs,
629-
{ cwd: entry.project.rootPath },
634+
{ cwd },
630635
async (error, _stdout, stderr) => {
631636
if (!error?.killed) {
632637
if (debug())

0 commit comments

Comments
 (0)