reduce boilerplate in compiler command line parsing
Created by: sliquister
Changing compiler flags is quite annoying currently due to how it requires:
- adding a ref to Clflags, and to the mli
- adding the flag to main_args.ml
- and add the callback for said flag in the right module type (ml and mli)
- list said flag in the body of n functors
- implement said flag at the n+ call sites of these n functors, almost all of which will simply set Clflags
- maybe updating man pages
I propose a change such that the work required is:
- unchanged
- adding the flag to main_arg.ml, but the spec sets
Clflags.foo
instead of calling af
parameter - gone
- unchanged (can be improved upon later)
- gone
- unchanged
You can see the concrete impact of that change in the second commit, for a fraction of the flags (not every flag, because such a change would conflict a lot and for some flags, such a change would require more refactoring, because of OCAMLPARAM in particular).
Now about the implementation.
The reason why the interpretation of flags is left to a functor is ocamlcp, which wants to interpret flags differently from everyone else: print them back, instead of setting Clflags. I don't think we can change ocamlcp to have a command line like ocamlcp ocamlcp-flags -- ocamlc-flags
at this point (which would be much simpler).
So I change ocamlcp so it reinterprets flags at a different level: at the level of the Arg.spec, which is simpler (and less error prone: who knows if there are typos in the flag names given to ocamlc by ocamlcp?). With that, most flags (or perhaps all flags) can simply set references in Clflags.
(an alternative implementation to get rid of 5. but not 3. would have been for main_args.ml to provide a structure that implements as much as possible [val _mk_foo] as [Clflags.foo := true], but I see no point in preserving the parametrization, and the code is more direct without it)