-
-
Notifications
You must be signed in to change notification settings - Fork 347
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
Restructure TestModule
, add RunModule
#3064
Conversation
TestModule.testClasspath
to decouple from compilationTestModule
to make it independent of compilation
TestModule
to make it independent of compilationTestModule
, add RunModule
This should it make easier to define multiple test modules with differnt test frameworks on the same test classpath.
*/ | ||
def testClasspath: T[Seq[PathRef]] = T { | ||
// bin-compat-shim: keep the super.call in the classfile | ||
super.testClasspath |
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.
Calling super
here but without calling apply
, so even when not actual using the super-target here (we don't insert a real dependency to the super-target), we ensure the super
-reference is generated in the byte-code. This allows us later to use the super-target without worrying about binary compatibility.
This is some new pattern I want to try out and establish. If it works out, we could automate it in the T
-macros.
See for more details:
Looks good to me. I've needed this before: apart from the testFramework use case discussed earlier, I've needed to share the same compiled code but testing it with different flags or environment variables. It's possible to do today with a bunch of |
That's probably even better covered by my other subsequent PR which is in the making: It's exactly for the case, when you want run with different flags, envs, or main classes or classpaths. |
This PR moves the definition of the `run` targets from `JavaModule` into `RunModule`. Also some other targets where moved, e.g. `mainClass`, `finalMainClassOpt` and `finalMainClass`. 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 the `cli.DaemonTool` class. ```scala import mill._, scalalib._ object foo extends RootModule with JavaModule { def mainClass = "cli.Main" object daemon extends RunModule { def runClasspath = foo.runClasspath def localRunClasspath = foo.localRunClasspath def mainClass = "cli.DaemonTool" } } ``` To preserve binary compatibility, all moved `def`s retain an override in `JavaModule` and forward to their `super`-`def` in `RunModule`. Therefore traits compiled against older versions of trait `JavaModule` should still be runnable with newer versions. Some `run`-targets (`run`, `runLocal` and `runBackground`) previously required the `compile` target, since that also provided some zinc analysis which included some main class discovery. Since the goal was to decouple the `run` targets from the concept of compilation, I implemented a different discovery logic for main classes which uses the Scala API of `scalap`. 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 all `RunModule`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 new `allLocalMainClasses` target can be used to find all main classes in the `localRunClasspath`. 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 easy `show`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 the `testClassapth` introdcued in PR #3064. Since both typically hold the same classpath, `testClasspath` by default uses the result of `localRunClasspath`. We probably could remove `testClasspath` altogether, but it's semantically bound to `TestModule` and isn't necessarily the same as `localRunClasspath`, so I think it's legit to keep it. For consistency, I also added a `localCompileClasspath` which resembles the part of the `localClasspath` which is feed into the compiler. All added classpath targets also have a version for BSP (named with prefix `bsp` and returning a `T[Agg[UnresolvedPath]]`) when appropriate. Pull request: #3090
in case someone else trying out similar setup, in IJ you also need |
Nice catch, @chikei ! That was probably an oversight. Can you show your complete example? I wonder why the |
Honestly I am not really sure if tweaking As for |
We currently don't check the
Ok. So I think if you stay with the simple example from this PR, If you extends from an real language module like |
So I tried defining additional test without an real language module, this line in mill will throw a MatchError as the additional test module does not inherent |
This is in fact a bug. I opened #3110 to track it. |
So with PR #3111, I can make IJ import without error, but build project will fail as mill return Skimming through IJ's BSP code, my understanding is that IJ ignores |
@chikei Thanks for the feedback. |
This idea of this change is to restructure the
TestModule
to decouple it from the concept of compilation. After this change, only arunClasspath
and atestClasspath
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 oftest
.Please note the
compile
target is a legacy to our binary-compatibility promise. The target is not used directly inTestModule
.This pull request additionally contains the following changes:
RunModule
and moved somerun
-related task previously inTestModule
up.RunModule
inJavaModule
to share run-releated targets and resolve super-hierarchyWithZincWorker
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
toRunModule
in a subsequent PR. (See #3090)See also the following discussion: