Skip to content

Commit 479bbeb

Browse files
committed
Fix refmt location and parsing ocaml-version
1 parent 6338bb1 commit 479bbeb

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/analyze/BuildSystem.re

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ let getCompilerVersion = executable => {
146146
let (output, success) = Commands.execSync(cmd);
147147
success ? switch output {
148148
| [line] when Str.string_match(Str.regexp_string("BuckleScript "), line, 0) =>
149-
switch (Str.split(Str.regexp_string("(Using OCaml"), String.trim(line))) {
149+
switch (Str.split(Str.regexp("( *Using OCaml:?"), String.trim(line))) {
150150
| [_, version] => parseOCamlVersion(version)
151-
| _ => Error("Cannot detect OCaml version from BuckleScript version string: " ++ line)
151+
| xs => Error("Cannot detect OCaml version from BuckleScript version string: " ++ line ++ "[" ++ String.concat(" ;", xs) ++ "]")
152152
}
153153
| [line] => parseOCamlVersion(line)
154154
| _ => Error("Unable to determine compiler version (ran " ++ cmd ++ "). Output: " ++ String.concat("\n", output))
@@ -350,19 +350,28 @@ let getCompiler = (rootPath, buildSystem) => {
350350
};
351351

352352
let getRefmt = (rootPath, buildSystem) => {
353+
let bsRefmt = (bsPlatformDir) =>
354+
switch (Files.ifExists(bsPlatformDir/+"lib"/+"refmt.exe")){
355+
| Some (x) => x
356+
| None =>
357+
switch(Files.ifExists(bsPlatformDir /+ nodePlatform /+ "refmt.exe")){
358+
| Some (x) => x
359+
| None => bsPlatformDir /+ "lib" /+ "refmt3.exe"
360+
}
361+
}
353362
switch (buildSystem) {
354363
| BsbNative("3.2.0", _) =>
355364
let%try_wrap bsPlatformDir = getBsPlatformDir(rootPath);
356-
bsPlatformDir /+ "lib" /+ "refmt.exe"
365+
bsRefmt(bsPlatformDir)
357366
| Bsb(version) when version > "2.2.0" =>
358367
let%try_wrap bsPlatformDir = getBsPlatformDir(rootPath);
359-
bsPlatformDir /+ "lib" /+ "refmt.exe"
368+
bsRefmt(bsPlatformDir)
360369
| BsbNative(version, _) when version >= "4.0.6" =>
361370
let%try_wrap bsPlatformDir = getBsPlatformDir(rootPath);
362-
bsPlatformDir /+ "lib" /+ "refmt.exe"
371+
bsRefmt(bsPlatformDir)
363372
| Bsb(_) | BsbNative(_, _) =>
364373
let%try_wrap bsPlatformDir = getBsPlatformDir(rootPath);
365-
bsPlatformDir /+ "lib" /+ "refmt3.exe"
374+
bsRefmt(bsPlatformDir)
366375
| Dune(Esy(_)) => getExecutableInEsyPath("refmt",~pwd=rootPath)
367376
| Dune(Opam(switchPrefix)) =>
368377
Ok(switchPrefix /+ "bin" /+ "refmt")

0 commit comments

Comments
 (0)