From 23186b5c5b5d68eb03accedbd92129580de5e2c8 Mon Sep 17 00:00:00 2001 From: Tobias Schlatter Date: Sun, 11 Jul 2021 13:17:23 +0200 Subject: [PATCH] Rely on sbt's run cancellation rather than building our own Since the upgrade to sbt 1.5.4, Ctrl+C during a run cancels it as expected. Therefore, we remove our custom implementation of a similar thing (which was buggy anyways, e.g. #4336). I believe it reasonable to expect users that need this feature to upgrade sbt. --- project/BinaryIncompatibilities.scala | 3 + .../scala/org/scalajs/sbtplugin/Run.scala | 58 ------------------- .../sbtplugin/ScalaJSPluginInternal.scala | 5 +- 3 files changed, 6 insertions(+), 60 deletions(-) delete mode 100644 sbt-plugin/src/main/scala/org/scalajs/sbtplugin/Run.scala diff --git a/project/BinaryIncompatibilities.scala b/project/BinaryIncompatibilities.scala index 50ed423e45..786a68bf2f 100644 --- a/project/BinaryIncompatibilities.scala +++ b/project/BinaryIncompatibilities.scala @@ -14,6 +14,9 @@ object BinaryIncompatibilities { ) val SbtPlugin = Seq( + // private[sbtplugin], not an issue. + exclude[MissingClassProblem]("org.scalajs.sbtplugin.Run"), + exclude[MissingClassProblem]("org.scalajs.sbtplugin.Run$"), ) val TestCommon = Seq( diff --git a/sbt-plugin/src/main/scala/org/scalajs/sbtplugin/Run.scala b/sbt-plugin/src/main/scala/org/scalajs/sbtplugin/Run.scala deleted file mode 100644 index 242d8a77de..0000000000 --- a/sbt-plugin/src/main/scala/org/scalajs/sbtplugin/Run.scala +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Scala.js (https://www.scala-js.org/) - * - * Copyright EPFL. - * - * Licensed under Apache License 2.0 - * (https://www.apache.org/licenses/LICENSE-2.0). - * - * See the NOTICE file distributed with this work for - * additional information regarding copyright ownership. - */ - -package org.scalajs.sbtplugin - -import org.scalajs.jsenv._ - -import scala.concurrent._ -import scala.concurrent.duration.Duration -import scala.concurrent.ExecutionContext.Implicits.global - -private[sbtplugin] object Run { - /** Starts and waits for a run on the given [[JSEnv]] interruptibly. - * - * Interruption can be triggered by typing anything into stdin. - */ - def runInterruptible(jsEnv: JSEnv, input: Seq[Input], config: RunConfig): Unit = { - val readPromise = Promise[Unit]() - val readThread = new Thread { - override def run(): Unit = { - try { - while (System.in.available() == 0) { - Thread.sleep(50) - } - - System.in.read() - } catch { - case _: InterruptedException => - } finally { - readPromise.success(()) - } - } - } - - val run = jsEnv.start(input, config) - try { - readThread.start() - - val fut = Future.firstCompletedOf(List(readPromise.future, run.future)) - Await.result(fut, Duration.Inf) - } finally { - run.close() - } - - readThread.interrupt() - readThread.join() - Await.result(run.future, Duration.Inf) - } -} diff --git a/sbt-plugin/src/main/scala/org/scalajs/sbtplugin/ScalaJSPluginInternal.scala b/sbt-plugin/src/main/scala/org/scalajs/sbtplugin/ScalaJSPluginInternal.scala index cf783e9bb1..faeaeaffef 100644 --- a/sbt-plugin/src/main/scala/org/scalajs/sbtplugin/ScalaJSPluginInternal.scala +++ b/sbt-plugin/src/main/scala/org/scalajs/sbtplugin/ScalaJSPluginInternal.scala @@ -518,13 +518,14 @@ private[sbtplugin] object ScalaJSPluginInternal { val env = jsEnv.value val className = mainClass.value.getOrElse("") - log.info(s"Running $className. Hit any key to interrupt.") + log.info(s"Running $className.") log.debug(s"with JSEnv ${env.name}") val input = jsEnvInput.value val config = RunConfig().withLogger(sbtLogger2ToolsLogger(log)) - Run.runInterruptible(env, input, config) + val run = env.start(input, config) + Await.result(run.future, Duration.Inf) }, runMain := {