Fix plugins lookup dir when Catala is installed to PATH

This commit is contained in:
Louis Gesbert 2024-02-27 11:24:33 +01:00
parent 346f401523
commit bc3add57ec
3 changed files with 15 additions and 5 deletions

View File

@ -278,10 +278,7 @@ module Poll = struct
Some root
| _ -> None)
let exec_dir : File.t =
(* Do not use Sys.executable_name, which may resolve symlinks: we want the
original path. (e.g. _build/install/default/bin/foo is a symlink) *)
Filename.dirname Sys.argv.(0)
let exec_dir : File.t = Catala_utils.Cli.exec_dir
let clerk_exe : File.t Lazy.t = lazy (Unix.realpath Sys.executable_name)

View File

@ -113,6 +113,15 @@ let file_lang filename =
@{<yellow>%s@}, and @{<bold>--language@} was not specified"
filename)
let exec_dir =
let cmd = Sys.argv.(0) in
if String.contains cmd '/' then
(* Do not use Sys.executable_name, which may resolve symlinks: we want the
original path. (e.g. _build/install/default/bin/foo is a symlink) *)
Filename.dirname cmd
else (* searched in PATH *)
Filename.dirname Sys.executable_name
let reverse_path ?(from_dir = Sys.getcwd ()) ~to_dir f =
if Filename.is_relative from_dir then invalid_arg "File.with_reverse_path"
else if not (Filename.is_relative f) then f
@ -225,7 +234,6 @@ module Flags = struct
let env = Cmd.Env.info "CATALA_PLUGINS" in
let default =
let ( / ) = Filename.concat in
let exec_dir = Filename.(dirname Sys.argv.(0)) in
let dev_plugin_dir = exec_dir / "plugins" in
if Sys.file_exists dev_plugin_dir then
(* When running tests in place, may need to lookup in _build/default

View File

@ -154,3 +154,8 @@ val s_plugins : string
exception Exit_with of int
(** Exit with a specific exit code (but less brutally than [Sys.exit] which
would bypass all finalisers) *)
(** {2 Other helpers} *)
val exec_dir : file
(** Returns the directory of the currently running executable *)