-
-
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
Draft
Baccata
wants to merge
4
commits into
com-lihaoyi:0.12.x
Choose a base branch
from
Baccata:baccata/codegen-tasks
base: 0.12.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+92
−12
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ import coursier.{Repository, Type} | |
import mainargs.{Flag, arg} | ||
import mill.Agg | ||
import mill.api.{Ctx, JarManifest, MillException, PathRef, Result, internal} | ||
import mill.define.{Command, ModuleRef, Segment, Task, TaskModule} | ||
import mill.define.{Command, ModuleRef, NamedTask, Segment, Task, TaskModule} | ||
import mill.scalalib.internal.ModuleUtils | ||
import mill.scalalib.api.CompilationResult | ||
import mill.scalalib.bsp.{BspBuildTarget, BspModule, BspUri, JvmBuildTarget} | ||
|
@@ -847,10 +847,59 @@ trait JavaModule | |
*/ | ||
def generatedSources: T[Seq[PathRef]] = Task { Seq.empty[PathRef] } | ||
|
||
/** | ||
* A set of tasks producing generated code. The difference between this and | ||
* [[generatedSources]] lies in the fact that IDE-related tasks | ||
* (BSP/Bloop/GenIdea) will not run the tasks, but will use them to statically | ||
* determine the location of the source code they will produce by looking up their | ||
* [[Task#generatedSourceRoots]], knowing that these roots will be present under | ||
* the dest directories once the task is run. | ||
*/ | ||
def deferredSourceGenerators: Seq[NamedTask[Unit]] = Seq.empty | ||
|
||
private def deferredSourceRoots(task: NamedTask[Unit])(workspace: os.Path): Seq[os.Path] = { | ||
val dest = mill | ||
.eval | ||
.EvaluatorPaths | ||
.resolveDestPaths(workspace / "out", task) | ||
.dest | ||
val explicitSourceRoots = task.generatedSourceRoots | ||
if (explicitSourceRoots.isEmpty) Seq(dest) | ||
else explicitSourceRoots.map(subPath => dest / subPath) | ||
} | ||
|
||
/** | ||
* Computes the list of source roots that will be produced by [[deferredSourceGenerators]] without | ||
* actually running the generators in question. | ||
*/ | ||
def allDeferredSourceRoots: T[Seq[PathRef]] = T { | ||
val ws = T.workspace | ||
deferredSourceGenerators.flatMap(t => deferredSourceRoots(t)(ws)).map(PathRef(_)) | ||
} | ||
|
||
/** | ||
* Runs the lazy source generators, returning references to the expanded generated source roots | ||
* they are supposed to have written code in. | ||
*/ | ||
final def deferredGeneratedSources: T[Seq[PathRef]] = T { | ||
val ws = T.workspace | ||
T.sequence { | ||
deferredSourceGenerators.map { t => t.map((_: Unit) => deferredSourceRoots(t)) } | ||
}().flatMap(_.apply(ws)).map(PathRef(_)) | ||
} | ||
|
||
/** | ||
* Task that IDE-configuration tasks should rely on, as they avoid eagerly | ||
* running source generators referenced by [[deferredSourceGenerators]] | ||
*/ | ||
def ideSources: T[Seq[PathRef]] = | ||
Task { sources() ++ generatedSources() ++ allDeferredSourceRoots() } | ||
|
||
/** | ||
* 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 commentThe reason will be displayed to describe this comment to others. Learn more. Keeps the current (0.12.x) behaviour of |
||
|
||
/** | ||
* All individual source files fed into the Java compiler | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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