Since typechecking the scripts requires to provide an interpretation of the #require directives (and to ignore calls to Toplevel functions), I fear that the easiest option would be to call ocamlc/opt -stop-after typing from b0caml itself.
Sure these things can be solved with interpreters that parse the script. In b0caml (and I guess ocamlscript) since I actually compile the script to an executable, I don’t even need to stop-after.
I was really looking to solve the problem for #!/usr/bin/env ocaml.
(Note that except for the exit code what I mentioned above almost works, the painful and brittle workaround is for the build system to parse the output to look for Error: messages).
How about keeping the original source code without any shebang or other directives, and using the build system to generate the final script with the shebang etc. on top? That way you can use ocaml or whatever to typecheck the source code.
Sure, there’s thousands of horrible workarounds, I was just enquiring whether I had missed something. It seems I didn’t.
Not really surprised. The whole toplevel/ocaml interpreter user experience is utterly broken without anyone caring more than that (and I won’t bother open an issue upstream, these usability issues just end up being closed by the “friendly bot” ).
We could consider having the ocaml toplevel support -stop-after X options – without running the actual code of each phrase. If X is typing or after, the phrase extends the typing environment.
Edit; I guess the next step is a feature request on ocaml/ocaml.