ocaml-community / utop

Universal toplevel for OCaml
Other
833 stars 110 forks source link

utop/init.ml does not respect XDG on Windows #451

Open jonahbeckford opened 11 months ago

jonahbeckford commented 11 months ago

Context

You can see in my utop session below that XDG correctly reports the configuration directory is LOCALAPPDATA, but some magic in utop is mangling the path badly.

You can follow along with DkML 2.0.1 at https://gitlab.com/diskuv-ocaml/distributions/dkml/-/releases/2.0.1/downloads/setup64u.exe in a Windows Sandbox or a VM. Then run utop in a Command Prompt or PowerShell.

utop # #require "utop";;

utop # let xdg = Xdg.create ~env:Sys.getenv_opt () ;;
val xdg : Xdg.t = <abstr>

utop # Xdg.config_dir xdg ;;
- : string = "C:\\Users\\WDAGUtilityAccount\\AppData\\Local"

utop # LTerm_resources.xdgbd_file ~loc:LTerm_resources.Config "utop/init.ml";;
- : string =
"C:\\Users\\WDAGUtilityAccount\\AppData\\Local\\Programs\\DiskuvOCaml\\tools\\MSYS2\\home\\WDAGUtilityAccount\\Local Settings\\utop/init.ml"

Root Cause Guess

Somehow xdgbd_file is combining both HOME and XDG (on Windows HOME should either be ignored or be the fallback to LOCALAPPDATA). My guess is that something is interpreting Xdg.config_dir xdg as a relative path (a common mistake is to assume that absolute paths have to start with a / forward slash), and then making Xdg.config_dir xdg an absolute path relative to $HOME.

That means utop can't locate the correct init.ml file:

https://github.com/ocaml-community/utop/blob/5b98d2845bf8e46a253593578cf0371d773f6da0/src/lib/uTop_main.ml#L1406-L1417

Related