Skip to content

Handle space in path#10727

Open
Et7f3 wants to merge 14 commits intoocaml:trunkfrom
Et7f3:handle_space_in_path
Open

Handle space in path#10727
Et7f3 wants to merge 14 commits intoocaml:trunkfrom
Et7f3:handle_space_in_path

Conversation

@Et7f3
Copy link
Copy Markdown
Contributor

@Et7f3 Et7f3 commented Oct 26, 2021

Hello,

This is my hacktoberfest contribution. In a downstream project someone tried to compile with a space in his path (his username) and he reported to us. This PR intend to only fix the build system. So now we can build OCaml in path with space. The generated compiler are still broken (shebang, missing quoting, ...). We can also launch the test suite (-3 tests) in folder with space.

I did three iterations:

  • first just modify and see more test green to discover code base (I broke some tests in non-whitespace path)
  • Redo the same thing but check at each commit I don't break non-whitespace path
  • Merge common pattern dispatched in multiple commits for easing review. (each commit add minimal change to keep unexpected error to 0 and make a the testsuite with more failure pass)

third iteration:

    List of failed tests:
        tests/typing-misc/'typecore_empty_polyvariant_error.ml' with 1.1.1 (toplevel)
        tests/parsing/'broken_invariants.ml' with 1.1.1 (toplevel)
        tests/ppx-contexts/'test.ml' with 1.1.1 (ocamlc.byte)

    Summary:
      2973 tests passed
       37 tests skipped
        3 tests failed
      106 tests not started (parent test skipped or failed)
        0 unexpected errors
      3119 tests considered

To reviewer: can you compare these two commits: 6c0c5c4
3dce845
and say which one I keep ? both ?

Edit: I redid a review and saw I forgotten file like testsuite/tests/asmgen/immediates.cmmpp I don't know if I have missed other.

@Et7f3 Et7f3 force-pushed the handle_space_in_path branch 2 times, most recently from 36189dd to a2046d8 Compare October 31, 2021 21:49
@Et7f3 Et7f3 force-pushed the handle_space_in_path branch from ad279c4 to 8deaf61 Compare November 2, 2021 00:01
@Octachron
Copy link
Copy Markdown
Member

Note when you are working on a draft PR and trying to get the test suite to pass, it is better to work on a separate branch (after activating Appveyor on your fork), otherwise you are consuming CI time that could be used for non-draft PRs.

Also cc @shindere that might be interested by this PR making the build system works with path containing spaces.

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Nov 2, 2021 via email

@Et7f3
Copy link
Copy Markdown
Contributor Author

Et7f3 commented Nov 2, 2021

after activating Appveyor on your fork

Have link how to enable it ? I was only able to set as new project but it didn't loaded the yml file so I have to fill the gui dashboard.

Edit: ok I found it I will create another branch to test without triggering this CI.

@Et7f3 Et7f3 force-pushed the handle_space_in_path branch 2 times, most recently from 2a9b761 to 0d0a5ae Compare November 7, 2021 02:10
@Et7f3
Copy link
Copy Markdown
Contributor Author

Et7f3 commented Nov 7, 2021

Ok squashed my commit --fixup and rebased on trunk. Trunk head is broken for windows but it succeeded before so it should keep passing.

@dra27 dra27 closed this Nov 9, 2021
@dra27 dra27 reopened this Nov 9, 2021
@dra27
Copy link
Copy Markdown
Member

dra27 commented Nov 9, 2021

(closed/re-opened to force GitHub to redo the merge commit and pull in the fix for AppVeyor)

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Nov 9, 2021

Many thanks for your work, @Et7f3. I find it both brave and cool
that you started to work on this.

Regarding your first commit, I have another, configure-based fix that
I hope to implement soon. I'll submit a PR and post a link to it
to the current one.

I couldn't review the rest of your PR now but will try to do so starting
from next week.

Did you also try make install? Including installing to a directory
with spaces in its name? Does that owrk, too, and is the installed compiler
usable to compile files that have also spaces in their paths?

