diff --git a/examples/example-esy-dune-project/lib/.merlin b/examples/example-esy-dune-project/lib/.merlin index 637ce484..17730d88 100644 --- a/examples/example-esy-dune-project/lib/.merlin +++ b/examples/example-esy-dune-project/lib/.merlin @@ -1,4 +1,4 @@ EXCLUDE_QUERY_DIR -B /Users/jared/clone/tools/reason-language-server/examples/example-esy-dune-project/_esy/default/store/b/hello-bb5af4c3/default/lib/.lib.objs/byte +B C:/Users/User/clone/reason-language-server/examples/example-esy-dune-project/_esy/default/store/b/hello-022fadb7\default/lib/.lib.objs/byte S . FLG -open Lib -w -40 diff --git a/src/analyze/BuildSystem.re b/src/analyze/BuildSystem.re index 7722a24c..36720b29 100644 --- a/src/analyze/BuildSystem.re +++ b/src/analyze/BuildSystem.re @@ -187,8 +187,17 @@ let detectFull = projectDir => { let getEsyCompiledBase = () => { let env = Unix.environment()->Array.to_list; + let correctSlashesOnWindows = (p) => { + if (Sys.win32) { + let slashRegex = Str.regexp("/"); + Str.global_replace(slashRegex, "\\\\", p); + } else { + p + } + }; + switch(Utils.getEnvVar(~env, "cur__original_root"), Utils.getEnvVar(~env, "cur__target_dir")) { - | (Some(projectRoot), Some(targetDir)) => Ok(Files.relpath(projectRoot, targetDir)) + | (Some(projectRoot), Some(targetDir)) => Ok(Files.relpath(correctSlashesOnWindows(projectRoot), correctSlashesOnWindows(targetDir))) | (_, _) => switch (Commands.execResult("esy command-env --json")) { | Ok(commandEnv) => @@ -206,7 +215,7 @@ let getEsyCompiledBase = () => { Json.get("cur__original_root", json) |?> Json.string, Json.get("cur__target_dir", json) |?> Json.string, ) { - | (Some(projectRoot), Some(targetDir)) => Ok(Files.relpath(projectRoot, targetDir)) + | (Some(projectRoot), Some(targetDir)) => Ok(Files.relpath(correctSlashesOnWindows(projectRoot), correctSlashesOnWindows(targetDir))) | _ => Error("Couldn't find Esy target directory (missing json entries)") } ) @@ -276,9 +285,10 @@ let getStdlib = (base, buildSystem) => { switch (Utils.getEnvVar(~env, "OCAMLLIB")) { | Some(esy_ocamllib) => Ok([esy_ocamllib]) | None => - let command = v < "0.5.6" ? - "esy -q sh -- -c 'echo $OCAMLLIB'" : "esy -q sh -c 'echo $OCAMLLIB'"; - let%try_wrap esy_ocamllib = getLine(command, ~pwd=base); + let echoCommand = Filename.quote("echo $OCAMLLIB"); + let commandPrefix = v < "0.5.6" ? + "esy -q sh -- -c " : "esy -q sh -c "; + let%try_wrap esy_ocamllib = getLine(commandPrefix ++ echoCommand, ~pwd=base); [esy_ocamllib]; }; | Dune(Opam(switchPrefix)) => @@ -293,12 +303,13 @@ let isRunningInEsyNamedSandbox = () => { }; let getExecutableInEsyPath = (exeName, ~pwd) => { + let whichCommand = Sys.win32 ? "where" : "which" let ret = if (isRunningInEsyNamedSandbox()) { - getLine("which " ++ exeName, ~pwd) + getLine(whichCommand ++ " " ++ exeName, ~pwd) } else { - getLine("esy which " ++ exeName, ~pwd) + getLine("esy " ++ whichCommand ++ " " ++ exeName, ~pwd) }; - if (Sys.win32) { + /*if (Sys.win32) { switch ret { | RResult.Ok(ret) => let ret = if (isRunningInEsyNamedSandbox()) { @@ -309,9 +320,9 @@ let getExecutableInEsyPath = (exeName, ~pwd) => { ret | Error(a) => Error(a) } - } else { + } else {*/ ret - } + //} }; let getCompiler = (rootPath, buildSystem) => { diff --git a/src/analyze_example_tests/ExamplesTests.re b/src/analyze_example_tests/ExamplesTests.re index a0f88772..c814d653 100644 --- a/src/analyze_example_tests/ExamplesTests.re +++ b/src/analyze_example_tests/ExamplesTests.re @@ -54,7 +54,6 @@ let checkExampleProject = (describe, name, rootPath, sourcePaths, prepareCommand let esyProjects = [ ("dune", ["src", "both"], "esy"), ("dune-complex", ["src", "both", "awesome"], "esy"), - ("example-esy-dune-project", ["lib", "bin"], "esy"), ]; // Don't run the esy examples on windows, they're failing right now. @@ -64,6 +63,7 @@ let projects = (Sys.os_type == "Unix" ? esyProjects : []) @ [ ("example-react", ["src", "__tests__"], "npm install"), ("name_with_underscore", ["src"], "npm install"), ("bs-3.1.5", ["src"], "npm install"), + ("example-esy-dune-project", ["lib", "bin"], "esy"), ]; // let main = (baseDir, _verbose, args) => { @@ -118,4 +118,4 @@ let baseDir = Sys.getcwd(); // | `FileFail(uri, message) => print_endline("- Failed to get compilation info for " ++ uri ++ " : " ++ message) // }); // exit(10) -// } \ No newline at end of file +// } diff --git a/util/Commands.re b/util/Commands.re index e2fbe25d..8dd3507d 100644 --- a/util/Commands.re +++ b/util/Commands.re @@ -2,18 +2,8 @@ let shellEscape = path => Filename.quote(path); -let execFull = (~input=?, ~pwd=?, ~env=Unix.environment(), cmd) => { - let cmd = - if (Sys.os_type == "Win32") { - Printf.sprintf("\"%s\"", cmd) - } else { - cmd - } - let env = switch pwd { - | None => env - | Some(pwd) => Array.map(item => String.length(item) > 4 && String.sub(item, 0, 4) == "PWD=" ? "PWD=" ++ pwd : item, env) - }; - let prevCwd = switch pwd { +let withCwd = (~cwd, f) => { + let prevCwd = switch cwd { | None => None | Some(pwd) => let prevCwd = Unix.getcwd(); @@ -24,11 +14,32 @@ let execFull = (~input=?, ~pwd=?, ~env=Unix.environment(), cmd) => { Some(prevCwd) } } - let (cmd_out, cmd_in, cmd_err) = Unix.open_process_full(cmd, env); + + let ret = f(); + switch prevCwd { | None => () | Some(prevCwd) => Unix.chdir(prevCwd) }; + + ret; +}; + +let execFull = (~input=?, ~pwd=?, ~env=Unix.environment(), cmd) => { + let cmd = + if (Sys.os_type == "Win32") { + Printf.sprintf("\"%s\"", cmd) + } else { + cmd + } + let env = switch pwd { + | None => env + | Some(pwd) => Array.map(item => String.length(item) > 4 && String.sub(item, 0, 4) == "PWD=" ? "PWD=" ++ pwd : item, env) + }; + + let (cmd_out, cmd_in, cmd_err) = withCwd(~cwd=pwd, () => { + Unix.open_process_full(cmd, env); + }) switch input { | None => () @@ -104,8 +115,8 @@ let execOption = cmd => { } }; -let execResult = cmd => { - let (lines, success) = execSync(cmd); +let execResult = (~cwd=?, cmd) => { + let (lines, success) = withCwd(~cwd, () => execSync(cmd)); if (success) { RResult.Ok(String.concat("\n", lines)) } else { diff --git a/util/Infix.re b/util/Infix.re index 4f737f02..291ecbcb 100644 --- a/util/Infix.re +++ b/util/Infix.re @@ -43,4 +43,4 @@ let maybeConcat = (a, b) => { } }; -let (/+) = fileConcat; \ No newline at end of file +let (/+) = fileConcat;