summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2017-11-25 12:34:40 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2017-11-25 12:34:40 -0800
commitf98a88f898f8de10c5145a13792151663f424518 (patch)
tree4ee797baf8f268dd2772b5c2734c93e96d7871ed
parent2c0ecb9733dfd231c8d16b819d89d515569f104c (diff)
downloadmill-f98a88f898f8de10c5145a13792151663f424518.tar.gz
mill-f98a88f898f8de10c5145a13792151663f424518.tar.bz2
mill-f98a88f898f8de10c5145a13792151663f424518.zip
Streamline cross-build Scala syntax to avoid the unnecessary `List(...)` wrapper
-rw-r--r--core/src/main/scala/mill/define/Cross.scala16
-rw-r--r--core/src/main/scala/mill/discover/Discovered.scala2
-rw-r--r--core/src/test/scala/mill/discover/CrossModuleTests.scala18
-rw-r--r--core/src/test/scala/mill/main/MainTests.scala8
-rw-r--r--readme.md24
5 files changed, 48 insertions, 20 deletions
diff --git a/core/src/main/scala/mill/define/Cross.scala b/core/src/main/scala/mill/define/Cross.scala
index ac1ee966..85341d12 100644
--- a/core/src/main/scala/mill/define/Cross.scala
+++ b/core/src/main/scala/mill/define/Cross.scala
@@ -9,10 +9,18 @@ case class Cross[+T](items: List[(List[Any], T)]){
def map[V](f: T => V): Cross[V] = new Cross(items.map{case (l, v) => (l, f(v))})
def withFilter(f: T => Boolean): Cross[T] = new Cross(items.filter(t => f(t._2)))
- def applyOpt(input: List[Any]): Option[T] = items.find(_._1 == input).map(_._2)
- def apply(input: List[Any]): T = applyOpt(input).getOrElse(
- throw new Exception("Unknown set of cross values: " + input + " not in known values\n" + items.map(_._1).mkString("\n"))
- )
+ def applyOpt(input: Any*): Option[T] = {
+ val inputList = input.toList
+ items.find(_._1 == inputList).map(_._2)
+ }
+ def apply(input: Any*): T = {
+ applyOpt(input:_*).getOrElse(
+ throw new Exception(
+ "Unknown set of cross values: " + input +
+ " not in known values\n" + items.map(_._1).mkString("\n")
+ )
+ )
+ }
}
object Cross{
def apply[T](t: T*) = new Cross(t.map(i => List(i) -> i).toList)
diff --git a/core/src/main/scala/mill/discover/Discovered.scala b/core/src/main/scala/mill/discover/Discovered.scala
index 36ec49b7..6bed7919 100644
--- a/core/src/main/scala/mill/discover/Discovered.scala
+++ b/core/src/main/scala/mill/discover/Discovered.scala
@@ -82,7 +82,7 @@ object Discovered {
val base = q"${TermName(c.freshName())}"
val ident = segments.reverse.zipWithIndex.foldLeft[Tree](base) {
case (prefix, (Some(name), i)) => q"$prefix.${TermName(name)}"
- case (prefix, (None, i)) => q"$prefix.apply($crossName($i))"
+ case (prefix, (None, i)) => q"$prefix.apply($crossName($i):_*)"
}
q"($base: $tpe, $crossName: List[List[Any]]) => $ident"
}
diff --git a/core/src/test/scala/mill/discover/CrossModuleTests.scala b/core/src/test/scala/mill/discover/CrossModuleTests.scala
index c426d126..6c328a7e 100644
--- a/core/src/test/scala/mill/discover/CrossModuleTests.scala
+++ b/core/src/test/scala/mill/discover/CrossModuleTests.scala
@@ -31,7 +31,7 @@ object CrossModuleTests extends TestSuite{
val keys = gen(outer.crossed)
assert(keys == List(List("2.10.6"), List("2.11.8"), List("2.12.4")))
for(k <- keys){
- assert(outer.crossed(k).scalaVersion == k.head)
+ assert(outer.crossed(k:_*).scalaVersion == k.head)
}
}
'doubleCross - {
@@ -67,7 +67,7 @@ object CrossModuleTests extends TestSuite{
assert(keys == expectedKeys)
for(k <- keys){
- val suffix = outer.crossed(k).suffix
+ val suffix = outer.crossed(k:_*).suffix
val expected = k.map(_.toString).filter(_.nonEmpty).map("_"+_).mkString
assert(suffix == expected)
}
@@ -89,9 +89,9 @@ object CrossModuleTests extends TestSuite{
assert(segments == expectedSegments)
val targets = discovered.targets(outer).map(_.target)
val expected = List(
- outer.crossed(List("2.10.6")).scalaVersion,
- outer.crossed(List("2.11.8")).scalaVersion,
- outer.crossed(List("2.12.4")).scalaVersion
+ outer.crossed("2.10.6").scalaVersion,
+ outer.crossed("2.11.8").scalaVersion,
+ outer.crossed("2.12.4").scalaVersion
)
assert(targets == expected)
}
@@ -108,10 +108,10 @@ object CrossModuleTests extends TestSuite{
val targets = discovered.targets(outer).map(_.target)
val expected = List(
- outer.crossed(List("sjs0.6", "2.11.8")).suffix,
- outer.crossed(List("native0.3", "2.11.8")).suffix,
- outer.crossed(List("sjs0.6", "2.12.4")).suffix,
- outer.crossed(List("native0.3", "2.12.4")).suffix
+ outer.crossed("sjs0.6", "2.11.8").suffix,
+ outer.crossed("native0.3", "2.11.8").suffix,
+ outer.crossed("sjs0.6", "2.12.4").suffix,
+ outer.crossed("native0.3", "2.12.4").suffix
)
assert(targets == expected)
}
diff --git a/core/src/test/scala/mill/main/MainTests.scala b/core/src/test/scala/mill/main/MainTests.scala
index c0030e25..b9f2020f 100644
--- a/core/src/test/scala/mill/main/MainTests.scala
+++ b/core/src/test/scala/mill/main/MainTests.scala
@@ -55,8 +55,8 @@ object MainTests extends TestSuite{
val target = test()
}
}
- 'pos1 - check(outer, "cross[jarA].target", Right(outer.cross(List("jarA")).target))
- 'pos2 - check(outer, "cross[jarB].target", Right(outer.cross(List("jarB")).target))
+ 'pos1 - check(outer, "cross[jarA].target", Right(outer.cross("jarA").target))
+ 'pos2 - check(outer, "cross[jarB].target", Right(outer.cross("jarB").target))
'neg1 - check(outer, "cross[jarA].doesntExist", Left("Cannot resolve task cross[jarA].doesntExist"))
// 'neg2 - check(outer, "cross[doesntExist].doesntExist", Left("Cannot resolve cross cross[doesntExist]"))
// 'neg2 - check(outer, "cross[doesntExist].target", Left("Cannot resolve cross cross[doesntExist]"))
@@ -74,12 +74,12 @@ object MainTests extends TestSuite{
'pos1 - check(
outer,
"cross[jvm,jarA].target",
- Right(outer.cross(List("jvm", "jarA")).target)
+ Right(outer.cross("jvm", "jarA").target)
)
'pos2 - check(
outer,
"cross[jvm,jarB].target",
- Right(outer.cross(List("jvm", "jarB")).target)
+ Right(outer.cross("jvm", "jarB").target)
)
}
'nested - {
diff --git a/readme.md b/readme.md
index 23a1bff0..ee735f13 100644
--- a/readme.md
+++ b/readme.md
@@ -56,6 +56,27 @@ Within each `Module` you can define 3 type of task:
- `Task`: take arguments, output is not cached; do not run from `bash` (e.g.
`def foo = T.task{...}` )
+### Self Hosting
+
+You can use SBT to build a Mill executable, which itself is able to build more
+Mill executables that can you can use to run Mill commands:
+
+```bash
+git clean -xdf
+
+# Build Mill executable using SBT
+sbt scalaplugin/test:assembly
+
+# Build Mill executable using the Mill executable generated by SBT
+scalaplugin/target/mill run Core.assembly
+
+# Build Mill executable using the Mill executable generated by Mill itself
+out/ScalaPlugin/assembly run Core.assembly
+```
+
+Eventually, as Mill stabilizes, we will get rid of the SBT build entirely and
+rely on previous versions of Mill to build itself.
+
### Troubleshooting
In case of troubles with caching and/or incremental compilation, you can always
@@ -98,8 +119,7 @@ able to run it.
Cross builds, using the `Cross` data structure, are just another kind of node in
the object hierarchy. The only difference is syntax: from the command line you'd
run something via `mill run Core.cross[a].printIt` while from code you use
-`Core.cross(List("a")).printIt` due to different restrictions in Scala/Bash
-syntax.
+`Core.cross("a").printIt` due to different restrictions in Scala/Bash syntax.
### Caching by default