diff options
| author | Sébastien Hinderer <Sebastien.Hinderer@inria.fr> | 2018-02-19 16:33:53 +0100 |
|---|---|---|
| committer | Sébastien Hinderer <Sebastien.Hinderer@inria.fr> | 2018-02-20 08:30:46 +0100 |
| commit | f0e2b2c463d92dc482a6bca163873fe03451c2af (patch) | |
| tree | f9dd92b74fdd9d64ac174a4833344e54f5be3815 | |
| parent | 59bc6e1f986d2027563a5f7b627f07b6d8cdb190 (diff) | |
| download | ocaml-f0e2b2c463d92dc482a6bca163873fe03451c2af.tar.gz | |
ocamltest: expand variables before exporting them to system env
| -rw-r--r-- | ocamltest/environments.ml | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/ocamltest/environments.ml b/ocamltest/environments.ml index 49293b3bf0..c5b9ba0b6a 100644 --- a/ocamltest/environments.ml +++ b/ocamltest/environments.ml @@ -31,17 +31,7 @@ let string_of_binding variable value = let name = (Variables.name_of_variable variable) in Printf.sprintf "%s=%s" name value -let to_system_env ?(f= string_of_binding) env = - let system_env = Array.make (VariableMap.cardinal env) "" in - let i = ref 0 in - let store variable value = - system_env.(!i) <- f variable value; - incr i in - VariableMap.iter store env; - system_env - let expand env value = - let bindings = to_bindings env in let f (variable, value) = ((Variables.name_of_variable variable), value) in let simple_bindings = List.map f bindings in @@ -49,6 +39,15 @@ let expand env value = let b = Buffer.create 100 in try Buffer.add_substitute b subst value; Buffer.contents b with _ -> value +let to_system_env ?(f= string_of_binding) env = + let system_env = Array.make (VariableMap.cardinal env) "" in + let i = ref 0 in + let store variable value = + system_env.(!i) <- f variable (expand env value); + incr i in + VariableMap.iter store env; + system_env + let lookup variable env = try Some (expand env (VariableMap.find variable env)) with Not_found -> None |
