Octachron / codept

Contextual Ocaml DEPendencies Tool: alternative ocaml dependency analyzer
Other
59 stars 10 forks source link

codept as a library? #6

Closed mobileink closed 3 weeks ago

mobileink commented 3 years ago

Hello! I'm writing a tool to generate Bazel build files, and I'm using codept to do dependency analysis. I've got a daemon (written in C) that runs fswatch to monitor the source tree, and I'm now adding code to call codept for new or changed files. Currently I'm planning to use posix_spawn to run codept (originally I was using popen).

The daemon is intended to run in the background during development edit sessions, so it could detect lots of changes in a short period of time, and thus spawn/fork a lot of codept jobs. I'm wondering if it would make sense to make a library interface for codept so my code could call it directly. Do you think that would be worth the trouble?

Alternatively, I see from reading the source that you already have a codept_server of some kind. Would it make sense to run a codept server that my daemon could talk to? Do you have any sample code showing how to use the codept_server?

Thanks,

Gregg

Octachron commented 3 years ago

There is already a library core for codept. This part is not published in the opam package, but it is reused in various part of the testsuite (to test that different resolution strategies yield the same result, or what would happen if the name resolver was on the wire and randomly failing). One option would be to publish this library independently.

Another option would be indeed to resurrect the server mode that has been failing on the side by lack of time or interest. Note that the current implementation is really minimalist as far as I remember. It would probably need to be extended. But if there is an use case, that sounds like an interesting venue to explore.

mobileink commented 3 years ago

Thanks, I'll dig into the test code. In the meantime, I'll have some questions about the interface, which I'll post here (for posterity) unless you think discord or some other forum is better.

Octachron commented 3 years ago

Don't hesitate to ask question here about the interface here. It has certainly accumulated some quirks.

mobileink commented 3 years ago

I just noticed license is GPL3. I would not be able to use it as a library with that license. Any chance you could dual license, with some BSD/Apache/etc. type license?

OTOH I may not need a lib. For small projects it's definitely fast enough as an executable, even with a list of > 300 opam libs. It'll be interesting to see how it does with ~ 8K source files.

Octachron commented 3 years ago

Morally, the library part is LGP (with static linking exception). That should be sufficient to be used as a library in a non-copyleft code base? I can add the corresponding license file.

My current performance guestimate is that codept is mostly IO-read bound (since at the module level the structure of most compilation units are very simple). If that model is right, having a server mode that preloads opam libs and stable file would be the easiest way to increase performance without needing to use the library part directly.

mobileink commented 3 years ago

LGPL + static exception would work for me, thanks!

Octachron commented 3 weeks ago

There is now an independent package for the library part, which would be published with the new version 0.12 of codept this month.