Skip to content

Commit

Permalink
Merge commit 'fetch_head' into mill-sc
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Sep 5, 2024
2 parents 4f271ad + 13567c0 commit 45264b1
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 13 deletions.
46 changes: 42 additions & 4 deletions bsp/worker/src/mill/bsp/worker/MillJvmBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import ch.epfl.scala.bsp4j.{
}
import mill.T
import mill.bsp.worker.Utils.sanitizeUri
import mill.scalalib.JavaModule
import mill.scalalib.api.CompilationResult
import mill.scalalib.{JavaModule, TestModule}

import java.util.concurrent.CompletableFuture
import scala.jdk.CollectionConverters._
Expand Down Expand Up @@ -50,6 +51,10 @@ private trait MillJvmBuildServer extends JvmBuildServer { this: MillBuildServer
targetIds = _ => targetIds,
tasks = {
case m: JavaModule =>
val moduleSpecificTask = m match {
case m: TestModule => m.getTestEnvironmentVars()
case _ => m.compile
}
T.task {
(
m.runClasspath(),
Expand All @@ -58,18 +63,51 @@ private trait MillJvmBuildServer extends JvmBuildServer { this: MillBuildServer
m.forkEnv(),
m.mainClass(),
m.zincWorker().worker(),
m.compile()
moduleSpecificTask()
)
}
}
) {
// We ignore all non-JavaModule
case (
ev,
state,
id,
_: TestModule with JavaModule,
(
_,
forkArgs,
forkWorkingDir,
forkEnv,
_,
_,
testEnvVars: (String, String, String, Seq[String])
)
) =>
val (mainClass, testRunnerClassPath, argsFile, classpath) = testEnvVars
val fullMainArgs: List[String] = List(testRunnerClassPath, argsFile)
val item = new JvmEnvironmentItem(
id,
classpath.asJava,
forkArgs.asJava,
forkWorkingDir.toString(),
forkEnv.asJava
)
item.setMainClasses(List(mainClass).map(new JvmMainClass(_, fullMainArgs.asJava)).asJava)
item
case (
ev,
state,
id,
_: JavaModule,
(runClasspath, forkArgs, forkWorkingDir, forkEnv, mainClass, zincWorker, compile)
(
runClasspath,
forkArgs,
forkWorkingDir,
forkEnv,
mainClass,
zincWorker,
compile: CompilationResult
)
) =>
val classpath = runClasspath.map(_.path).map(sanitizeUri)
val item = new JvmEnvironmentItem(
Expand Down
3 changes: 2 additions & 1 deletion docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* xref:Modules.adoc[]
* xref:Cross_Builds.adoc[]
* xref:Target_Query_Syntax.adoc[]
* xref:Structuring_Large_Builds.adoc[]
* xref:The_Mill_Evaluation_Model.adoc[]
Expand Down Expand Up @@ -72,6 +73,6 @@
// *somewhere*.
.Reference
* xref:Mill_Design_Principles.adoc[]
* xref:External_References.adoc[]
* xref:Bundled_Libraries.adoc[]
* {mill-doc-url}/api/latest/mill/index.html[Mill Scaladoc]
* xref:Changelog.adoc[]
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
= External References
= Bundled Libraries

:page-aliases: External_References.adoc

Mill comes bundled with a set of external Open Source libraries and projects.

Expand Down Expand Up @@ -39,7 +41,7 @@ ScalaDoc:: https://javadoc.io/doc/com.lihaoyi/requests_2.13/latest/index.html
MainArgs is a small, dependency-free library for command line argument parsing
in Scala.

Mill uses MainArgs to handle argument parsing for `T.command`s that are run
Mill uses MainArgs to handle argument parsing for ``T.command``s that are run
from the command line.

Project page:: https://github.com/com-lihaoyi/mainargs
Expand Down
7 changes: 4 additions & 3 deletions example/depth/large/11-helper-files/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ object `package` extends RootModule with MyModule{
"MY_PROJECT_VERSION" -> versions.myProjectVersion,
)
}
///** See Also: util.mill */
///** See Also: foo/package.mill */
///** See Also: foo/versions.mill */

/** See Also: util.mill */
/** See Also: foo/package.mill */
/** See Also: foo/versions.mill */


// Apart from having `package` files in subfolders to define modules, Mill
Expand Down
6 changes: 3 additions & 3 deletions example/depth/large/12-helper-files-sc/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ object `package` extends RootModule with MyModule{
"MY_PROJECT_VERSION" -> versions.myProjectVersion,
)
}
///** See Also: util.sc */
///** See Also: foo/package.sc */
///** See Also: foo/versions.sc */
/** See Also: util.sc */
/** See Also: foo/package.sc */
/** See Also: foo/versions.sc */


// To ease the migration from Mill 0.11.x, the older `.sc` file extension is also supported
Expand Down
40 changes: 40 additions & 0 deletions scalalib/src/mill/scalalib/TestModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ trait TestModule
testTask(T.task { args }, T.task { Seq.empty[String] })()
}

def getTestEnvironmentVars(args: String*): Command[(String, String, String, Seq[String])] = {
T.command {
getTestEnvironmentVarsTask(T.task { args })()
}
}

/**
* Args to be used by [[testCached]].
*/
Expand Down Expand Up @@ -124,6 +130,40 @@ trait TestModule
*/
def testReportXml: T[Option[String]] = T(Some("test-report.xml"))

/**
* Returns a Tuple where the first element is the main-class, second and third are main-class-arguments and the forth is classpath
*/
private def getTestEnvironmentVarsTask(args: Task[Seq[String]])
: Task[(String, String, String, Seq[String])] =
T.task {
val mainClass = "mill.testrunner.entrypoint.TestRunnerMain"
val outputPath = T.dest / "out.json"
val selectors = Seq.empty

val testArgs = TestArgs(
framework = testFramework(),
classpath = runClasspath().map(_.path),
arguments = args(),
sysProps = Map.empty,
outputPath = outputPath,
colored = T.log.colored,
testCp = testClasspath().map(_.path),
home = T.home,
globSelectors = selectors
)

val argsFile = T.dest / "testargs"
os.write(argsFile, upickle.default.write(testArgs))

val testRunnerClasspathArg =
zincWorker().scalalibClasspath()
.map(_.path.toNIO.toUri.toURL).mkString(",")

val cp = (runClasspath() ++ zincWorker().testrunnerEntrypointClasspath()).map(_.path.toString)

Result.Success((mainClass, testRunnerClasspathArg, argsFile.toString, cp))
}

/**
* Whether or not to use the test task destination folder as the working directory
* when running tests. `true` means test subprocess run in the `.dest/sandbox` folder of
Expand Down

0 comments on commit 45264b1

Please sign in to comment.