-
Notifications
You must be signed in to change notification settings - Fork 81
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
Use forward slashes and quoted OCaml strings #323
Conversation
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.
This change looks okay to me; I don't know about whether it preserves Windows compatibility, but I certainly assume @jonahbeckford does, and keeping forward slashes for all systems probably makes things simpler.
(On the other hand I don't understand the relation with #321; I will ask there.)
In fact, thinking about it twice, I am not completely sure that this is safe for Unix users:
If (2) is indeed a real issue, we are fixing the behavior of Windows users with backslashes in their paths, but we are breaking the behavior of some Unix users with spaces or other escapable characters in their path, depending on how they are doing their escaping or quoting. What problems would we have if we only kept the part of this PR that uses quoted string literals, and removed the rotation of slashes? |
Test 1
As best as I can tell after doing a search of the code, the following generated variables in OCAML_PREFIX=
OCAML_BINDIR=C:/Users/beckf/AppData/Local/Programs/DKMLNA~1/bin
OCAML_LIBDIR=C:/Users/beckf/AppData/Local/Programs/DKMLNA~1/lib/ocaml
OCAML_MANDIR=C:/Users/beckf/AppData/Local/Programs/DKMLNA~1/man so the backslash in |
Test 2 including OCaml quoted string literalsLet's change the example to:
That gives: # file: Makefile.config
#...
PREFIX=/tmp/my\ ocaml\ prefix
BINDIR=/tmp/my\ ocaml\ prefix/bin
LIBDIR=/tmp/my\ ocaml\ prefix/lib
MANDIR=/tmp/my\ ocaml\ prefix/man and (* file: src/ocamlbuild_config.ml *)
let bindir = {|/tmp/my\ ocaml\ prefix/bin|}
let libdir = {|/tmp/my\ ocaml\ prefix/lib|}
let ocaml_libdir = {|/home/jonahbeckford/.opam/opam-publish/lib/ocaml|}
let libdir_abs = {|/tmp/my\ /home/jonahbeckford/source/ocamlbuild/ocaml\ /home/jonahbeckford/source/ocamlbuild/prefix/lib|}
let ocaml_native = true
(* ... *) The
|
Test 3 without quoted string literalsPATH=...:"$PATH" # Add opam
eval $(opam env)
WORKDIR=$(mktemp -d)
printf '#!/bin/sh\n exit 1' | tee "$WORKDIR/opam" > "$WORKDIR/ocamlfind"
chmod +x "$WORKDIR/opam" "$WORKDIR/ocamlfind"
PATH="$WORKDIR:$PATH"
make -f configure.make distclean
make -f configure.make all \
OCAMLBUILD_PREFIX='/tmp/some\backspace\dir' \
OCAMLBUILD_BINDIR='/tmp/some\backspace\dir/bin' \
OCAMLBUILD_LIBDIR='/tmp/some\backspace\dir/lib' \
OCAMLBUILD_MANDIR='/tmp/some\backspace\dir/man'
make check-if-preinstalled all During the compile we get:
What is worse is that notice the So we generate ... (* file: src/ocamlbuild_config.ml *)
let bindir = "/tmp/some�ackspace\dir/bin"
let libdir = "/tmp/some�ackspace\dir/lib"
let ocaml_libdir = "/home/jonahbeckford/.opam/opam-publish/lib/ocaml"
let libdir_abs = "/tmp/some�ackspace\dir/lib"
let ocaml_native = true and $ ./ocamlbuild.native -where
/tmp/somackspace\dir/lib/ocamlbuild That is the original bug I found in DkML 2.0.3: diskuv/dkml-installer-ocaml#70. That means backslash characters were already unsafe. Perhaps backslashed spaces work, but if it did that was an accident. |
Anyway, I think this needs to be communicated as a major breaking change. |
369b374
to
35c65d9
Compare
What I understand from your experiments is that my worries are moot because any use of backslash (be it part of the path, or an attempt to escape spaces) is likely to be deeply broken today. @kit-ty-kate, I wonder if you have an opinion; do you also now consider that this PR is safe? |
My opinion is that the part changing However I’m rather on the fence about the
do you have an example of such users?
I just read the documentation for the |
I agree that quoted strings are fine. @jonahbeckford I think that I got us in the wrong direction with my previous question on non-Windows peoples using spaces or backslashes in their path. If we ignore those, what are the issues with just using quoted strings and not performing the translation of backslash into slash in this PR? Note: I also wondered if:
|
Oh i like that very much. Looking at what that file is doing it seems like it would be possible to rewrite it in caml in a more concise way. The only annoying bit seems to be the
and we would be able to get the value from OCaml using:
I’m not sure to understand what you mean. We can always assume OCaml is available as every dependencies are required to be installed before the package that depends on them. Plus if that wasn’t the case the Makefile would simply fail (if only for the |
Ah, good point about dependencies being available at package-configure-time already.
We can call |
diskuv/dkml-installer-ocaml#70 : ptime. That was my initial blocker, but now that is unblocked. My memory also says I've seen this same error in a few more packages. I have no bandwidth to do refactoring of ocamlbuild. And there are several more commits from fdopen before ocamlbuild is in a healthy state. If worse comes to worse, let's just keep this issue open with a concrete list of recommendations for an interested party to tackle. |
@jonahbeckford would you be able to check if #334 works for your setup ? |
TLDR: If ocamlbuild compiles ptime.1.1.0 and any other random ocamlbuild package without modification, then it is good. I think "your setup" meant MSVC on Windows. Has it been tested with opam 2.2 beta3 + MSVC? That is the real target. If that works, this issue can be closed! |
#334 is tested with opam 2.2 beta3 + mingw |
Oh that is great! I could have sworn that opam 2.2 has a msvc mode. You may have to ping the opam 2.2 folks how to do that in whatever testing pipeline they gave you. It is possible testing of msvc is punted ... which means this issue should stay open (MSVC is way less tolerant of incorrect slashes and incorrect quotes than GCC/MinGW). Please don't worry about DkML ... it should work if opam 2.2 + MSVC works (not the other way around). And it has a working fork of ocamlbuild that won't be merged with your changes until absolutely necessary ... which is hopefully never b/c testing an infrastructure package like ocamlbuild is laborious in DkML (well, at least until opam 2.x has parity with DkML ... then DkML won't be needed!). |
I believe that everything here is fixed |
I'd like to thank everyone involved here for the end result which is a net improvement to the upstream ocamlbuild windows story (stories, as several distinct configurations are in use). I was of course unhappy that we couldn't help @jonahbeckford get his work upstream, but that required more effort than Jonah and @kit-ty-kate and myself were able to pour into the topic. We are fortunate that @hhugo and @dra27 were willing to revive it, with new Windows CI goodness that made working on this surprisingly efficient. Impressive work, thanks! |
This is the upstream of https://github.com/diskuv/diskuv-opam-repository/blob/main/packages/ocamlbuild/ocamlbuild.0.14.0/files/ocamlbuild-0.14.0.diskuvocaml.patch
Before
Makefile.config:
src/ocamlbuild_config.ml:
After
Makefile.config:
src/ocamlbuild_config.ml: