Removal of boot/ocamldep, phase 1: add ocamlc -depend#1078
Removal of boot/ocamldep, phase 1: add ocamlc -depend#1078damiendoligez merged 1 commit intoocaml:trunkfrom
Conversation
This is frowned upon by many, not least the GNU coding standards: |
|
@xavierleroy Indeed, the current version of this PR would fail if somebody wants to rename |
|
Would it help to add an option like --depends to ocamlc and ocamlopt?
After all, e.g. for C the dependencies are computed by the compiler itself,
not by a different tool.
|
|
I support attempts at removing boot/ocamldep. What about using the command-line to enable ocamldep behavior from withing ocamlc/ocamlopt? E.g. a sub-command syntax "ocamlc depend ..." (I think the risk of conflict with current use is tiny: all files passed on the command-line usually have an extension). User code would need to be adapted, but one can always produce an |
|
Yes @alainfrisch that's what I tried to suggest, although the initial
suggestion was not fully correct.
ocamldep could become just a script that invokes the feature from the
compiler...
|
This probably won't work under Windows, but is indeed an option elsewhere. I think that a dedicated "sub-command" is better in this case than a regular option, because ocamldep itself has a number of command-line options than are irrevelant for the compiler. |
|
Alain Frisch (2017/03/06 07:19 -0800):
> ocamldep could become just a script that invokes the feature from the compiler...
This probably won't work under Windows, but is indeed an option
elsewhere.
Ah, indeed. Well if it does not work under Windows it's probably not
worth doing, even if it works elsewhere...
I think that a dedicated "sub-command" is better in this case than a
regular option, because ocamldep itself has a number of command-line
options than are irrevelant for the compiler.
Yeah and there may be ocamldep options which conflict with
ocamlc/ocamlopt ones, that's what I meant when saying that my suggestin
was not fully correct.
|
|
Why not call the sub-command |
|
@damiendoligez I don't understand your comment, which new syntax for command-line arguments ? The new version uses |
3ab0a8f to
44f0c34
Compare
|
@alainfrisch was talking about using Since you used |
driver/makedepend.ml
Outdated
|
|
||
| let main_from_option () = | ||
| if Sys.argv.(1) <> "-depend" then begin | ||
| Printf.eprintf "Fatal error: argument -depend must be used first.\n%!"; |
There was a problem hiding this comment.
This should probably say must be in first position or something.
There was a problem hiding this comment.
I could write must be used as first argument, is it better ?
driver/makedepend.ml
Outdated
| exit 2; | ||
| end; | ||
| incr Arg.current; | ||
| Sys.argv.(!Arg.current) <- Sys.argv.(0) ^ " -depend"; |
There was a problem hiding this comment.
Why do you do this? As far as I can tell, it doesn't do anything because lines 531 and 534 use a hard-coded program name instead of argv.
There was a problem hiding this comment.
Because otherwise, the error message printed in case of argument error would wrongly use -depend as the name of the program...
driver/optmain.ml
Outdated
| Clflags.add_arguments __LOC__ (Arch.command_line_options @ Options.list); | ||
| Clflags.add_arguments __LOC__ | ||
| ["-depend", Arg.Unit Makedepend.main_from_option, | ||
| "ARGS Compute dependencies between source files"]; |
There was a problem hiding this comment.
You should refer the user to ocamlc -depend -help for an explanation of ARGS, or even just replace this message with "<options> run ocamldep on <options>".
There was a problem hiding this comment.
Ok for <options> Compute dependencies (use 'ocaml -depend -help' for help) ?
There was a problem hiding this comment.
As my well-known hidden agenda is to get rid of ocamldep, I don't want to refer to it here...
|
Damien Doligez (2017/03/22 08:23 -0700):
You should refer the user to `ocamlc -depend -help` for an explanation
of ARGS, or even just replace this message with `"<options> run
ocamldep on <options>"`.
But it won't _run_ ocamldep, actually, right? Perhaps "same as
running"... would be more accurate?
|
|
Regarding your changes to the Makefile: Since CAMLDEP does now call CAMLC, CAMLC=$(CAMLRUN) boot/ocamlc And then replace the occurrences of $(CAMLC) by |
I believe people are used to the notion of subcommand, and it would make it clearer that (i) the new option can only be used as the first argument; (ii) this option switches the CLI parsing to an entirely different set of command-line options. |
|
Alain Frisch (2017/03/22 10:04 -0700):
> @alainfrisch was talking about using depend (rather than -depend) as the subcommand name, and that is what I found objectionable.
I believe people are used to the notion of subcommand,
That holds for tools like git but not for compilers, in my opinion.
and it would make it clearer that (i) the new option can only be used
as the first argument; (ii) this option switches the CLI parsing to an
entirely different set of command-line options.
The thing is that without the dash there is kind of an ambiguity, since
you can't say for sure whether that first thing you are parsing is an
option or a filename. Plus, as far as I know ocamlc does not even
support the -- thing to force the remainder of the command-line to be
parsed as file names.
One may argue that if the first argument does not have an extension then
it is considered to be a subcommand but I am not sure how
backward-compatible that would be.
|
|
Yes, assuming that a first command-line argument without an extension is a subcommand should work fine, since the files passed to the compiler always have an extension, as far as I know.
What's the difference? |
|
Alain Frisch (2017/03/22 10:21 -0700):
> That holds for tools like git but not for compilers, in my opinion.
What's the difference?
You said that people are used to sub-commands and I guess you meant they
are used to that in general. I just wanted to emphasize that I
personnally do not expect a compiler to take subcommands. I am used to
this only in contexts different than compilers. gcc, for instance, does
not take subcommands.
|
But what distinction do you make? |
|
Adding a subcommand would make the interface a bit inconsistent, no ? Maybe I can just add the option, and we can later discuss a subcommand schema for OCaml ? |
|
Alain Frisch (2017/03/22 10:31 -0700):
> I just wanted to emphasize that I personnally do not expect a compiler to take subcommands.
But what distinction do you make? `ocamlfind`, for instance, uses
sub-commands to call compilers.
Indeed. Just that ocamlfind did that from the beginning, or from as far
as I can remember in the past, while as far as I know ocamlc and
ocamlopt do not have a notion of subcommand so far.
But why not, after all.
|
|
Fabrice Le Fessant (2017/03/22 10:33 -0700):
Maybe I can just add the option, and we can later discuss a subcommand
schema for OCaml ?
Looks wise to me and is in agreement with what @damiendoligez wrote.
|
Why not, but we would then need to maintain backward compatibility with
Indeed. But we are talking here about including an "entirely" different tool, with its own command-line arguments, into an executable that does otherwise something else. This seems to be a good time to discuss this idea of using a sub-command syntax for such cases.
Technically speaking, some features of git are accessible without a subcommand ( Btw, did you consider also merging ocamllex into ocamlc? |
|
Alain Frisch (2017/03/22 10:54 -0700):
Btw, did you consider also merging ocamllex into ocamlc?
Hmm. gcc has -MM for dependencies so having a way to compute
dependencies with the compiler itself in OCaml seems reasonable to me.
It's not quite the same for generating a lexer.
|
|
Is this feature discussed for 4.05 or 4.06 ? I assumed it was for 4.06, so I would expect we would have time to decide on a subcommand scheme later. |
|
We shouldn't restrict ourselves to what another command does, especially as old as |
|
New version with the requested changes. I also took this opportunity to add |
|
Fabrice Le Fessant (2017/03/24 07:31 -0700):
New version with the requested changes.
Thanks. Three remarks / questions:
1. About the Changes entry: it says that the -depend option has been
added to ocamlc. Hasn't it been added to ocamlopt, too?
2. About the Makefile. Your implementation indeed requires less changes
than the one I have suggested (because it does not touch the CAMLC
variable), but to be honest I find it a bit hackish.
3. About the help text:
"(use 'ocamlc -depend -help' for help)" looks uselessly redundant to me.
I'd say either "(use 'ocamlc -depend -help' for details)" or simply (use
'ocamlc -depend -help')
I also took this opportunity to add `Depend.pp_deps`, a variable that
plugins can use to add dependencies (for example to a file that was
included or used to generate some code). They will be printed in the
standard output, but not in the raw output.
To me this is not really related to this PR so I'd rather have this
submitted in a separate one.
|
Fixed !
I don't see why. The other solution would have uselessly added $(CAMLCFLAGS) to all the lines in the Makefile, whereas this one is much shorter. So, isn't it the other way around ?
Fixed !
I would have to create another git branch, another PR, start a new discussion, just for 5 lines of changes that do nothing if you don't use plugins. Is it really worth wasting that much time, just for the sake of respecting the "process" as much as we can ? I would do it if Damien tells me he wants to cherry-pick it to 4.05 :-) |
|
Fabrice Le Fessant (2017/03/24 08:28 -0700):
> 1. About the Changes entry: it says that the -depend option has been
added to ocamlc. Hasn't it been added to ocamlopt, too?
Fixed !
Thanks. Sorry to be picky, may I suggest to say:
- GPR#1078: add the -depend subcommand to ocaml{c,opt}, ...
And, wouldn't it be worth mentionning which GPR added ocamldep to boot
in this entry?
> 2. About the Makefile. Your implementation indeed requires less changes
> than the one I have suggested (because it does not touch the CAMLC
> variable), but to be honest I find it a bit hackish.
I don't see why. The other solution would have uselessly added
$(CAMLCFLAGS) to all the lines in the Makefile, whereas this one is
much shorter. So, isn't it the other way around ?
Well I hope these lines can be factorized a bit in the future. That
being said I agree it's not done yet. Still, I believe the $(COMPILER)
$(COMPILERFLAGS) approach is widespread in makefiles and in my opinion
it is clearer to read and makes it more straightforward to override just
the flags...
But that's a minor remark, I am fine with the code as it is now.
> About the help text:
Fixed !
Thanks.
> To me this is not really related to this PR so I'd rather have this
> submitted in a separate one.
I would have to create another git branch, another PR, start a new
discussion, just for 5 lines of changes that do nothing if you don't
use plugins. Is it really worth wasting that much time, just for the
sake of respecting the "process" as much as we can ? I would do it if
Damien tells me he wants to cherry-pick it to 4.05 :-)
Let's see what others think about it. As I said, I'm fine with the code
as it is now, my remark was also for the future.
|
I'm not sure I understand this sentence. Does this mean you output a different dependency graph depending on the textual format chosen for the output? |
|
@damiendoligez It means that |
This breaks the invariant that dependencies printed with "-modules" are a superset of the ones printed with ocamldep's default mode. At the very least, I am not sure to understand why |
To the best of my knowledge, this subject has never been discussed before, I have never heard of such an invariant.
Because the files that would be included in that list are not modules, so they have no .cmo, .cmi, .cmx ? If there is some popular demand for it, I can add an option |
|
@lefessan you need to update the man pages and the reference manual. I'll be particularly interested in seeing your specification of |
|
@damiendoligez Currently, there is no change in the arguments of |
|
I mean you should document the interface you offer to plug-ins, obviously. You also need to document the |
|
Yes, I should do it for For the plugin API, where shall I start ? By describing all the internal data structures (parsetree, typedtree, lambda, clambda, cmm, mach) that are accessible to plugins ? Then, any modification in the code of the compiler would require a change in the documentation... |
|
Fabrice Le Fessant (2017/03/30 13:22 -0700):
Yes, I should do it for `-depend`.
For the plugin API, where shall I start ? By describing all the
internal data structures (parsetree, typedtree, lambda, clambda, cmm,
mach) that are accessible to plugins ? Then, any modification in the
code of the compiler would require a change in the documentation...
Sure, but couldn't the documentation be kept close to the code it
documents?
|
|
Honestly, I don't see what plugins add to the already existing compiler-libs, for which we did not provide any documentation. Ppx have been around too for a while now, and their internals (and API) are not documented either. For me, such APIs are not to be used by OCaml developers, they are supposed to use existing plugins, not to develop them. If we start going into another direction, we should also reject any modification of the compiler that is not commented enough for any OCaml developer to understand it, as he might use that code through plugins or compiler-libs... |
Hooks are entry points to be used by external code, by definition. Ideally all internal APIs should be documented (and some parts are indeed being incrementally documented), but new entry points deserves a few lines of documentations. It's not about specifying formally all internal data structures and invariants, just adding a few lines of docstrings for each hook. Explaining what the Depends.pp_deps is and how it is supposed to be used could be done in probably 5 lines of texts and would make it much more useful.
What do you mean? I find Ast_mapper and Parsetree rather well documented, and it is roughly the API surface required for ppx.
Hooks are added so that they can be used. Hopefully not by newcomers, but not necessarily only by core developers (and even for them, a few lines of explanation would be useful). |
I just discovered chapter 24 of the manual, I was previously mistaken by the missing link in the documentation of
I will do it once there is an agreement that the PR will be accepted. |
Thanks for pointing the missing link, see #1129 for a fix. |
Another possibility would be a flag ( |
61dac78 to
abe3547
Compare
|
I updated this PR:
|
|
@damiendoligez Do you need more changes for acceptation ? |
|
Fabrice Le Fessant (2017/05/14 07:47 -0700):
I updated this PR:
* It is not used anymore in the current Makefiles. The idea is to
first accept the PR, wait for a bootstrap of the compiler, making
`-depend` available for the Makefiles, and then provide a new PR to
use it and remove boot/ocamldep
This looks nice to me. I'd just modify the title of the PR so that it
describes its current content more accurately.
* the manual and the man pages have been updated with a short
description of `-depend`
This looks good to me.
Re: the code that is moved from tools/ocamldep.ml to driver/makedepend.ml:
- I am not fully convinced by the name, makedepend. Wouldn't something
like ocamldep_internal be more appropriate? Well I am not sure this
proposal is really good, but I find the current name a bit misleading.
- I understand that the GPL header in the .mli file comes from the .ml
file, but I am still wondering whether it wouldn't be more accurate to
change the year and author in the interface.
|
|
@shindere I think the header date is OK, and the file name doesn't look so bad. We can change it later if needed. |
|
Damien Doligez (2017/06/01 06:56 -0700):
@shindere I think the header date is OK, and the file name doesn't
look so bad. We can change it later if needed.
OK
|
Size of ocamldep has recently increased from 700 kB to 2 MB with the fix for -plugin. Since ocamldep is included in boot/ for safety reasons, this increase in size might become a problem in the future. This PR removes boot/ocamldep, and makes boot/ocamlc an equivalent for ocamldep:
when renamed as
ocamldep,boot/ocamlcwill behave asocamldepNo bootstrap commit added, I will only do it if the PR is accepted.