summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.sbt10
-rwxr-xr-xbuild.sc4
-rw-r--r--integration/test/resources/upickle/build.sc148
-rw-r--r--integration/test/src/mill/integration/UpickleTests.scala23
4 files changed, 182 insertions, 3 deletions
diff --git a/build.sbt b/build.sbt
index 403d036f..940ca96f 100644
--- a/build.sbt
+++ b/build.sbt
@@ -227,6 +227,11 @@ val testRepos = Map(
resourceManaged in test,
List("shared.sc", "downloadTestRepo", "lihaoyi/ammonite", "96ea548d5e3b72ab6ad4d9765e205bf6cc1c82ac", _),
suffix = "ammonite"
+ ),
+ "MILL_UPICKLE_REPO" -> ammoniteRun(
+ resourceManaged in test,
+ List("shared.sc", "downloadTestRepo", "lihaoyi/upickle", "7f33085c890db7550a226c349832eabc3cd18769", _),
+ suffix = "upickle"
)
)
@@ -242,9 +247,10 @@ lazy val integration = project
"MILL_ACYCLIC_REPO" -> testRepos("MILL_ACYCLIC_REPO").value,
"MILL_AMMONITE_REPO" -> testRepos("MILL_AMMONITE_REPO").value,
"MILL_JAWN_REPO" -> testRepos("MILL_JAWN_REPO").value,
- "MILL_BETTERFILES_REPO" -> testRepos("MILL_BETTERFILES_REPO").value
+ "MILL_BETTERFILES_REPO" -> testRepos("MILL_BETTERFILES_REPO").value,
+ "MILL_UPICKLE_REPO" -> testRepos("MILL_UPICKLE_REPO").value
)
- scalaWorkerProps.value ++ (for((k, v) <- kvs) yield s"-D$k=$v")
+ jsbridgeProps.value.toSeq ++ scalaWorkerProps.value ++ (for((k, v) <- kvs) yield s"-D$k=$v")
}
)
diff --git a/build.sc b/build.sc
index e862683c..103b1cea 100755
--- a/build.sc
+++ b/build.sc
@@ -175,7 +175,9 @@ def testRepos = T{
"MILL_BETTERFILES_REPO" ->
shared.downloadTestRepo("pathikrit/better-files", "ba74ae9ef784dcf37f1b22c3990037a4fcc6b5f8", T.ctx().dest/"better-files"),
"MILL_AMMONITE_REPO" ->
- shared.downloadTestRepo("lihaoyi/ammonite", "96ea548d5e3b72ab6ad4d9765e205bf6cc1c82ac", T.ctx().dest/"ammonite")
+ shared.downloadTestRepo("lihaoyi/ammonite", "96ea548d5e3b72ab6ad4d9765e205bf6cc1c82ac", T.ctx().dest/"ammonite"),
+ "MILL_UPICKLE_REPO" ->
+ shared.downloadTestRepo("lihaoyi/upickle", "7f33085c890db7550a226c349832eabc3cd18769", T.ctx().dest/"upickle")
)
}
diff --git a/integration/test/resources/upickle/build.sc b/integration/test/resources/upickle/build.sc
new file mode 100644
index 00000000..39742562
--- /dev/null
+++ b/integration/test/resources/upickle/build.sc
@@ -0,0 +1,148 @@
+import mill._, mill.scalalib._, mill.scalalib.publish._, mill.scalajslib._
+
+
+trait UpickleModule extends CrossSbtModule with PublishModule{
+
+ def millSourcePath = build.millSourcePath / "upickle"
+
+ def artifactName = "mill-" + super.artifactName()
+ def publishVersion = "0.5.1"
+
+ def pomSettings = PomSettings(
+ description = artifactName(),
+ organization = "com.lihaoyi",
+ url = "https://github.com/lihaoyi/upickle",
+ licenses = Seq(
+ License("MIT license", "http://www.opensource.org/licenses/mit-license.php")
+ ),
+ scm = SCM(
+ "git://github.com/lihaoyi/upickle.git",
+ "scm:git://github.com/lihaoyi/upickle.git"
+ ),
+ developers = Seq(
+ Developer("lihaoyi", "Li Haoyi","https://github.com/lihaoyi")
+ )
+ )
+ def scalacPluginIvyDeps = super.scalacPluginIvyDeps() ++ Agg(
+ ivy"com.lihaoyi::acyclic:0.1.5"
+ )
+ def compileIvyDeps = Agg(
+ ivy"com.lihaoyi::acyclic:0.1.5",
+ ivy"org.scala-lang:scala-reflect:${scalaVersion()}",
+ ivy"org.scala-lang:scala-compiler:${scalaVersion()}"
+ )
+ def ivyDeps = Agg(
+ ivy"com.lihaoyi::sourcecode::0.1.3"
+ )
+ def scalacOptions = Seq("-unchecked",
+ "-deprecation",
+ "-encoding", "utf8",
+ "-feature"
+ )
+
+ def sources = T.sources(
+ millSourcePath / platformSegment / "src" / "main",
+ millSourcePath / "shared" / "src" / "main"
+ )
+
+ def generatedSources = T{
+ val dir = T.ctx().dest
+ val file = dir / "upickle" / "Generated.scala"
+ ammonite.ops.mkdir(dir / "upickle")
+ val tuplesAndCases = (1 to 22).map{ i =>
+ def commaSeparated(s: Int => String) = (1 to i).map(s).mkString(", ")
+ val writerTypes = commaSeparated(j => s"T$j: Writer")
+ val readerTypes = commaSeparated(j => s"T$j: Reader")
+ val typeTuple = commaSeparated(j => s"T$j")
+ val written = commaSeparated(j => s"writeJs(x._$j)")
+ val pattern = commaSeparated(j => s"x$j")
+ val read = commaSeparated(j => s"readJs[T$j](x$j)")
+ val caseReader =
+ if(i == 1) s"f(readJs[Tuple1[T1]](x)._1)"
+ else s"f.tupled(readJs[Tuple$i[$typeTuple]](x))"
+ (s"""
+ implicit def Tuple${i}W[$writerTypes] = makeWriter[Tuple${i}[$typeTuple]](
+ x => Js.Arr($written)
+ )
+ implicit def Tuple${i}R[$readerTypes] = makeReader[Tuple${i}[$typeTuple]](
+ validate("Array(${i})"){case Js.Arr($pattern) => Tuple${i}($read)}
+ )
+ """, s"""
+ def Case${i}R[$readerTypes, V]
+ (f: ($typeTuple) => V, names: Array[String], defaults: Array[Js.Value])
+ = RCase[V](names, defaults, {case x => $caseReader})
+ def Case${i}W[$writerTypes, V]
+ (g: V => Option[Tuple${i}[$typeTuple]], names: Array[String], defaults: Array[Js.Value])
+ = WCase[V](names, defaults, x => writeJs(g(x).get))
+ """)
+ }
+ val (tuples, cases) = tuplesAndCases.unzip
+ ammonite.ops.write(file, s"""
+ package upickle
+ import acyclic.file
+ import language.experimental.macros
+ /**
+ * Auto-generated picklers and unpicklers, used for creating the 22
+ * versions of tuple-picklers and case-class picklers
+ */
+ trait Generated extends GeneratedUtil{
+ ${tuples.mkString("\n")}
+ }
+ """)
+ Seq(PathRef(dir))
+ }
+
+ def platformSegment: String
+}
+
+trait UpickleTestModule extends TestModule{
+ def platformSegment: String
+
+ def ivyDeps = Agg(
+ ivy"com.lihaoyi::utest::0.5.4",
+ ivy"com.lihaoyi::acyclic:0.1.5"
+ )
+
+ def sources = T.sources(
+ millSourcePath / platformSegment / "src" / "test",
+ millSourcePath / "shared" / "src" / "test"
+ )
+ def testFramework = "utest.runner.Framework"
+}
+
+object upickleJvm extends Cross[UpickleJvmModule]("2.11.11", "2.12.4")
+class UpickleJvmModule(val crossScalaVersion: String) extends UpickleModule{
+ def platformSegment = "jvm"
+
+ def ivyDeps = T{
+ super.ivyDeps() ++ Seq(ivy"org.spire-math::jawn-parser:0.11.0")
+ }
+ object test extends Tests with UpickleTestModule{
+ def platformSegment = "js"
+ def millSourcePath = build.millSourcePath / "upickle"
+ }
+}
+
+object upickleJs extends Cross[UpickleJsModule]("2.11.11", "2.12.4")
+class UpickleJsModule(val crossScalaVersion: String) extends UpickleModule with ScalaJSModule {
+ def platformSegment = "js"
+
+ def scalaJSVersion = "0.6.22"
+ def scalacOptions = T{
+ super.scalacOptions() ++ Seq({
+ val a = build.millSourcePath.toString.replaceFirst("[^/]+/?$", "")
+ val g = "https://raw.githubusercontent.com/lihaoyi/upickle"
+ s"-P:scalajs:mapSourceURI:$a->$g/v${publishVersion()}/"
+ })
+ }
+ object test extends Tests with UpickleTestModule{
+ def platformSegment = "js"
+ def millSourcePath = build.millSourcePath / "upickle"
+ }
+}
+
+object test extends ScalaModule{
+ def scalaVersion = "2.12.4"
+ def moduleDeps = Seq(upickleJvm("2.12.4"))
+ def sources = T.sources{millSourcePath}
+}
diff --git a/integration/test/src/mill/integration/UpickleTests.scala b/integration/test/src/mill/integration/UpickleTests.scala
new file mode 100644
index 00000000..7c6778ad
--- /dev/null
+++ b/integration/test/src/mill/integration/UpickleTests.scala
@@ -0,0 +1,23 @@
+package mill.integration
+
+import ammonite.ops._
+import utest._
+
+object UpickleTests extends IntegrationTestSuite("MILL_UPICKLE_REPO", "upickle") {
+ val tests = Tests{
+ initWorkspace()
+ 'test - {
+ assert(eval("upickleJvm[2.11.11].test"))
+ assert(eval("upickleJs[2.12.4].test"))
+
+ val jvmMeta = meta("upickleJvm[2.11.11].test.test")
+ assert(jvmMeta.contains("example.ExampleTests.simple"))
+ assert(jvmMeta.contains("upickle.MacroTests.commonCustomStructures.simpleAdt"))
+
+ val jsMeta = meta("upickleJs[2.12.4].test.test")
+ assert(jsMeta .contains("example.ExampleTests.simple"))
+ assert(jsMeta .contains("upickle.MacroTests.commonCustomStructures.simpleAdt"))
+ }
+
+ }
+}