@Et7f3
Copy link
Copy Markdown
Contributor Author

Et7f3 commented Nov 9, 2021

I haven't tried make install because I still need to fix 4 tests related to pp/ppx: Does they are expected to take only program (like we can read in some comment) or quoted command (we see command in the helpstring) ?

I came after failure of ocamlmklib wrt to bad quoting of arguments. This isn't addressed. OCaml was builded in sane path and used in path with space. So this PR only address build system. I wonder If I should rewrite to use utils and then it will fix automatically or other solution are preferable.
I tried to build with clang in my env (strangely command where called with gcc alias). I can try to build with CC=/some/path with/space/clang. I expect failure for that case.

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Nov 9, 2021 via email

@Et7f3
Copy link
Copy Markdown
Contributor Author

Et7f3 commented Nov 9, 2021

I have updated my message on GitHub with better explanation.

ocamlmklib don't quote args:

(Printf.sprintf "%s %s -o %s %s %s %s %s %s %s"

I don't understand the question, I'm sorry.

I see the ocamlmklib call the linker and the linker Config.mkdll and the linker is also called in utils/ccomp.ml
So I was asking if ocamlmklib should instead of directly call the linker reuse the code in ccomp.ml

@Et7f3
Copy link
Copy Markdown
Contributor Author

Et7f3 commented Nov 9, 2021

I ignored the four failings tests and tried make install
I choke on this line:

ocaml/stdlib/Makefile

Lines 60 to 62 in edf0075

install::
stale="$(filter-out $(notdir $(wildcard stdlib__*.cmi)), \
$(notdir $(wildcard $(INSTALL_LIBDIR)/stdlib__*.cmi)))"; \

Here we want to check that all cmi we try to install are absent ? Why not test existence/emptiness of the folder ?

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Nov 9, 2021 via email

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Nov 9, 2021 via email

@Et7f3
Copy link
Copy Markdown
Contributor Author

Et7f3 commented Nov 9, 2021

Do you intend to fix it here

I think I will only fix the build system in this PR so fix make install. And I will do another round to make it usable.
This check was added in 4.13.0-alpha1. I still see PR that have base before 4.13.0 so I should better keep it and try to find a workaround.

@Et7f3 Et7f3 force-pushed the handle_space_in_path branch from 0d0a5ae to 3602209 Compare November 9, 2021 19:36
@Et7f3
Copy link
Copy Markdown
Contributor Author

Et7f3 commented Nov 9, 2021

Ok workaround found so make install successfully install all pieces. But the generated ocaml doesn't seem to have the workaround shebang. Should I bootstrap ?

pwd: /Users/Et7f3/projects/space with ocaml/ocamltest
pwd/..: /Users/Et7f3/projects/space with ocaml/ocamltest/..
abspath: /Users/Et7f3/projects/space /Users/Et7f3/projects/space with ocaml/ocamltest/with /Users/Et7f3/projects/space with ocaml/ocamltest/ocaml+

With this path make produce same ouput in directory with space and without space.
Summary:
  646 tests passed
   29 tests skipped
  1655 tests failed
  775 tests not started (parent test skipped or failed)
   11 unexpected errors
  3116 tests considered
for file in $(grep -rl 'sh ${test_source_directory}' .); do sed -i '' -e 's|sh ${test_source_directory}|sh '"'"'${test_source_directory}'"'|" "$file"; done
                                                                                                           ^^^^^ Sorry for this and this^^^^^
for file in $(grep -rl '\-I \?${' .); do sed -i '' -e 's|-I\( *\)${\([^}]*\)}|-I\1'"'"'${\2}'"'|g" "$file"; done
                                                                                  ^^^^^ and ^^^

And fix others places manually.

Summary:
  653 tests passed
   32 tests skipped
  1659 tests failed
  766 tests not started (parent test skipped or failed)
    6 unexpected errors
  3116 tests considered
Summary:
  657 tests passed
   32 tests skipped
  1660 tests failed
  764 tests not started (parent test skipped or failed)
    2 unexpected errors
  3115 tests considered
make one TEST=tests/tool-debugger/find-artifacts/'debuggee.ml' before exited without error.
This can be replaced with the following commit. To be decided on review.
Summary:
  657 tests passed
   32 tests skipped
  1661 tests failed
  769 tests not started (parent test skipped or failed)
    0 unexpected errors
  3119 tests considered
Summary:
  1636 tests passed
   32 tests skipped
  991 tests failed
  460 tests not started (parent test skipped or failed)
    0 unexpected errors
  3119 tests considered
Summary:
  2838 tests passed
   37 tests skipped
   59 tests failed
  185 tests not started (parent test skipped or failed)
    0 unexpected errors
  3119 tests considered
Summary:
  2961 tests passed
   37 tests skipped
    8 tests failed
  113 tests not started (parent test skipped or failed)
    0 unexpected errors
  3119 tests considered
List of failed tests:
    tests/typing-misc/'typecore_empty_polyvariant_error.ml' with 1.1.1 (toplevel)
    tests/parsing/'broken_invariants.ml' with 1.1.1 (toplevel)
    tests/ppx-contexts/'test.ml' with 1.1.1 (ocamlc.byte)

Summary:
  2973 tests passed
   37 tests skipped
    3 tests failed
  106 tests not started (parent test skipped or failed)
    0 unexpected errors
  3119 tests considered
@Et7f3 Et7f3 force-pushed the handle_space_in_path branch from 3d25274 to de1c552 Compare November 12, 2021 23:07
@Et7f3
Copy link
Copy Markdown
Contributor Author

Et7f3 commented Nov 12, 2021

I rebased (I needed a buildable branch). This PR don't cause regression with test added on trunk. For the last three tests I have a dirty patch for unix but since quoting is shell dependent it don't work on cmd.

Dirty hack This patch is also dirty because it use " around ppx path so if ppx is located in space with $ or ` it can have unexpected side effect. I tried with strong quote but they all cancel. I suspect String.word to be responsible.
From 94f57affd438c21c9d587ff75f8138b18e92b2b7 Mon Sep 17 00:00:00 2001
From: Et7f3 <cadeaudeelie@gmail.com>
Date: Fri, 12 Nov 2021 22:55:57 +0100
Subject: [PATCH] fix(tests): Dirty hack to have all tests green.

---
 ocamltest/tsl_lexer.mll                                       | 2 ++
 testsuite/tests/parsing/broken_invariants.ml                  | 2 +-
 testsuite/tests/ppx-contexts/test.ml                          | 4 ++--
 .../tests/typing-misc/typecore_empty_polyvariant_error.ml     | 2 +-
 4 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/ocamltest/tsl_lexer.mll b/ocamltest/tsl_lexer.mll
index 3a7f91748..d9d3c397c 100644
--- a/ocamltest/tsl_lexer.mll
+++ b/ocamltest/tsl_lexer.mll
@@ -90,6 +90,8 @@ and string acc = parse
       string (acc ^ space) lexbuf }
   | '\\'
     {string (acc ^ "\\") lexbuf}
