diff --git a/src/kernel_services/ast_queries/file.ml b/src/kernel_services/ast_queries/file.ml index 70ef66d61040e8a0dba60b655ac82f492b051f4a..d384a53a64504ab3309ebbb6a0a73a386e371399 100644 --- a/src/kernel_services/ast_queries/file.ml +++ b/src/kernel_services/ast_queries/file.ml @@ -447,16 +447,19 @@ let concat_strs ?(pre="") ?(sep=" ") l = if l = [] then "" else pre ^ (String.concat sep l) +let cwd () = + (* TODO: we currently use PWD instead of Sys.getcwd () because OCaml has + no function in its stdlib to resolve symbolic links (e.g. realpath) + 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. *) + try Unix.getenv "PWD" with Not_found -> Sys.getcwd () + let adjust_pwd fp cpp_command = if Kernel.JsonCompilationDatabase.is_set () then - (* TODO: we currently use PWD instead of Sys.getcwd () because OCaml has - no function in its stdlib to resolve symbolic links (e.g. realpath) - 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. *) - let cwd = try Unix.getenv "PWD" with Not_found -> Sys.getcwd () in + let cwd = cwd () in let dir = match Json_compilation_database.get_dir fp with | None -> cwd @@ -577,10 +580,10 @@ let abort_with_detailed_pp_message f cpp_command = else "" in Kernel.abort - "failed to run: %s@\n\ + "failed to run: %s\n(PWD: %s)@\n\ %sSee chapter \"Preparing the Sources\" in the Frama-C user manual \ for more details." - cpp_command possible_cause + cpp_command (cwd ()) possible_cause let parse_cabs cpp_command = function | NoCPP f ->