Expose the main entrypoint in compilerlibs#9688
Conversation
7395fba to
ef5850c
Compare
| print_string "Standard library directory: "; | ||
| print_string Config.standard_library; print_newline(); | ||
| exit 0 | ||
| raise (Exit_compiler 0) |
There was a problem hiding this comment.
Have you checked that there are no more calls to exit in the compiler code?
There was a problem hiding this comment.
Yes, I've changed all the ones I could find that might be reachable from ocamlc or ocamlopt. (There are others used by tools other than the compiler)
utils/clflags.ml
Outdated
| try | ||
| let argv = ref Sys.argv in | ||
| let argv = ref argv in | ||
| let current = ref (!Arg.current) in |
There was a problem hiding this comment.
Should [current] be passed as an argument too? It's easy to forget to update Arg.current when calling main from the client of compiler-libs, possibly with a different argument array rather than Sys.argv.
There was a problem hiding this comment.
I've changed it to always start from 0. Since we're passing in argv, anyone whose wants to chop off some arguments can do so with Array.sub before here.
There was a problem hiding this comment.
Yes, makes sense. I think the code that calls Clflags.parse_arguments in makedepend.ml needs to be adjusted this way, as makedepend advances Arg.current and fiddles with Sys.argv before calling parse_arguments.
Line 646 in 6f3fc91
There was a problem hiding this comment.
Nice catch! Thanks
6f3fc91 to
cf25526
Compare
cf25526 to
34ead63
Compare
|
Any other comments? |
Expose the main entrypoint in compilerlibs (cherry picked from commit 088fa01)
Expose the main entrypoint in compilerlibs (cherry picked from commit 088fa01)
Expose the main entrypoint in compilerlibs (cherry picked from commit 088fa01)
* Merge pull request ocaml#9688 from stedolan/main-compiler-libs * Gc.Memprof.start: take a record instead of 5 optional parameters * Try and vendor memtrace * Move memtrace to otherlibs * Add changes to configure * Add a memtrace-enabled ocamlopt as ocamlopt-memtrace * Fix dune build following driver split Co-authored-by: Stephen Dolan <sdolan@janestreet.com> Co-authored-by: Gabriel Scherer <gabriel.scherer@gmail.com>
* Merge pull request ocaml#9688 from stedolan/main-compiler-libs * Gc.Memprof.start: take a record instead of 5 optional parameters * Try and vendor memtrace * Move memtrace to otherlibs * Add changes to configure * Add a memtrace-enabled ocamlopt as ocamlopt-memtrace * Fix dune build following driver split Co-authored-by: Stephen Dolan <sdolan@janestreet.com> Co-authored-by: Gabriel Scherer <gabriel.scherer@gmail.com>
* Merge pull request ocaml#9688 from stedolan/main-compiler-libs * Gc.Memprof.start: take a record instead of 5 optional parameters * Try and vendor memtrace * Move memtrace to otherlibs * Add changes to configure * Add a memtrace-enabled ocamlopt as ocamlopt-memtrace * Fix dune build following driver split Co-authored-by: Stephen Dolan <sdolan@janestreet.com> Co-authored-by: Gabriel Scherer <gabriel.scherer@gmail.com>
* Merge pull request ocaml#9688 from stedolan/main-compiler-libs * Gc.Memprof.start: take a record instead of 5 optional parameters * Try and vendor memtrace * Move memtrace to otherlibs * Add changes to configure * Add a memtrace-enabled ocamlopt as ocamlopt-memtrace * Fix dune build following driver split Co-authored-by: Stephen Dolan <sdolan@janestreet.com> Co-authored-by: Gabriel Scherer <gabriel.scherer@gmail.com>
It's quite awkward to compile programs using a custom binary with compilerlibs, because there's a lot of logic in
main.mlandoptmain.mlthat needs to be replicated. (I was doing this to trace the compiler with memtrace).This patch exposes optmain and main in compilerlibs, and moves the actual entry point to the new, trivial
optmainentry.mlandmainentry.mlfiles.(Best reviewed commit-by-commit)