summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Pouillard <np@nicolaspouillard.fr>2010-02-03 13:11:19 +0000
committerNicolas Pouillard <np@nicolaspouillard.fr>2010-02-03 13:11:19 +0000
commita463a1b0a6c848534756ea09e3d5aa1c0b138dee (patch)
treea13a262f2dd6a24764f247d4dc56eba4071f5b2b
parent8822cbb173d1ed2b6e3f7762ff7562f67c697fec (diff)
downloadocaml-a463a1b0a6c848534756ea09e3d5aa1c0b138dee.tar.gz
ocamlbuild: fix a bug about $PATH
Replace the colon_sep_strings lexing function by parse_environment_path which better account for leading or trailing colons. git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@9611 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--ocamlbuild/command.ml10
-rw-r--r--ocamlbuild/lexers.mli10
-rw-r--r--ocamlbuild/lexers.mll13
3 files changed, 21 insertions, 12 deletions
diff --git a/ocamlbuild/command.ml b/ocamlbuild/command.ml
index b5488eb5fe..131cd8586c 100644
--- a/ocamlbuild/command.ml
+++ b/ocamlbuild/command.ml
@@ -91,7 +91,15 @@ let atomize_paths l = S(List.map (fun x -> P x) l)
let env_path = lazy begin
let path_var = Sys.getenv "PATH" in
- Lexers.colon_sep_strings (Lexing.from_string path_var)
+ let paths =
+ try
+ Lexers.parse_environment_path (Lexing.from_string path_var)
+ with Lexers.Error msg -> raise (Lexers.Error ("$PATH: " ^ msg))
+ in
+ let norm_current_dir_name path =
+ if path = "" then Filename.current_dir_name else path
+ in
+ List.map norm_current_dir_name paths
end
let virtual_solvers = Hashtbl.create 32
diff --git a/ocamlbuild/lexers.mli b/ocamlbuild/lexers.mli
index 5fc1d9283b..2f37edca64 100644
--- a/ocamlbuild/lexers.mli
+++ b/ocamlbuild/lexers.mli
@@ -26,10 +26,12 @@ val comma_sep_strings : Lexing.lexbuf -> string list
val comma_or_blank_sep_strings : Lexing.lexbuf -> string list
val trim_blanks : Lexing.lexbuf -> string
-(* Parse a colon separated string.
- Note: successive colons are ignored.
- Example: "aaa:bbb:::ccc" -> ["aaa"; "bbb"; "ccc"] *)
-val colon_sep_strings : Lexing.lexbuf -> string list
+(* Parse an environment path (i.e. $PATH).
+ This is a colon separated string.
+ Note: successive colons means an empty string.
+ Example:
+ ":aaa:bbb:::ccc:" -> [""; "aaa"; "bbb"; ""; ""; "ccc"; ""] *)
+val parse_environment_path : Lexing.lexbuf -> string list
val conf_lines : string option -> int -> string -> Lexing.lexbuf -> conf
val path_scheme : bool -> Lexing.lexbuf ->
diff --git a/ocamlbuild/lexers.mll b/ocamlbuild/lexers.mll
index 97240d9c1d..7b191b0d97 100644
--- a/ocamlbuild/lexers.mll
+++ b/ocamlbuild/lexers.mll
@@ -81,15 +81,14 @@ and comma_or_blank_sep_strings_aux = parse
| space* eof { [] }
| _ { raise (Error "Expecting (comma|blank)-separated strings (2)") }
-and colon_sep_strings = parse
- | ([^ ':']+ as word) eof { [word] }
- | ([^ ':']+ as word) { word :: colon_sep_strings_aux lexbuf }
+and parse_environment_path = parse
+ | ([^ ':']* as word) { word :: parse_environment_path_aux lexbuf }
+ | ':' ([^ ':']* as word) { "" :: word :: parse_environment_path_aux lexbuf }
| eof { [] }
- | _ { raise (Error "Expecting colon-separated strings (1)") }
-and colon_sep_strings_aux = parse
- | ':'+ ([^ ':']+ as word) { word :: colon_sep_strings_aux lexbuf }
+and parse_environment_path_aux = parse
+ | ':' ([^ ':']* as word) { word :: parse_environment_path_aux lexbuf }
| eof { [] }
- | _ { raise (Error "Expecting colon-separated strings (2)") }
+ | _ { raise (Error "Impossible: expecting colon-separated strings") }
and conf_lines dir pos err = parse
| space* '#' not_newline* newline { conf_lines dir (pos + 1) err lexbuf }