[sbt 1.0] Support sourceGenerators += Def.task { ... }#2942
[sbt 1.0] Support sourceGenerators += Def.task { ... }#2942
Conversation
This adds a macro-level hack to support += op for sourceGenerators and resourceGenerators using RHS of Initialize[Task[Seq[File]]]. When the types match up, the macro now calls `.taskValue` automatically.
dwijnand
left a comment
There was a problem hiding this comment.
I don't know if we're improving or not the situation by adding a macro-level hack.
|
At least the end-user won't have to think about the subtlety of "task" vs |
|
This would be like a macro-level hack so you could do Personally I think this would be just as easily solved with a |
|
My real target is the backport to 0.13.14, so we can address both of the issues that came up in 0.13.13 regarding |
|
I think instead we should provide |
|
I don't see sourceGenerators in Compile += buildInfo,
sourceGenerators in Compile += Def.task { Nil } |
What discrepancy? What do you mean? |
In general this is where the rubber meets the road, or (insert impedance mismatch analogy). Similarly, what we colloquially call "tasks" are My claim is that the build user expects sourceGenerators in Compile += buildInfo |
|
Should you also be able to write |
No, I don't think so. We know crossScalaVersions += scalaVersion.valueThe tricky bit is that |
|
Let's be clear, If it's accepted that you can't And if adding an inline task by writing Or, of course, it's your prerogative to overrule me. |
I'm fairly sure this magic is the way to go. For a reference, earlier version of sbt required In this case, the implicit conversion from "task" to
|
|
why have a macro at all, isn't this ideal for an implicit conversion? |
|
A few thoughts:
|
|
I am doing an implicit conversion. It's just that the RHS requires a macro, so it's stubbed with |
|
One thought: is the failure in CI relevant? I believe it is. |
|
iirc I cancelled the Travis job on merge commit because there was some other thing I needed to verify at the time. |
This is on top of #2937
During the docs review, one of the comments we got from @lihaoyi was:
A quick answer is because the types don't match up. The expected type for the generator is
Seq[Task[Seq[File]]]whereasDef.task { ... }returnsDef.Initialize[Task[...]].Initialize[_]is sort of the DAG node, andTask[_]is like a beefed upFunction0[_].Since we are pretty sure what user wants, we can extract the
Task[...]out ofInitialize[Task[...]].Append instance that extracts taskValue
This adds a macro-level hack to support += op for sourceGenerators and resourceGenerators using RHS of Initialize[Task[Seq[File]]]. When the types match up, the macro now calls
.taskValueautomatically.