lf-lang / lingo

Package manager and build tool for the Lingua Franca coordination language
BSD 2-Clause "Simplified" License
4 stars 1 forks source link

What should be the output of `lfc`? #30

Closed erlingrj closed 12 months ago

erlingrj commented 1 year ago

In today's (July 25th) meeting, we discussed how lfc could/should be changed to output JSON on the stdout which can be consumed by lingo. The usecase motivating this is currently that for the C target, lfc will generate compile definitions based on the source code, i.e. not only based on the target properties. Currently lfc spits out a CompileDefinitions.txt in the src-gen folder with these compile defs as well. For lingo to generate the CMakeLists.txt by itself, it would need this information. Either by using this CompileDefinitions.txt file or, as discussed today, by changing the output of lfc to be e.g. a JSON which contains this info.

lfc also outputs all sorts of other useful information while compiling which we also need. A potential disadvantage of having it output a JSON is that we might have to wait until the compilation is completed before lfc can output this JSON, this would be very bad for the user experience.

cmnrd commented 1 year ago

Producing a json output sounds good to me. It would likely need to have target specific sections, but that should be Ok.

lfc also outputs all sorts of other useful information while compiling which we also need. A potential disadvantage of having it output a JSON is that we might have to wait until the compilation is completed before lfc can output this JSON, this would be very bad for the user experience.

I don't follow this point. Why would we need to wait, and what is bad about it?

erlingrj commented 1 year ago

If I understand correctly. If we want lfc to output a JSON with both human-readable info about the compilation process (e.g. the "info" and "warning" messages), and also other fields, e.g. compileDefinitions. Then, lfc would need to "build" this JSON string internally, while compiling and write it to stdout at the very end, when it completes. Then we wouldnt get the info and warning messages "as-we-go".

I guess it could continously write this JSON string as it compiles. And Lingo could work with a partial JSON string to forward the info/warning messages. I havent worked much with JSON, is it common to receive a JSON as a stream and parse it partially and work with the partial result and then go back to parsing more of the stream?

cmnrd commented 1 year ago

This is what lfc does already internally. It collects all errors and warnings and only prints them when exiting. Producing the json would only require a different message printer, which should be quite easy to add. Normally, lfc should run quite fast (if it just does the code generation and no target compilation), so there shouldn't be a noticeable difference anyway.