New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.ocamlinit: XDG base directory lookup. #8834
Conversation
(In case anyone wonders about the code dupe this point 4. of #7589) |
toplevel/opttoploop.ml
Outdated
if Sys.file_exists ocamlinit then Some ocamlinit else | ||
let exists_in_dir dir p = match dir with | ||
| None -> None | ||
| Some dir -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the weird (non-)indentation intentional? I would expect the match cases to be indented (and below as well)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the way ocp-indent
idents for me (strict_with=always
, a good way of making the most of the 80 columns that are available to express yourself) but I can certainly change that if it disturbs people.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact I realized there's an .ocp-indent
in the repo but apparently it wasn't taken into account. Let me fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok it seems there was .emacs
configuration taking over on my side. Now indented according the the repo's .ocp-indent
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dbuenzli What Emacs configuration? Tuareg indents |
by default. It also indents the else
clause:
https://github.com/ocaml/ocaml/pull/8834/files#diff-59d1589c8c3e651da23f92e75ce9c12eR550-R572
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An ocp-indent
emacs configuration. I don't use tuareg anyways but caml-mode
.
I can't comment on the Windows-related changes, but the rest looks ok. Since XDG is as far as I can tell a Linux(unix?)-specific thing, I would be slightly in favor of not breaking anything for Windows users... but to be fair I have zero insight on how |
AFAIK |
I never used |
But isn't |
Actually, it depends which version of OCaml you are using. If you run the "native" ports (ie compiled with Put another way, As another example of these kind of gymnastics, see #1406. |
@nojb Thanks for the explanation. So the remaining question is: is in cygwin |
On 28 July 2019 at 11:25 CEST, Daniel Bünzli ***@***.***> wrote:
An ocp-indent emacs configuration. I don't user tuareg anyways but caml-mode.
OK, thanks for the info.
|
I’m fairly |
c85962d
to
d06482d
Compare
Since what I did was anyway stupid I went on to implement what git devs do to lookup This means |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Libraries in other languages (Rust and Python) have put a lot of thought into the XDG + Windows side of this.
I don't like the Git approach - it's not uncommon, but it blats lots of unhidden dotfiles in a directory which is supposed to only contain other Microsoft-defined directories, and files blatted there do not roam.
Up to now on Windows, it's been necessary to set HOME
to achieve this and I have indeed done that for as long as I can remember. I'd keep that part as no change on Windows - .ocamlinit
is only found in the current directory or %HOME%
.
I'm tempted to say don't check XDG_CONFIG_HOME
at all on Windows, but for compatibility with running a native OCaml toplevel inside Cygwin, I guess it makes sense.
If only one of the APPDATA
variables is to be checked, I'd check APPDATA
(i.e. the roaming one). However, I think it would better to check %LOCALAPPDATA%
and then %APPDATA%
.
I think that eliminates the differences in home_dir
and adds one further check for APPDATA
in config_dir
.
It's a nice change, thanks!
Incidentally, for the roaming/local thing on Windows, the idea is that machine-specific things go in For |
@dra27 thanks for your comments but I have difficulty understanding what and if I need to change something, could you please maybe make comments in the code what and where things should be changed (if any) ? |
@dbuenzli - oops, sorry! I was suggesting:
I hadn't spotted it before, but note that it is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The environment change isn't quite what I meant - LOCALAPPDATA
will always be defined on Windows. What I meant is if %LOCALAPPDATA%\ocaml\init.ml
exists then use it, otherwise try %APPDATA%\ocaml\init.ml
and otherwise fallback to the usual %HOME%\.ocamlinit
.
Thinking some more, the same behaviour should apply to XDG_CONFIG_HOME
, because the directory referred to may be a Cygwin, MSYS or WSL path, which native Windows will be unable to translate. So I think you'd want to try %XDG_CONFIG_HOME%\ocaml\init.ml
and then if that doesn't exist (or XDG_CONFIG_HOME
wasn't defined) then move on to %LOCALAPPDATA%
, etc.)
I think that then means it's only a small tweak - instead of config_dir
, you want config_dirs
to return a list of possible directories to try (obviously, a user could choose to erase LOCALAPPDATA
or APPDATA
from their environment, so they shouldn't be tried at all if they're missing).
I did what you suggested though it also changes the way I had implemented the XDG spec in a subtle way. Before you would determine a config directory and then lookup if a file exists in that directory. Now you lookup a file in any of what config directory could be and load it if there is one in any of those. I don't think that's the way XDG is supposed to work but I think it's harmless for lookup. However if you need to determine a directory for writing a configuration file that may not exist what would you suggest on windows ? |
Well no I think it's problematic in fact. If you set your I think the behaviour on each platform should to be to take the first of the following files that exist:
On non windows platforms |
As a slightly pedantic aside, when writing you'd want to adopt the Windows casing conventions (so the file would be For the |
For Windows, could it be predicated on the existence of the |
@alainfrisch (and others who regularly use WSL builds of OCaml on Windows) - what do you think about whether Windows should always ignore |
I find the fact that this doesn't allow me to determine a location to write a non existing configuration file suspicious. |
As far as I can tell (both knowing how Windows roaming configure "works", and looking at other libraries), it's because you're (well "one's") working under the assumption that there is one file and for Windows there's likely to be two. One of those libraries indeed adds a |
So I implemented the procedure I mentioned in this comment assuming OCaml Windows users want their |
I agree with the change to check Thinking more about invoking a native Windows binary from within another subsystem (since this is getting ever more popular), I'm uneasy about what happens when a native Windows There's another issue in this situation with either When |
(Note it will be @dra27 I already spent a bit too much time fiddling on this PR on Windows problems I do certainly not understand to their full extent. So maybe we could merge this and you can tweak the windows path yourself later ? That being said
|
Is there anything more that needs to be done for this to be merged ? The Windows support may not be perfect (see last two messages) but I don't think it is worse than before. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can go in if XDG_CONFIG_HOME
is completely ignored for Sys.win32 = true
(there'd be a man page tweak as well). It can read that in future if there's work to ensure the value makes sense.
I don't understand why you want this, I mean at that rate I'm fine not doing this if there's a good rationale for it, but for now there doesn't seem to be any. I don't see how it could harm windows user, it rather gives them a hook to configure things to their wishes and in a uniform way with other tools from the unix world that abide to that convention and they might be using. |
For example it seems |
Git-for-Windows is my example and reason for how not to do it - the interaction of Git-for-Windows in Cygwin is very easy to mess up, and is where it's coming from. There are even special tests in opam's CI to deal with Cygwin My rationale is that if |
Again, I don't see how this differs from the status of
I would rather say it is point 3 that demonstrates it: it seems every Windows user out there has a different opinion on how things should be done and they enjoy each of their tool to behave differently and/or in fiddly manners. Not my philosophy so I simply elected to restore the plain old behaviour for Windows so that nothing prevents this to be merged. Thanks. |
It seems there's a CI glitch here could someone please restart the job. |
Ping. Is there something that prevents this to be merged ? The initial description is up-to-date with the current state of the PR. |
@dra27 are you happy with the current state of the PR? |
Ping. It seems to me that @dra27 should now have had enough time to comment on a PR that doesn't change anything as far as Windows is concerned. |
Indeed. I'm merging the PR. Thank you for working on this! |
Thanks @Armael ! |
This makes the
ocaml
tool lookup an.ocamlinit
file in the configuration directory of the XDG base directory specification.The file is
ocaml/init.ml
in the XDG configuration directory. This filename was chosen so that your editor recognizes it as a proper OCaml file. The XDG specification is followed by quite a few Linux distributions and its home directory fallback also makes it a good macos citizen.The
~/.ocamlinit
file is still looked up if the XDG lookup does not yield anything and on Windows this new lookup procedure is skipped, so no regressions should be expected.On Windows%APPDATA%
is tentatively looked up ifXDG_CONFIG_HOME
is undefined or empty. and a complicated fallback is implemented in caseHOME
is undefined and needed by the lookup procedure. One regression is thatHOME
is no longer looked up on Windows (as defined bySys.win32
, so not oncygwin
) but%HomePath%
is. This can be changed if Windows users would prefer no change in behaviour.