summaryrefslogtreecommitdiff
path: root/scalalib
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-01-21 23:35:52 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-01-21 23:35:52 -0800
commit4a0658da074bc7b7df0c5bdff90e2c6bb1977b15 (patch)
tree59d077d40a7e96b419161f5b10cb17d326a51f9f /scalalib
parent3e80ade3249bc83b564d7b5bd31853c8affd555d (diff)
downloadmill-4a0658da074bc7b7df0c5bdff90e2c6bb1977b15.tar.gz
mill-4a0658da074bc7b7df0c5bdff90e2c6bb1977b15.tar.bz2
mill-4a0658da074bc7b7df0c5bdff90e2c6bb1977b15.zip
- Make `forkTest` and `forkRun` the default, renaming `test` and `run` to `testLocal` and `runLocal`
- Support passing `forkEnv` parameters to `test` and `run`, necessary to get Ammonite working - Standardize signatures of `Jvm.interactiveSubprocess`/`Jvm.subprocess` - `Jvm.inprocess` is now `Jvm.runLocal` - Swap `TestModule.testLocal` over to using `Jvm.runLocal`, for consistency with everything else
Diffstat (limited to 'scalalib')
-rw-r--r--scalalib/src/mill/scalalib/ScalaModule.scala65
-rw-r--r--scalalib/test/src/mill/scalalib/HelloWorldTests.scala8
2 files changed, 50 insertions, 23 deletions
diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala
index 975a5972..87bf119c 100644
--- a/scalalib/src/mill/scalalib/ScalaModule.scala
+++ b/scalalib/src/mill/scalalib/ScalaModule.scala
@@ -7,7 +7,7 @@ import mill.define.{Cross, Task}
import mill.define.TaskModule
import mill.eval.{PathRef, Result}
import mill.modules.Jvm
-import mill.modules.Jvm.{createAssembly, createJar, interactiveSubprocess, subprocess, inprocess}
+import mill.modules.Jvm.{createAssembly, createJar, interactiveSubprocess, subprocess, runLocal}
import Lib._
import mill.define.Cross.Resolver
import mill.util.Loose.Agg
@@ -205,7 +205,7 @@ trait ScalaModule extends mill.Module with TaskModule { outer =>
if (files.nonEmpty) subprocess(
"scala.tools.nsc.ScalaDoc",
compileDepClasspath().filter(_.path.ext != "pom").map(_.path),
- options = (files ++ options).toSeq
+ mainArgs = (files ++ options).toSeq
)
createJar(Agg(javadocDir))(outDir / "javadoc.jar")
@@ -217,38 +217,51 @@ trait ScalaModule extends mill.Module with TaskModule { outer =>
def forkArgs = T{ Seq.empty[String] }
+ def forkEnv = T{ sys.env.toMap }
- def run(args: String*) = T.command {
- inprocess(
+ def runLocal(args: String*) = T.command {
+ Jvm.runLocal(
mainClass().getOrElse(throw new RuntimeException("No mainClass provided!")),
runClasspath().map(_.path),
- args)
+ args
+ )
}
- def forkRun(args: String*) = T.command{
- subprocess(
+ def run(args: String*) = T.command{
+ Jvm.interactiveSubprocess(
mainClass().getOrElse(throw new RuntimeException("No mainClass provided!")),
runClasspath().map(_.path),
forkArgs(),
+ forkEnv(),
args,
workingDir = ammonite.ops.pwd)
}
+
+ def runMainLocal(mainClass: String, args: String*) = T.command {
+ Jvm.runLocal(
+ mainClass,
+ runClasspath().map(_.path),
+ args
+ )
+ }
+
def runMain(mainClass: String, args: String*) = T.command{
- subprocess(
+ Jvm.interactiveSubprocess(
mainClass,
runClasspath().map(_.path),
forkArgs(),
+ forkEnv(),
args,
workingDir = ammonite.ops.pwd
)
}
def console() = T.command{
- interactiveSubprocess(
+ Jvm.interactiveSubprocess(
mainClass = "scala.tools.nsc.MainGenericRunner",
classPath = runClasspath().map(_.path),
- options = Seq("-usejavacp")
+ mainArgs = Seq("-usejavacp")
)
}
@@ -282,15 +295,16 @@ trait TestModule extends ScalaModule with TaskModule {
def forkWorkingDir = ammonite.ops.pwd
- def forkTest(args: String*) = T.command{
+ def test(args: String*) = T.command{
mkdir(T.ctx().dest)
val outputPath = T.ctx().dest/"out.json"
Jvm.subprocess(
mainClass = "mill.scalalib.TestRunner",
classPath = Jvm.gatherClassloaderJars(),
- jvmOptions = forkArgs(),
- options = Seq(
+ jvmArgs = forkArgs(),
+ envArgs = forkEnv(),
+ mainArgs = Seq(
testFramework(),
runClasspath().map(_.path).mkString(" "),
Seq(compile().classes.path).mkString(" "),
@@ -306,13 +320,26 @@ trait TestModule extends ScalaModule with TaskModule {
TestModule.handleResults(doneMsg, results)
}
- def test(args: String*) = T.command{
- val (doneMsg, results) = TestRunner(
- testFramework(),
- runClasspath().map(_.path),
- Agg(compile().classes.path),
- args
+ def testLocal(args: String*) = T.command{
+ mkdir(T.ctx().dest)
+ val outputPath = T.ctx().dest/"out.json"
+
+ Jvm.runLocal(
+ mainClass = "mill.scalalib.TestRunner",
+ classPath = Jvm.gatherClassloaderJars(),
+ mainArgs = Seq(
+ testFramework(),
+ runClasspath().map(_.path).mkString(" "),
+ Seq(compile().classes.path).mkString(" "),
+ args.mkString(" "),
+ outputPath.toString,
+ T.ctx().log.colored.toString
+ )
)
+
+ val jsonOutput = upickle.json.read(outputPath.toIO)
+ val (doneMsg, results) = upickle.default.readJs[(String, Seq[TestRunner.Result])](jsonOutput)
TestModule.handleResults(doneMsg, results)
+
}
} \ No newline at end of file
diff --git a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala
index 8ac45bf3..1c22c578 100644
--- a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala
+++ b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala
@@ -267,7 +267,7 @@ object HelloWorldTests extends TestSuite {
'runIfMainClassProvided - {
val runResult = basePath / 'out / 'run / 'dest / "hello-mill"
val Right((_, evalCount)) = helloWorldWithMainEvaluator(
- HelloWorldWithMain.forkRun(runResult.toString)
+ HelloWorldWithMain.run(runResult.toString)
)
assert(evalCount > 0)
@@ -279,7 +279,7 @@ object HelloWorldTests extends TestSuite {
)
}
'notRunWithoutMainClass - {
- val Left(Result.Exception(err, _)) = helloWorldEvaluator(HelloWorld.forkRun())
+ val Left(Result.Exception(err, _)) = helloWorldEvaluator(HelloWorld.run())
assert(
err.isInstanceOf[RuntimeException]
@@ -290,7 +290,7 @@ object HelloWorldTests extends TestSuite {
'runIfMainClassProvided - {
val runResult = basePath / 'out / 'run / 'dest / "hello-mill"
val Right((_, evalCount)) = helloWorldWithMainEvaluator(
- HelloWorldWithMain.run(runResult.toString)
+ HelloWorldWithMain.runLocal(runResult.toString)
)
assert(evalCount > 0)
@@ -302,7 +302,7 @@ object HelloWorldTests extends TestSuite {
)
}
'notRunWithoutMainClass - {
- val Left(Result.Exception(err, _)) = helloWorldEvaluator(HelloWorld.run())
+ val Left(Result.Exception(err, _)) = helloWorldEvaluator(HelloWorld.runLocal())
assert(
err.isInstanceOf[RuntimeException]