Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows fixes + OCAMLPATH compatibility #170

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/indexOptions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ let filter opt info =
| ModuleType | ClassType -> kinds.s
| Keyword -> kinds.k

let null_file = if Sys.win32 then "NUL" else "/dev/null"

let cmd_input_line cmd =
try
let ic = Unix.open_process_in (cmd ^ " 2>/dev/null") in
let ic = Unix.open_process_in (Printf.sprintf "%s 2>%s" cmd null_file) in
let r = input_line ic in
let r =
let len = String.length r in
Expand All @@ -72,6 +74,15 @@ let filter_to_string l =
in
String.concat "," (List.map pp l)

let initial_cwd = Sys.getcwd ()

let path_sep = if Sys.win32 then ';' else ':'

let parse_path_var s =
let l = String.split_on_char path_sep s in
let l = List.filter (fun s -> s <> "") l in
List.map (fun path -> if Filename.is_relative path then Filename.concat initial_cwd path else path) l

let common_opts ?(default_filter = default_filter) () : t Term.t =
let ocamllib : string list Term.t =
let no_stdlib : bool Term.t =
Expand All @@ -90,6 +101,11 @@ let common_opts ?(default_filter = default_filter) () : t Term.t =
in
let set_default no_stdlib no_opamlib includes =
let paths = List.flatten includes in
let paths =
match Sys.getenv "OCAMLPATH" with
| exception Not_found -> paths
| s -> parse_path_var s @ paths
in
let paths =
if no_opamlib then paths else
try cmd_input_line "opam config var lib" :: paths
Expand Down
Loading