-
-
Notifications
You must be signed in to change notification settings - Fork 353
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
Move run
-targets into RunModule
#3090
Merged
Merged
Conversation
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
lefou
added a commit
that referenced
this pull request
Mar 20, 2024
This idea of this change is to restructure the `TestModule` to decouple it from the concept of compilation. After this change, only a `runClasspath` and a `testClasspath` is needed to run tests. This makes adding test modules for the sake of using a different test framework a breeze. See the following example: the `test2` module is an additional test framework on the same classes of `test`. ```scala import mill._ import mill.scalalib._ import mill.scalalib.api.CompilationResult object foo extends RootModule with ScalaModule { def scalaVersion = "2.13.11" def ivyDeps = Agg( ivy"com.lihaoyi::scalatags:0.12.0", ivy"com.lihaoyi::mainargs:0.6.2" ) object test extends ScalaTests { def ivyDeps = Agg( ivy"com.lihaoyi::utest:0.7.11", ivy"org.scalatest::scalatest-freespec:3.2.18" ) def testFramework = "utest.runner.Framework" } object test2 extends TestModule with TestModule.ScalaTest { override def compile: T[CompilationResult] = ??? override def runClasspath: T[Seq[PathRef]] = foo.test.runClasspath() override def testClasspath = foo.test.testClasspath() } } ``` Please note the `compile` target is a legacy to our binary-compatibility promise. The target is not used directly in `TestModule`. This pull request additionally contains the following changes: * Introduces a new `RunModule` and moved some `run`-related task previously in `TestModule` up. * Extend `RunModule` in `JavaModule` to share run-releated targets and resolve super-hierarchy * Introduces a `WithZincWorker` as a shared base trait to resolve super-hierarchies for using and overriding a common worker. I plan to move more run-releated target from `JavaModule` to `RunModule` in a subsequent PR. (See #3090) See also the following discussion: * #3076 Pull request: #3064
lefou
commented
Mar 20, 2024
lefou
changed the title
WIP Move
Move Mar 20, 2024
run
-targets into RunModule
run
-targets into RunModule
lihaoyi
approved these changes
Mar 26, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR moves the definition of the
run
targets fromJavaModule
intoRunModule
. Also some other targets where moved, e.g.mainClass
,finalMainClassOpt
andfinalMainClass
.The advantage of having them in
RunModule
is, that one can easily define and configure additional runners as sub-modules.Example: Define a
daemon
sub-module which acts as runner for thecli.DaemonTool
class.To preserve binary compatibility, all moved
def
s retain an override inJavaModule
and forward to theirsuper
-def
inRunModule
. Therefore traits compiled against older versions of traitJavaModule
should still be runnable with newer versions.Some
run
-targets (run
,runLocal
andrunBackground
) previously required thecompile
target, since that also provided some zinc analysis which included some main class discovery. Since the goal was to decouple therun
targets from the concept of compilation, I implemented a different discovery logic for main classes which uses the Scala API ofscalap
. This is completely newly written code but it's only a couple of lines and all existing tests (which also include main class discovery) succeeded. The advantage of the new logic is, that it should work with any given classpath and also for non-Scala classes. The new code is located in the zinc worker, since this is already shared between allRunModule
s, but there is no real need to have it there. To avoid increased complexity, I resisted to introduce a new shared worker just for the sake of technical independence, for now. The newallLocalMainClasses
target can be used to find all main classes in thelocalRunClasspath
. This is some useful information I needed now and then in projects, so it makes sense to have it in a dedicated target for better caching and easyshow
ing.I also introduced a new
localRunClasspath
target which abstracts away the classpath that is supposed to be produced by compilation. This is somewhat analogue to thetestClassapth
introdcued in PR #3064. Since both typically hold the same classpath,testClasspath
by default uses the result oflocalRunClasspath
. We probably could removetestClasspath
altogether, but it's semantically bound toTestModule
and isn't necessarily the same aslocalRunClasspath
, so I think it's legit to keep it.For consistency, I also added a
localCompileClasspath
which resembles the part of thelocalClasspath
which is feed into the compiler. All added classpath targets also have a version for BSP (named with prefixbsp
and returning aT[Agg[UnresolvedPath]]
) when appropriate.Depends on
TestModule
, addRunModule
#3064