From 2bd2fd997d8898e07d14f23d344008e5a5d9a7a0 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Mon, 16 Sep 2019 11:08:15 +0800 Subject: cross-build cask.util for Scala.js --- build.sc | 52 ++++++++++++++++++++++++-------- cask/src/cask/util/BatchActor.scala | 40 ------------------------ cask/src/cask/util/Logger.scala | 18 ----------- cask/util/src/cask/util/BatchActor.scala | 40 ++++++++++++++++++++++++ cask/util/src/cask/util/Logger.scala | 18 +++++++++++ 5 files changed, 98 insertions(+), 70 deletions(-) delete mode 100644 cask/src/cask/util/BatchActor.scala delete mode 100644 cask/src/cask/util/Logger.scala create mode 100644 cask/util/src/cask/util/BatchActor.scala create mode 100644 cask/util/src/cask/util/Logger.scala diff --git a/build.sc b/build.sc index 926f049..834f1bf 100644 --- a/build.sc +++ b/build.sc @@ -1,4 +1,4 @@ -import mill._, scalalib._, publish._ +import mill._, scalalib._, scalajslib._, publish._ import $file.ci.upload, $file.ci.version import $file.example.compress.build @@ -23,18 +23,8 @@ import $file.example.variableRoutes.build import $file.example.websockets.build import $file.example.websockets2.build -object cask extends ScalaModule with PublishModule { +trait CaskModule extends ScalaModule with PublishModule{ def scalaVersion = "2.13.0" - def ivyDeps = Agg( - ivy"org.scala-lang:scala-reflect:${scalaVersion()}", - ivy"io.undertow:undertow-core:2.0.13.Final", - ivy"com.lihaoyi::upickle:0.7.5", - ivy"com.lihaoyi::sourcecode:0.1.7", - ivy"com.lihaoyi::pprint:0.5.5" - ) - def compileIvyDeps = Agg(ivy"com.lihaoyi::acyclic:0.2.0") - def scalacOptions = Seq("-P:acyclic:force") - def scalacPluginIvyDeps = Agg(ivy"com.lihaoyi::acyclic:0.2.0") def publishVersion = build.publishVersion()._2 @@ -48,6 +38,44 @@ object cask extends ScalaModule with PublishModule { Developer("lihaoyi", "Li Haoyi","https://github.com/lihaoyi") ) ) +} + +object cask extends CaskModule { + def moduleDeps = Seq(util.jvm) + + def ivyDeps = Agg( + ivy"org.scala-lang:scala-reflect:${scalaVersion()}", + ivy"io.undertow:undertow-core:2.0.13.Final", + ivy"com.lihaoyi::upickle:0.7.5" + ) + def compileIvyDeps = Agg(ivy"com.lihaoyi::acyclic:0.2.0") + def scalacOptions = Seq("-P:acyclic:force") + def scalacPluginIvyDeps = Agg(ivy"com.lihaoyi::acyclic:0.2.0") + + + object util extends Module { + trait UtilModule extends CaskModule { + def platformSegment: String + def millSourcePath = super.millSourcePath / os.up + + def sources = T.sources( + millSourcePath / "src", + millSourcePath / s"src-$platformSegment" + ) + def ivyDeps = Agg( + ivy"com.lihaoyi::sourcecode:0.1.7", + ivy"com.lihaoyi::pprint:0.5.5" + ) + } + + object js extends UtilModule with ScalaJSModule{ + def platformSegment = "js" + def scalaJSVersion = "0.6.28" + } + object jvm extends UtilModule{ + def platformSegment = "jvm" + } + } object test extends Tests{ diff --git a/cask/src/cask/util/BatchActor.scala b/cask/src/cask/util/BatchActor.scala deleted file mode 100644 index 137b852..0000000 --- a/cask/src/cask/util/BatchActor.scala +++ /dev/null @@ -1,40 +0,0 @@ -package cask.util - -import cask.util.Logger - -import scala.collection.mutable -import scala.concurrent.ExecutionContext - -/** - * A simple asynchrous actor, allowing safe concurrent asynchronous processing - * of queued items. `run` handles items in batches, to allow for batch - * processing optimizations to be used where relevant. - */ -abstract class BatchActor[T]()(implicit ec: ExecutionContext, - log: Logger) { - def run(items: Seq[T]): Unit - - private val queue = new mutable.Queue[T]() - private var scheduled = false - def send(t: => T): Unit = synchronized{ - queue.enqueue(t) - if (!scheduled){ - scheduled = true - ec.execute(() => runWithItems()) - } - } - - def runWithItems(): Unit = { - val items = synchronized(queue.dequeueAll(_ => true)) - try run(items) - catch{case e: Throwable => log.exception(e)} - synchronized{ - if (queue.nonEmpty) ec.execute(() => runWithItems()) - else{ - assert(scheduled) - scheduled = false - } - } - - } -} diff --git a/cask/src/cask/util/Logger.scala b/cask/src/cask/util/Logger.scala deleted file mode 100644 index 8dc3156..0000000 --- a/cask/src/cask/util/Logger.scala +++ /dev/null @@ -1,18 +0,0 @@ -package cask.util - -import sourcecode.{File, Line, Text} - -trait Logger { - def exception(t: Throwable): Unit - - def debug(t: sourcecode.Text[Any])(implicit f: sourcecode.File, line: sourcecode.Line): Unit -} -object Logger{ - class Console() extends Logger{ - def exception(t: Throwable): Unit = t.printStackTrace() - - def debug(t: Text[Any])(implicit f: File, line: Line): Unit = { - println(f.value.split('/').last + ":" + line + " " + t.source + " " + pprint.apply(t.value)) - } - } -} \ No newline at end of file diff --git a/cask/util/src/cask/util/BatchActor.scala b/cask/util/src/cask/util/BatchActor.scala new file mode 100644 index 0000000..137b852 --- /dev/null +++ b/cask/util/src/cask/util/BatchActor.scala @@ -0,0 +1,40 @@ +package cask.util + +import cask.util.Logger + +import scala.collection.mutable +import scala.concurrent.ExecutionContext + +/** + * A simple asynchrous actor, allowing safe concurrent asynchronous processing + * of queued items. `run` handles items in batches, to allow for batch + * processing optimizations to be used where relevant. + */ +abstract class BatchActor[T]()(implicit ec: ExecutionContext, + log: Logger) { + def run(items: Seq[T]): Unit + + private val queue = new mutable.Queue[T]() + private var scheduled = false + def send(t: => T): Unit = synchronized{ + queue.enqueue(t) + if (!scheduled){ + scheduled = true + ec.execute(() => runWithItems()) + } + } + + def runWithItems(): Unit = { + val items = synchronized(queue.dequeueAll(_ => true)) + try run(items) + catch{case e: Throwable => log.exception(e)} + synchronized{ + if (queue.nonEmpty) ec.execute(() => runWithItems()) + else{ + assert(scheduled) + scheduled = false + } + } + + } +} diff --git a/cask/util/src/cask/util/Logger.scala b/cask/util/src/cask/util/Logger.scala new file mode 100644 index 0000000..8dc3156 --- /dev/null +++ b/cask/util/src/cask/util/Logger.scala @@ -0,0 +1,18 @@ +package cask.util + +import sourcecode.{File, Line, Text} + +trait Logger { + def exception(t: Throwable): Unit + + def debug(t: sourcecode.Text[Any])(implicit f: sourcecode.File, line: sourcecode.Line): Unit +} +object Logger{ + class Console() extends Logger{ + def exception(t: Throwable): Unit = t.printStackTrace() + + def debug(t: Text[Any])(implicit f: File, line: Line): Unit = { + println(f.value.split('/').last + ":" + line + " " + t.source + " " + pprint.apply(t.value)) + } + } +} \ No newline at end of file -- cgit v1.2.3