+  | '\\' '"'
+    {string (acc ^ "\"") lexbuf}
   | '"'
     {acc}
 and comment = parse
diff --git a/testsuite/tests/parsing/broken_invariants.ml b/testsuite/tests/parsing/broken_invariants.ml
index 29e09a191..74774a463 100644
--- a/testsuite/tests/parsing/broken_invariants.ml
+++ b/testsuite/tests/parsing/broken_invariants.ml
@@ -6,7 +6,7 @@
   program="ppx.exe"
   *** toplevel
   all_modules="broken_invariants.ml"
-  flags="-ppx '${ocamlrun} ${test_build_directory_prefix}/ocamlc.byte/ppx.exe'"
+  flags="-ppx '\"${ocamlrun}\" \"${test_build_directory_prefix}/ocamlc.byte/ppx.exe\"'"
 *)
 
 let empty_tuple = [%tuple];;
diff --git a/testsuite/tests/ppx-contexts/test.ml b/testsuite/tests/ppx-contexts/test.ml
index 75d942fdc..b642118a3 100644
--- a/testsuite/tests/ppx-contexts/test.ml
+++ b/testsuite/tests/ppx-contexts/test.ml
@@ -14,13 +14,13 @@ flags = "-thread \
          -principal \
          -alias-deps \
          -unboxed-types \
-         -ppx ${program}"
+         -ppx '\"${program}\"'"
 **** ocamlc.byte
 module = "test.ml"
 flags = "-g \
          -no-alias-deps \
          -no-unboxed-types \
-         -ppx ${program}"
+         -ppx '\"${program}\"'"
 ***** check-ocamlc.byte-output
 *)
 
