-
-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
POC : static computation of source roots for code-generating tasks #4621
base: 0.12.x
Are you sure you want to change the base?
Conversation
@Baccata one new development worth mentioning is that #4524 targeting 0.13.x, we've moved the computation of Following the naming convention would just define a |
@lihaoyi, with the difference that the case class SourceGenerator(task: T[Unit], sourceRoots: Seq[os.SubPath])
trait JavaModule {
def sourceGenerators : Seq[SourceGenerator]
} But, putting aside the details, I agree that source generators are better captured statically like the |
See c262ea6 for a showcase of what I meant in #4621 (comment) |
val dest = mill | ||
.eval | ||
.EvaluatorPaths | ||
.resolveDestPaths(workspace / "out", task) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't know whether there's a better way to do it, to be honest
/** | ||
* The folders containing all source files fed into the compiler | ||
*/ | ||
def allSources: T[Seq[PathRef]] = Task { sources() ++ generatedSources() } | ||
def allSources: T[Seq[PathRef]] = | ||
Task { sources() ++ generatedSources() ++ deferredGeneratedSources() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeps the current (0.12.x) behaviour of generatedSources
to avoid breaking the ecosystem
@@ -133,14 +137,19 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule { | |||
!module.asInstanceOf[outer.Module].skipBloop | |||
else true | |||
|
|||
private def deferredAllSources(m: JavaModule): T[Seq[PathRef]] = Task { | |||
m.sources() ++ m.generatedSources() ++ m.allDeferredSourceRoots() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeps the current (0.12.x) behaviour of generatedSources
being run to produce IDE config, in order to avoid breaking the ecosystem. In addition, adds roots that will be produced by deferredSourceGenerators
when allSources
/compile
is run.
Context : #4530
@lihaoyi, I want to open this PR to continue the discussion. At the time of writing this, this adds a
generatedSourceRoots
parameter for tasks, as you've described, and uses it to compute the source directories for the bloop configuration, as opposed to actually running theallSources
task. A similar change would need to be achieved inGenIdea
andBSP
.So now, the problem I see is as follows : in order for this to be useful, it needs to be applied to all source generators provided OOTB by the mill codebase, but also third party providers of source-generator (like smithy4s), as the ability to jump to the sources is paramount for the user experience in IDEs.
Applying this change is a fair bit of work in this codebase, and a big ask for the larger ecosystem, and although I think SBT's approach of treating all source generators lazily is preferable to mill's current approach of running all source generators eagerly, I don't think I can weigh the benefits of changing the approach against the cost induced by breaking IDE behaviour for existing plugins.
With that in mind here's what I think would be a good mitigation :
The
Bloop
,GenIdea
andBSP
then get amended to callsources()
,generatedSources()
andlazyGeneratedSourceRoots()
, but avoidsrunLazySourceGenerators
.This approach would allow to alleviate the pain point raised in the discussion above, whilst retaining the current behaviour of the ecosystem. Mill plugin providers could be encouraged to use
runLazySourceGenerators
instead ofgeneratedSources
, but users would have a recourse to turn eager source generators into lazy ones if they need it to be (provided awithGeneratedSourceRoots
is provided to them, that is)