Dune init, I'm confused again

dune init proj foo doesn’t seem to generate any dune-project file. Does that mean dune-project files are optional? If so, how does dune know what package(s) I’m going to build? Ok, maybe it doesn’t care about packaging for a freshly bootstrapped project … but it does generate a foo.opam. So yes, I’m confused.

1 Like

dune-project files are required. dune init has some issues that need to be fixed

2 Likes

We reported just the same issue recently at dune#5429 while writing the RWO chapter on OCaml tooling.

Also, consequent creation of projects work in not expected for me manner. For example

➜  1 dune init proj hello --ppx ppx_inline_test --inline-tests                                                                                 4.13.1+flambda
Success: initialized project component named hello
➜  1 tree                                                                                                                                      4.13.1+flambda
.
├── _build
│   └── log
└── hello
    ├── bin
    │   ├── dune
    │   └── main.ml
    ├── hello.opam
    ├── lib
    │   └── dune
    └── test
        ├── dune
        └── hello.ml

5 directories, 7 files

It’s fine for now, but

➜  1 dune init project asdf -ppx ppx_inline_test --inline-tests                                                                                4.13.1+flambda
Success: initialized project component named asdf
➜  1 tree                                                                                                                                      4.13.1+flambda
.
├── _build
│   └── log
├── hello
│   ├── bin
│   │   ├── dune
│   │   └── main.ml
│   ├── hello.opam
│   ├── lib
│   │   └── dune
│   └── test
│       ├── dune
│       └── hello.ml
└── ppx_inline_test
    └── asdf
        ├── asdf.opam
        ├── bin
        │   ├── dune
        │   └── main.ml
        ├── lib
        │   └── dune
        └── test
            ├── asdf.ml
            └── dune

10 directories, 13 files

creates hierarchy that I don’t expect. Yes, I forgot extra dash, but it shouldn’t work like this.

This is a bit of a strange case, and has nothing in particular to do with dune init, afaict, but just with CLI parsing in general (perhaps with cmdliner in particular?).

The schema for dune init is:

dune init [OPTION]... INIT_KIND NAME [PATH]

But, in fact, the OPTIONs can be passed in at any point between the positional arguments. The third positional argument is the PATH, which is documented thus:

   If the optional PATH is provided, the component will be created there.

In the case of this invocation, I believe -ppx is getting read as the -p flag (short for --for-release-of-packages) passed the value px, and then ppx_inline_test is being given as the third positional argument, specifying a directory path in which to create the project.

I definitely think the CLI around init could be made simpler, but I’m afraid what you’re hitting here is more to do with the suboptimal nature of CLIs as a user interface :slight_smile:

For anyone interested, I’ve supplied more information on this point here: "dune init project" doesn't create a dune project file, creates unnecessary _build file · Issue #5429 · ocaml/dune · GitHub

If you can figure out how to install from master, it should fix the problem of missing dune-project files in the short term (until 3.0 is released), tho unfortunately it doesn’t seem like is as simple as opam pin https://github.com/ocaml/dune.git at the moment :confused: