Skip to content

Expose the main entrypoint in compilerlibs#9688

Merged
stedolan merged 4 commits intoocaml:trunkfrom
stedolan:main-compiler-libs
Jul 6, 2020
Merged

Expose the main entrypoint in compilerlibs#9688
stedolan merged 4 commits intoocaml:trunkfrom
stedolan:main-compiler-libs

Conversation

@stedolan
Copy link
Copy Markdown
Contributor

It's quite awkward to compile programs using a custom binary with compilerlibs, because there's a lot of logic in main.ml and optmain.ml that 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.ml and mainentry.ml files.

(Best reviewed commit-by-commit)

@stedolan stedolan force-pushed the main-compiler-libs branch from 7395fba to ef5850c Compare June 16, 2020 13:00
print_string "Standard library directory: ";
print_string Config.standard_library; print_newline();
exit 0
raise (Exit_compiler 0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Have you checked that there are no more calls to exit in the compiler code?

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.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

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.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Clflags.parse_arguments Sys.argv file_dependencies usage;

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.

Nice catch! Thanks

@stedolan stedolan force-pushed the main-compiler-libs branch from 6f3fc91 to cf25526 Compare June 24, 2020 13:39
@stedolan stedolan force-pushed the main-compiler-libs branch from cf25526 to 34ead63 Compare June 30, 2020 09:58
@stedolan
Copy link
Copy Markdown
Contributor Author

Any other comments?

Copy link
Copy Markdown
Member

@dra27 dra27 left a comment

Choose a reason for hiding this comment

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

LGTM!

@stedolan stedolan merged commit 088fa01 into ocaml:trunk Jul 6, 2020
Gbury pushed a commit to ocaml-flambda/ocaml that referenced this pull request Jul 31, 2020
Expose the main entrypoint in compilerlibs

(cherry picked from commit 088fa01)
Gbury pushed a commit to ocaml-flambda/ocaml that referenced this pull request Jul 31, 2020
Expose the main entrypoint in compilerlibs

(cherry picked from commit 088fa01)
Gbury pushed a commit to ocaml-flambda/ocaml that referenced this pull request Aug 20, 2020
Expose the main entrypoint in compilerlibs

(cherry picked from commit 088fa01)
mshinwell pushed a commit to ocaml-flambda/ocaml that referenced this pull request Aug 21, 2020
* 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>
lthls pushed a commit to lthls/ocaml that referenced this pull request Sep 23, 2020
* 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>
lthls pushed a commit to lthls/ocaml that referenced this pull request Sep 23, 2020
* 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>
lthls pushed a commit to lthls/ocaml that referenced this pull request Sep 24, 2020
* 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>
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