-
Notifications
You must be signed in to change notification settings - Fork 413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add dune init
command
#1448
Add dune init
command
#1448
Conversation
f811db7
to
66304ff
Compare
(Looks like I need to make several small changes for older OCaml versions. I'm looking in to that now.) |
66304ff
to
2555b7a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand the necessity of functor or first class modules here. It seems like plain old records would work just as well here.
I opted for modules to avoid having to thread the name and path parameters through a bunch of functions. However, I can definitely understand that the end result seems quite heavy duty given the simplicity of the feature added! Moreover, if we're not generating any content for the files, there's less need to thread those parameters through. I'll re-structure for a more lightweight approach. |
Thanks, we have situations in dune where we have a little too much boilerplate and we go with functors but the situation here is nowhere near as acute. The only case where we use first class modules are plugins, so introducing it here to get rid of a boilerplate is certainly unprecedented. I think the code will look quite clean with records by the way so boilerplate won't even be an issue. |
2555b7a
to
997eaeb
Compare
Notes on a few of the changes:
|
Okay, looks really nice. Good work @shonfeder. Before I merge I'm planning the following UI changes:
If you see any problems or propose any changes to these suggestions, please feel free to discuss. If you'd like some help in implementing some of this stuff, I'll gladly help out as well as I realize that some of these change aren't small. We'll also need to add a test suite for this feature. I suggest that we add this test suite before we start any of the changes I've proposed. If you need help here, I'm happy to point you in the right direction or put up a few tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This nex feature will probably open up a healthy amount of bikeshedding but this is probably necessary!
By the way, this issue is relevant to make the opam files obsolete: #1112 There are no immediate plans to implement this (we are looking for volunteers), but it shouldn't be too hard and hopefully will be present in the next version or two |
I have a question on one point, re: "Add the ability to put paths in the argument $ dune init <lib|exe> foo/bar". The current interface allows for Other than that, I don't have any problems with the proposed changes and I'm happy to make them. I will let know if I get stuck or bogged down, but I think I should be able to bring those changes about in the next several days. Thanks for the guidance, corrections, and reviews so far, @rgrinberg and @emillon! |
Well the current behavior isn't ideal as it's forcing a particular directory structure. Dune doesn't really recommend any directory structure and many existing projects and users will have their own preference regarding this. Therefore it seems best to make the feature usable with any kind of directory structure. My suggestion was just one idea on how to add the flexibility to create w/e directory structure the user wants. I'm happy to hear other suggestions. The use cases I have in mind are:
Thanks, we appreciate your work. |
Ah, I think I understand what you are after now: we're not talking about the root directory of the project but the directory in which the @rgrinberg, according to the plan sketched out at #159 (comment), the two features you mention
would be supplied by the |
It seems like Also, I'm not very sure how Here's another suggestion, if we want By the way, I think it would help to have a type like: type common =
{ name : string
; in_ : Path.t
}
type public = bool
type inline_tests
type init = (* pick your own name here *)
| Executable of common * public * libraries
| Library of common * public * libraries * inline_tests
| Test of common * Lib_name.t (* the library that we are testing *)
| Project of common (* This constructor would include Library + Test for example *) The above makes it very clear what arguments anything that we can |
I am OK with ditching the Rather than I will build out the API for init along the lines you suggest: that makes good sense to me. I'm hoping to have all the suggested changes in place and ready for review by the end of next week. [edited to amend estimate on turnaround time for completion] |
Sorry, my suggestion I suppose the main difference between between our tool and cargo/stack is the once-only restriction of the templates that I'm not so fond of. It's true that a tool that quickly generates dune boilerplate vs a tool that starts a new project aren't the same thing. But it seems like at least a flexible Btw, I have no experience with |
I thought I recalled this being an issue.... according to dbuenzli/cmdliner#24, cmdliner doesn't support nested subcommands. Does anyone know of a reasonable way around this? |
Ah, in dbuenzli/cmdliner#95 there is mention of implementing sub commands manually using positional arguments. Before I dig in to that, I'd like to confirm that the increased complexity of manual implementation of subcommands here is worth the cost. We should perhaps also consider that, since |
Just had the (obvious) realization that |
If we intentionally choose a suboptimal CLI for dune just because it's more convenient we are going to regret it down the line. |
Yes, this is alright for now. Although note that it's still not optimal because the help shown will not be specialized by the type. |
Ah, ok. So we do want this to be a nested subcommand -- for the focused help message (and added flexibility, etc.). So, just to be sure we're on the same page and that I understand correctly what's wanted here: completion of this PR (in it's ideal form) is now dependent on implementing a custom extension to cmdliner's CLI parsing that supports nested subcommands with their own help menus. Correct? |
Yup, that would be ideal. But the workaround you proposed is backwards compatible so I'm personally ok with delaying the fully featured CLI. |
@shonfeder I'm curious, why didn't you just use dune's own parsing code for parsing the stanzas? This way, I think we have some duplication in the code and it isn't very desirable. |
@rgrinberg Can you please specify which part of the code you think introduces parsing duplication and what existing code you think I might use instead? Afaik, I do very little in the way of parsing here. The only exception that comes to mind is the temporary function https://github.com/ocaml/dune/pull/1448/files#diff-ec22fb5fe4ab585936d484f498556279R69, which has the very specific purpose of identifying conflicting stanzas from the already loaded Edit: To clarify, I'm all for reducing code duplication if possible. |
Also, note that we need to preserve comments, since we read in and then re-emit dune code in dune files that may be hand written. |
@shonfeder yeah, that's indeed the function I'm talking about. Why is there an issue here regarding comments btw? We are simply using the My idea would be to get rid of Also note that we if we initialize a "super context", then we'll have all the parsed stanzas for free. |
Yep. That's a better idea for identifying conflicts. I'll make the change this weekend.
The issue with the comments in general is this: since we aim to be able to extend existing dune files and stanzas, we have to preserve the comments which users may have added. This means that in general, we can't just work with the
I wasn't aware of |
Indeed, but it it can be used for just identify conflicts. The dune file can then be re-parsed to cst's when necessary. |
@rgrinberg In order for the planned code reuse to work in a sensible way, the I would, of course, be happy to work out this plumbing myself, but if that is required, I think we should just mark this with a |
Yeah, that's fine with me as well. Let's do the following:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found a few typos.
Thanks for catching those, @kevinji -- fixed now. @rgrinberg action items addressed. Unless something else comes up, I think this should be ready for merge once CI is finished. |
After discussion on #1972, I've learned I was misunderstanding how I also need to correct a documentation comment is added to that function in this PR. |
Signed-off-by: Shon Feder <[email protected]> Signed-off-by: Rudi Grinberg <[email protected]>
@shonfeder Please make this improvement in a subsequent PR. Thank you for all the hard work on this. Let's track future improvements in other tickets. |
CHANGES: - Warn when generated `.merlin` does not reflect the preprocessing specification. This occurs when multiple stanzas in the same directory use different preprocessing specifications. This warning can now be disabled with `allow_approx_merlin` (ocaml/dune#1947, fix ocaml/dune#1946, @rgrinberg) - Watch mode: display "Success" in green and "Had errors" in red (ocaml/dune#1956, @emillon) - Fix glob dependencies on installed directories (ocaml/dune#1965, @rgrinberg) - Add support for library variants and default implementations. (ocaml/dune#1900, @TheLortex) - Add experimental `$ dune init` command. This command is used to create or update project boilerplate. (ocaml/dune#1448, fixes ocaml/dune#159, @shonfeder) - Experimental Coq support (fix ocaml/dune#1466, @ejgallego) - Install .cmi files of private modules in a `.private` directory (ocaml/dune#1983, fix ocaml/dune#1973 @rgrinberg) - Fix `dune subst` attempting to substitute on directories. (ocaml/dune#2000, fix ocaml/dune#1997, @rgrinberg) - Do not list private modules in the generated index. (ocaml/dune#2009, fix ocaml/dune#2008, @rgrinberg) - Warn instead of failing if an opam file fails to parse. This opam file can still be used to define scope. (ocaml/dune#2023, @rgrinberg) - Do not crash if unable to read a directory when traversing to find root (ocaml/dune#2024, @rgrinberg) - Do not exit dune if some source directories are unreadable. Instead, warn the user that such directories need to be ignored (ocaml/dune#2004, fix ocaml/dune#310, @rgrinberg) - Fix nested `(binaries ..)` fields in the `env` stanza. Previously, parent `binaries` fields would be ignored, but instead they should be combined. (ocaml/dune#2029, @rgrinberg) - Allow "." in `c_names` and `cxx_names` (ocaml/dune#2036, fix ocaml/dune#2033, @rgrinberg)
CHANGES: - Warn when generated `.merlin` does not reflect the preprocessing specification. This occurs when multiple stanzas in the same directory use different preprocessing specifications. This warning can now be disabled with `allow_approx_merlin` (ocaml/dune#1947, fix ocaml/dune#1946, @rgrinberg) - Watch mode: display "Success" in green and "Had errors" in red (ocaml/dune#1956, @emillon) - Fix glob dependencies on installed directories (ocaml/dune#1965, @rgrinberg) - Add support for library variants and default implementations. (ocaml/dune#1900, @TheLortex) - Add experimental `$ dune init` command. This command is used to create or update project boilerplate. (ocaml/dune#1448, fixes ocaml/dune#159, @shonfeder) - Experimental Coq support (fix ocaml/dune#1466, @ejgallego) - Install .cmi files of private modules in a `.private` directory (ocaml/dune#1983, fix ocaml/dune#1973 @rgrinberg) - Fix `dune subst` attempting to substitute on directories. (ocaml/dune#2000, fix ocaml/dune#1997, @rgrinberg) - Do not list private modules in the generated index. (ocaml/dune#2009, fix ocaml/dune#2008, @rgrinberg) - Warn instead of failing if an opam file fails to parse. This opam file can still be used to define scope. (ocaml/dune#2023, @rgrinberg) - Do not crash if unable to read a directory when traversing to find root (ocaml/dune#2024, @rgrinberg) - Do not exit dune if some source directories are unreadable. Instead, warn the user that such directories need to be ignored (ocaml/dune#2004, fix ocaml/dune#310, @rgrinberg) - Fix nested `(binaries ..)` fields in the `env` stanza. Previously, parent `binaries` fields would be ignored, but instead they should be combined. (ocaml/dune#2029, @rgrinberg) - Allow "." in `c_names` and `cxx_names` (ocaml/dune#2036, fix ocaml/dune#2033, @rgrinberg) - Format rules: if a dune file uses OCaml syntax, do not format it. (ocaml/dune#2014, fix ocaml/dune#2012, @emillon)
Towards completion of #159
This implements creation of new projects, as discussed in #159 (comment) and using the more simplistic, hard-coded strings approach encouraged here #159 (comment)
I think tests ensuring initialized projects can be build should be included in this PR, but I'd like to get the general shape of the implementation OKed before writing the test cases.