Skip to content
Snippets Groups Projects
Commit 62991347 authored by Patrick Baudin's avatar Patrick Baudin
Browse files

Merge branch 'fix/andre/remove-pwd-hack' into 'master'

[Kernel] remove reliance on 'PWD' environment variable

See merge request frama-c/frama-c!4267
parents c26d39f8 753c045c
No related branches found
No related tags found
No related merge requests found
...@@ -125,22 +125,15 @@ let insert base path_name = ...@@ -125,22 +125,15 @@ let insert base path_name =
Array.set cache (hash land 255) (Some (path_name, path)); Array.set cache (hash land 255) (Some (path_name, path));
path path
(* TODO: we currently use PWD instead of Sys.getcwd () because OCaml has (* Note: the call to Unix.realpath prevents some issues with symbolic links
no function in its stdlib to resolve symbolic links (e.g. realpath) in directory names. If you have problems with this, please contact us.
for a given path. 'getcwd' always resolves them, but if the user For the same reason, Sys.getcwd should _not_ be called directly, but only
supplies a path with symbolic links, this may cause issues. via this function, to avoid conflicting results in case the user forgot
Instead of forcing the user to always provide resolved paths, we to call Unix.realpath.
currently choose to never resolve them.
Note that, in rare situations (e.g. some Docker images), PWD does not
exist in the environment, so in that case, we fallback to Sys.getcwd.
REMARK[LC]: when the Frama-C binary is directly invoked by Node without
going through a shell script wrapper like ./bin/frama-c, the environment
variable "PWD" is _no more_ synchronized with Sys.getcwd.
This problem has been solved in `Dome.spawn()` by forcing the `PWD`
environement variable accordingly.
*) *)
let cwd = insert dummy (try Sys.getenv "PWD" with Not_found -> Sys.getcwd ()) let pwd () = Unix.(realpath (getcwd ()))
let cwd = insert dummy (pwd ())
type existence = type existence =
| Must_exist | Must_exist
...@@ -336,8 +329,6 @@ type position = ...@@ -336,8 +329,6 @@ type position =
let pp_pos fmt pos = let pp_pos fmt pos =
Format.fprintf fmt "%a:%d" Normalized.pretty pos.pos_path pos.pos_lnum Format.fprintf fmt "%a:%d" Normalized.pretty pos.pos_path pos.pos_lnum
let pwd () = try Unix.getenv "PWD" with Not_found -> Sys.getcwd ()
(* (*
Local Variables: Local Variables:
compile-command: "make -C ../../.." compile-command: "make -C ../../.."
......
...@@ -209,15 +209,8 @@ type position = ...@@ -209,15 +209,8 @@ type position =
val pp_pos : Format.formatter -> position -> unit val pp_pos : Format.formatter -> position -> unit
(** Return the current working directory. (** Return the current working directory.
Currently uses the environment's PWD instead of Sys.getcwd () because OCaml Implicitly uses {!Unix.realpath} to normalize paths and avoid issues with
has no function in its stdlib to resolve symbolic links (e.g. realpath) symbolic links in directory names.
for a given path. 'getcwd' always resolves them, but if the user
supplies a path with symbolic links, this may cause issues.
Instead of forcing the user to always provide resolved paths, we
currently choose to never resolve them.
We only resort to getcwd() to avoid issues when PWD does not exist.
Note that this function does not validate that PWD has not been tampered
with.
@since 25.0-Manganese @since 25.0-Manganese
*) *)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment