scala-cli
scala-cli copied to clipboard
[OLD PoC] Source generators
This is an old PoC for implementing source generators that was supposed to use Bloops capability to run an arbitrary command that would generate the sources.
Bloop.Project.sourceGenerators accepts a list of objects of this shape:
SourceGenerator(sourcesGlobs: List[SourcesGlobs], outputDirectory: PlatformFiles.Path, command: List[String])
By quickly looking at Bloop's code the command gets created like this:
(command :+ outputDirectory.syntax) ++ inputs.keys.map(_.syntax), where the inputs are the results of applying sourceGlobs
So trying to work with this, I wanted to run scala-cli command on a small app that uses dep "com.thesamet.scalapb::scalapbc:0.11.13", which would generate the sources before Bloop's compilation would run.
Unfortunately this didn't work, I recall that the command never managed to generate sources even though Bloop would run it (I think). Probably there was a problem with the command also calling Bloop.
I thought about a while ago and IMO for it to work we would need to first build the generator app (potentially without Bloop) and pass the run command to Bloop (sth like java --cp jar1:jar2:scalapbc-jar MainClass outputDir sourceArg1 sourceArg2 ...
We already do similar stuff in our Run command.
Off the top of my head this generator app could also be released to maven, but I don't see any problems in hardcoding it in our sources.
Additionally I think the easiest way would be to rework the Bloop API to allow more flexibility e.g. for calling ScalaPBC's main without the generator-app from gen.scala as it effectively just shuffles arguments around.