mjambon / dune-deps

Show the internal dependencies in your OCaml/Reason/Dune project
BSD 3-Clause "New" or "Revised" License
60 stars 5 forks source link

The format of dune files is not exactly the same as the sexplib format #4

Open ghost opened 4 years ago

ghost commented 4 years ago

There are a few differences between the format of dune files and the s-expressions parsed by sexplib. As a result, dune-deps cannot parse certain files. For instance, if I call dune-deps on dune itself, I get:

$ dune-deps 
Error: Cannot parse dune file ./test/blackbox-tests/test-cases/dune-ppx-driver-system/driver-tests/dune: exception (Sexplib.Sexp.Parse_error
  ((err_msg "unexpected character: ')'") (text_line 116) (text_char 21)
    (global_offset 2645) (buf_pos 2645)))

Eventually, we will probably extract a small stable library as we did for csexp and pp for parsing dune files. Another idea would be to rely on dune describe, which is meant precisely for this purpose: providing a stable interface for extracting information out of a dune project.

mjambon commented 4 years ago

I had noticed this error while running dune-deps on dune, but I quickly brushed it off, wrongly assuming that it was an intentionally broken test case :-p

The solutions you suggest look promising. Not sure what's best at the moment. To be continued.

mjambon commented 4 years ago

I haven't added support for the real dune syntax, but I added a --exclude or -x option to work around it. :-p

Together with the new -h option, we're getting something which looks usable.

dune

The command to make the image above is:

$ cd dune  # dune git repo
$ dune-deps -h dune -x test | tred | dot -Tpng > dune.png
ghost commented 4 years ago

Nice :)

BTW, I started working on a small separate library for parsing and editing dune files, in particular so that users can apply automatic transformations to dune files (cf https://github.com/ocaml/dune/issues/3337). It's not yet ready, but if you want to experiment with it, I'm happy to put it up.

mjambon commented 4 years ago

I like the idea of relying on a dune-compatible S-expression library, rather than depending on dune as a whole. For the sake of maintenance, I like that dune-deps doesn't depend on a specific version of dune. I don't mind if certain things don't work perfectly, such as the exclusion of files using (dirs ...).

I'm happy to create a branch for testing the new parsing library. I'd need a public git URL and a build/install command.

ghost commented 4 years ago

Alright, so I got a first version there: https://github.com/diml/dune-files. make&make install should do. A good entry point is Dune_files.Parser.load.

The name is not great BTW, but I don't know how to call it. If you have some ideas, I'm interested :)

mjambon commented 4 years ago

Looking good so far, thank you! I'll let you know how it goes.

mjambon commented 4 years ago

I created a parsing branch which works (as of commit ef75f53). You can try it out if you want. make && make test && make install should work if you have dune-files installed.

Regarding the name: dune-file sounds better to me than the plural version. I'm not great with names in general, though.

I also have a couple questions which I'll post on the dune-files repo.

ghost commented 4 years ago

dune-file seems better indeed, I'll remove the s