summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.sbt8
-rwxr-xr-xbuild.sc93
-rw-r--r--core/src/main/scala/mill/Main.scala103
-rw-r--r--scalaplugin/src/main/scala/mill/scalaplugin/Main.scala7
4 files changed, 147 insertions, 64 deletions
diff --git a/build.sbt b/build.sbt
index e88b5a90..4cccc499 100644
--- a/build.sbt
+++ b/build.sbt
@@ -14,7 +14,13 @@ val sharedSettings = Seq(
Seq("#!/usr/bin/env sh", """exec java -jar -Xmx500m -XX:+UseG1GC $JAVA_OPTS "$0" "$@"""")
)
),
-
+ assembly in Test := {
+ val dest = target.value/"mill"
+ IO.copyFile(assembly.value, dest)
+ import sys.process._
+ Seq("chmod", "+x", dest.getAbsolutePath).!
+ dest
+ },
libraryDependencies += "com.lihaoyi" %% "acyclic" % "0.1.7" % "provided",
scalacOptions += "-P:acyclic:force",
autoCompilerPlugins := true,
diff --git a/build.sc b/build.sc
index c6f0dab1..9a7928e0 100755
--- a/build.sc
+++ b/build.sc
@@ -1,56 +1,47 @@
-#!/usr/bin/env amm
-//import $cp.out.ScalaPlugin.assembly
-import $cp.scalaplugin.target.`scala-2.12`.`mill-scalaplugin-assembly-0.1-SNAPSHOT.jar`
-import ammonite.ops.pwd
+import ammonite.ops._
import mill._
-import mill.scalaplugin.{Module, Dep, TestRunner}
-
-@main def run(args: String*) = mill.Main(args, Build, interp.watch)
-
-@main def idea() = mill.scalaplugin.GenIdea(Build)
-object Build{
- object Core extends Module {
- def scalaVersion = "2.12.4"
- override def compileIvyDeps = Seq(
- Dep.Java("org.scala-lang", "scala-reflect", scalaVersion())
- )
-
- override def ivyDeps = Seq(
- Dep("com.lihaoyi", "sourcecode", "0.1.4"),
- Dep("com.lihaoyi", "pprint", "0.5.3"),
- Dep.Point("com.lihaoyi", "ammonite", "1.0.3"),
- Dep("com.typesafe.play", "play-json", "2.6.6"),
- Dep("org.scala-sbt", "zinc", "1.0.3"),
- Dep.Java("org.scala-sbt", "test-interface", "1.0")
- )
-
- def basePath = pwd / 'core
- override def sources = pwd/'core/'src/'main/'scala
- }
- object CoreTests extends Module {
- def scalaVersion = "2.12.4"
- override def projectDeps = Seq(Core)
- def basePath = pwd / 'scalaplugin
- override def sources = pwd/'core/'src/'test/'scala
- override def ivyDeps = Seq(
- Dep("com.lihaoyi", "utest", "0.6.0")
+import mill.scalaplugin._
+
+
+object Core extends Module {
+ def scalaVersion = "2.12.4"
+ override def compileIvyDeps = Seq(
+ Dep.Java("org.scala-lang", "scala-reflect", scalaVersion())
+ )
+
+ override def ivyDeps = Seq(
+ Dep("com.lihaoyi", "sourcecode", "0.1.4"),
+ Dep("com.lihaoyi", "pprint", "0.5.3"),
+ Dep.Point("com.lihaoyi", "ammonite", "1.0.3"),
+ Dep("com.typesafe.play", "play-json", "2.6.6"),
+ Dep("org.scala-sbt", "zinc", "1.0.3"),
+ Dep.Java("org.scala-sbt", "test-interface", "1.0")
+ )
+
+ def basePath = pwd / 'core
+ override def sources = pwd/'core/'src/'main/'scala
+}
+object CoreTests extends Module {
+ def scalaVersion = "2.12.4"
+ override def projectDeps = Seq(Core)
+ def basePath = pwd / 'scalaplugin
+ override def sources = pwd/'core/'src/'test/'scala
+ override def ivyDeps = Seq(
+ Dep("com.lihaoyi", "utest", "0.6.0")
+ )
+
+ def test() = T.command{
+ TestRunner.apply(
+ "mill.UTestFramework",
+ runDepClasspath().map(_.path) :+ compile().path,
+ Seq(compile().path)
)
-
- def test() = T.command{
- TestRunner.apply(
- "mill.UTestFramework",
- runDepClasspath().map(_.path) :+ compile().path,
- Seq(compile().path)
- )
- }
- }
-
- object ScalaPlugin extends Module {
- def scalaVersion = "2.12.4"
- override def projectDeps = Seq(Core)
- def basePath = pwd / 'scalaplugin
- override def sources = pwd/'scalaplugin/'src/'main/'scala
}
}
-
+object ScalaPlugin extends Module {
+ def scalaVersion = "2.12.4"
+ override def projectDeps = Seq(Core)
+ def basePath = pwd / 'scalaplugin
+ override def sources = pwd/'scalaplugin/'src/'main/'scala
+} \ No newline at end of file
diff --git a/core/src/main/scala/mill/Main.scala b/core/src/main/scala/mill/Main.scala
index 9a3ade04..87395113 100644
--- a/core/src/main/scala/mill/Main.scala
+++ b/core/src/main/scala/mill/Main.scala
@@ -1,14 +1,18 @@
package mill
+import ammonite.Main
+import ammonite.main.Scripts
import ammonite.ops._
-import ammonite.util.{Name, Res}
+import ammonite.util.{Colors, Name, Res}
import mill.define.Task
import mill.discover._
import mill.eval.Evaluator
import mill.util.OSet
import play.api.libs.json.Format
-
+import scala.annotation.tailrec
+import ammonite.main.Scripts.pathScoptRead
+import ammonite.repl.Repl
object Main {
def apply[T: Discovered](args: Seq[String], obj: T, watch: Path => Unit) = {
val startTime = System.currentTimeMillis()
@@ -58,21 +62,96 @@ object Main {
def main(args: Array[String]): Unit = {
+ case class Config(home: ammonite.ops.Path = pwd/'out/'ammonite,
+ colored: Option[Boolean] = None,
+ help: Boolean = false,
+ repl: Boolean = false,
+ watch: Boolean = false)
+ import ammonite.main.Cli.Arg
+ val signature = Seq(
+ Arg[Config, Path](
+ "home", Some('h'),
+ "The home directory of the REPL; where it looks for config and caches",
+ (c, v) => c.copy(home = v)
+ ),
+ Arg[Config, Unit](
+ "help", None,
+ """Print this message""".stripMargin,
+ (c, v) => c.copy(help = true)
+ ),
+ Arg[Config, Boolean](
+ "color", None,
+ """Enable or disable colored output; by default colors are enabled
+ |in both REPL and scripts if the console is interactive, and disabled
+ |otherwise""".stripMargin,
+ (c, v) => c.copy(colored = Some(v))
+ ),
+ Arg[Config, Unit](
+ "repl", Some('r'),
+ "Open a build REPL",
+ (c, v) => c.copy(repl = true)
+ ),
+ Arg[Config, Unit](
+ "watch", Some('w'),
+ "Watch and re-run your build when it changes",
+ (c, v) => c.copy(watch = true)
+ )
+ )
+ ammonite.main.Cli.groupArgs(args.toList, signature, Config()) match{
+ case Left(err) =>
+ case Right((config, leftover)) =>
+ if (config.help){
+ val leftMargin = signature.map(ammonite.main.Cli.showArg(_).length).max + 2
+ println(ammonite.main.Cli.formatBlock(signature, leftMargin).mkString("\n"))
+ }else if (config.repl){
+ val repl = ammonite.Main(
+ predefFile = Some(pwd/"build.sc")
+ ).instantiateRepl(remoteLogger = None)
+ repl.right.get.interp.initializePredef()
+ repl.right.get.run()
+ }else {
+ val interp = ammonite.Main(
+ predefFile = Some(pwd/"build.sc")
+ ).instantiateInterpreter()
- val List(buildFile, rest @_*) = args.toList
-
- ammonite.Main().instantiateInterpreter() match{
- case Left(problems) => pprint.log(problems)
- case Right(interp) =>
- val result = ammonite.main.Scripts.runScript(pwd, Path(buildFile, pwd), interp, Nil)
+ interp.right.get.initializePredef()
+ val syntheticPath = pwd/'out/"run.sc"
+ write.over(
+ syntheticPath,
+ """@main def run(args: String*) = mill.Main(args, ammonite.predef.FilePredef, interp.watch)
+ |
+ |@main def idea() = mill.scalaplugin.GenIdea(ammonite.predef.FilePredef)
+ """.stripMargin
+ )
- if (!result.isSuccess) println(result)
- else{
- val (obj, discovered) = result.asInstanceOf[Res.Success[(Any, Discovered[Any])]].s
- apply(rest, obj, _ => ())(discovered)
+ val res = ammonite.main.Scripts.runScript(
+ pwd,
+ syntheticPath,
+ interp.right.get,
+ Scripts.groupArgs(leftover)
+ )
+ handleWatchRes(res, true)
}
}
}
+ def handleWatchRes[T](res: Res[T], printing: Boolean) = {
+ val success = res match {
+ case Res.Failure(msg) =>
+ println(msg)
+ false
+ case Res.Exception(ex, s) =>
+ println(
+ Repl.showException(ex, fansi.Color.Red, fansi.Attr.Reset, fansi.Color.Green)
+ )
+ false
+
+ case Res.Success(value) =>
+ if (printing && value != ()) println(pprint.PPrinter.BlackWhite(value))
+ true
+ case Res.Skip => true // do nothing on success, everything's already happened
+ }
+ success
+ }
}
diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/Main.scala b/scalaplugin/src/main/scala/mill/scalaplugin/Main.scala
new file mode 100644
index 00000000..c54430e7
--- /dev/null
+++ b/scalaplugin/src/main/scala/mill/scalaplugin/Main.scala
@@ -0,0 +1,7 @@
+package mill.scalaplugin
+
+object Main {
+ def main(args: Array[String]): Unit = {
+ mill.Main.main(args)
+ }
+}