diff --git a/testsuite/tests/typing-misc/typecore_empty_polyvariant_error.ml b/testsuite/tests/typing-misc/typecore_empty_polyvariant_error.ml
index 9b4624d3e..6a03fbcfe 100644
--- a/testsuite/tests/typing-misc/typecore_empty_polyvariant_error.ml
+++ b/testsuite/tests/typing-misc/typecore_empty_polyvariant_error.ml
@@ -6,7 +6,7 @@
   program="ppx.exe"
   *** toplevel
   all_modules="${test_file}"
-  flags="-ppx '${ocamlrun} ${test_build_directory_prefix}/ocamlc.byte/ppx.exe'"
+  flags="-ppx '\"${ocamlrun}\" \"${test_build_directory_prefix}/ocamlc.byte/ppx.exe\"'"
 *)
 
 type t = [%empty_polyvar];;
-- 
2.30.1 (Apple Git-130)

For the original issue it should be enough.

Comment on lines +70 to +71
echo ' rm '"'"'$(INSTALL_LIBDIR)'"'"'/stdlib__[a-z]*.cm*'; \
echo 'and re-run make install'; \
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command might delete more file that necessary on Cygwin because we don't add shopt command.
Also instead of re-run make install I could have printed the original command If makefile weren't recursive: https://stackoverflow.com/a/38754878/7227940
One more point for "Recursive Make Considered Harmful". Do you want I help to de-recursify Makefile ?

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Nov 17, 2021 via email

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Nov 17, 2021 via email

@Et7f3
Copy link
Copy Markdown
Contributor Author

Et7f3 commented Nov 17, 2021

Et7f3 (2021/11/12 16:15 -0800):
@Et7f3 commented on this pull request. > + echo ' rm '"'"'$(INSTALL_LIBDIR)'"'"'/stdlib__[a-z].cm'; \ + echo 'and re-run make install'; \ This command might delete more file that necessary on Cygwin because we don't add shopt command. Also instead of re-run make install I could have printed the original command If makefile weren't recursive: https://stackoverflow.com/a/38754878/7227940 One more point for "Recursive Make Considered Harmful". Do you want I help to de-recursify Makefile ?
Yes I do agree that recursive makefiles are harmful and do wnat them to go away but it's a big task and other stuff must be done before so please let's this one be in peace for the moment, but many thanks for your interest in the compiler's build system.

Ok I will come back after 5.1

@Et7f3
Copy link
Copy Markdown
Contributor Author

Et7f3 commented Sep 6, 2022

most conflict are fix that were upstreamed independently so it is easy to chose which one we need to keep. many runtime-errors come from this commit 24bed4c.
Do you prefer I rebase or merge trunk in my branch ?

Almost all test pass like before. I have a dirty hack for the last one.

@dra27
Copy link
Copy Markdown
Member

dra27 commented Sep 6, 2022

Either is fine, although personally I prefer rebasing, please.

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Sep 13, 2022 via email

@Et7f3
Copy link
Copy Markdown
Contributor Author

Et7f3 commented Jan 12, 2023

This two commits: 6c0c5c4 and 3dce845 seems superseded by 89fb5b7 that is already in merged. Do you think I can drop them or in some case it can be useful ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants