Skip to content

Instantly share code, notes, and snippets.

@sjrd
Created September 1, 2017 12:41
Show Gist options
  • Save sjrd/4fb843629b7acd1917b0e005576211c7 to your computer and use it in GitHub Desktop.
Save sjrd/4fb843629b7acd1917b0e005576211c7 to your computer and use it in GitHub Desktop.
diff --cc ir/src/main/scala/org/scalajs/core/ir/ScalaJSVersions.scala
index f7c6b68,d9f10f9..0000000
--- a/ir/src/main/scala/org/scalajs/core/ir/ScalaJSVersions.scala
+++ b/ir/src/main/scala/org/scalajs/core/ir/ScalaJSVersions.scala
diff --cc project/Build.scala
index d985a48,1cb00ad..0000000
--- a/project/Build.scala
+++ b/project/Build.scala
@@@ -2,12 -3,6 +2,9 @@@ import scala.language.implicitConversio
import scala.annotation.tailrec
+import sbt._
+import Keys._
+
- import bintray.Plugin.bintrayPublishSettings
- import bintray.Keys.{repository, bintrayOrganization, bintray}
-
import com.typesafe.tools.mima.plugin.MimaPlugin.autoImport._
import java.io.{
@@@ -67,48 -48,15 +64,51 @@@ object MyScalaJSPlugin extends AutoPlug
val isGeneratingEclipse =
Properties.envOrElse("GENERATING_ECLIPSE", "false").toBoolean
+ override def projectSettings: Seq[Setting[_]] = Seq(
+ /* Remove libraryDependencies on ourselves; we use .dependsOn() instead
+ * inside this build.
+ */
+ libraryDependencies ~= { libDeps =>
+ val blacklist =
+ Set("scalajs-compiler", "scalajs-library", "scalajs-test-interface")
+ libDeps.filterNot(dep => blacklist.contains(dep.name))
+ },
+
+ /* Most of our Scala.js libraries are not cross-compiled against the
+ * the Scala.js binary version number.
+ */
+ crossVersion := CrossVersion.binary,
+
+ scalaJSLinkerConfig ~= (_.withCheckIR(true)),
+
+ // Link source maps
+ scalacOptions ++= {
+ val base = (baseDirectory in LocalProject("scalajs")).value
+ if (isGeneratingEclipse) Seq()
+ else if (isSnapshot.value) Seq()
+ else Seq(
+ // Link source maps to github sources
+ "-P:scalajs:mapSourceURI:" + base.toURI +
+ "->https://raw.githubusercontent.com/scala-js/scala-js/v" +
+ scalaJSVersion + "/"
+ )
+ }
+ )
+}
+
+object Build {
+ import MyScalaJSPlugin.isGeneratingEclipse
+
+ val bintrayProjectName = settingKey[String](
+ "Project name on Bintray")
+
val fetchScalaSource = taskKey[File](
"Fetches the scala source for the current scala version")
val shouldPartest = settingKey[Boolean](
"Whether we should partest the current scala version (and fail if we can't)")
+ /* MiMa configuration -- irrelevant while in 1.0.0-SNAPSHOT.
- val previousVersion = "0.6.19"
+ val previousVersion = "0.6.20"
val previousSJSBinaryVersion =
ScalaJSCrossVersion.binaryScalaJSVersion(previousVersion)
val previousBinaryCrossVersion =
@@@ -359,17 -312,24 +359,23 @@@
}
)
- private def publishToBintraySettings = Seq(
+ private def publishToBintraySettings = Def.settings(
- bintrayPublishSettings,
- repository in bintray := "scala-js-releases",
- bintrayOrganization in bintray := Some("scala-js")
+ publishTo := {
+ val proj = bintrayProjectName.value
+ val ver = version.value
+ if (isSnapshot.value) {
+ None // Bintray does not support snapshots
+ } else {
+ val url = new java.net.URL(
+ s"https://api.bintray.com/content/scala-js/scala-js-releases/$proj/$ver")
+ val patterns = Resolver.ivyStylePatterns
+ Some(Resolver.url("bintray", url)(patterns))
+ }
+ }
)
- val publishIvySettings = (
- publishToBintraySettings
- ) ++ Seq(
+ val publishIvySettings = Def.settings(
- if (Properties.envOrNone("PUBLISH_TO_BINTRAY") == Some("true"))
- publishToBintraySettings
- else
- Nil,
++ publishToBintraySettings,
publishMavenStyle := false
)
@@@ -428,26 -407,11 +434,9 @@@
)
}
}
-
- def enableScalastyleInSharedSources: Project = {
- import AddSettings._
- import org.scalastyle.sbt.ScalastylePlugin.scalastyleSources
-
- project.settings(
- scalastyleSources := (unmanagedSourceDirectories in Compile).value,
- scalastyleSources in Test := (unmanagedSourceDirectories in Test).value,
- SettingKey[String]("foobabar") := scalastyleSources.value.toString
- ).settingSets(
- /* We need to force our settings to be applied *after* settings
- * coming from non-Auto plugins. Because guess what, that's not the
- * default O_o!
- */
- seq(autoPlugins, nonAutoPlugins, buildScalaFiles, userSettings, defaultSbtFiles)
- )
- }
}
- val thisBuildSettings = (
- inScope(Global)(ScalaJSPlugin.globalSettings)
- ) ++ Seq(
+ val thisBuildSettings = Def.settings(
// Most of the projects cross-compile
crossScalaVersions := Seq(
"2.10.2",
@@@ -524,30 -491,33 +513,30 @@@
testOptions += Tests.Argument(TestFrameworks.JUnit, "-v", "-a", "-s")
)
- lazy val irProject: Project = Project(
- id = "ir",
- base = file("ir"),
- settings = commonIrProjectSettings ++ Seq(
+ lazy val irProject: Project = Project(id = "ir", base = file("ir")).settings(
+ commonIrProjectSettings,
libraryDependencies +=
"com.novocode" % "junit-interface" % "0.9" % "test"
- ).enableScalastyleInSharedSources
+ )
- )
lazy val irProjectJS: Project = Project(
- id = "irJS",
- base = file("ir/.js"),
- settings = commonIrProjectSettings ++ myScalaJSSettings ++ Seq(
+ id = "irJS", base = file("ir/.js")
+ ).enablePlugins(
+ MyScalaJSPlugin
+ ).settings(
+ commonIrProjectSettings,
crossVersion := ScalaJSCrossVersion.binary,
unmanagedSourceDirectories in Compile +=
(scalaSource in Compile in irProject).value,
unmanagedSourceDirectories in Test +=
(scalaSource in Test in irProject).value
- )
).withScalaJSCompiler.withScalaJSJUnitPlugin.dependsOn(
- javalibEx, jUnitRuntime % "test"
+ library, jUnitRuntime % "test"
- ).enableScalastyleInSharedSources
+ )
- lazy val compiler: Project = Project(
- id = "compiler",
- base = file("compiler"),
- settings = commonSettings ++ publishSettings ++ Seq(
+ lazy val compiler: Project = project.settings(
+ commonSettings,
+ publishSettings,
name := "Scala.js compiler",
crossVersion := CrossVersion.full, // because compiler api is not binary compatible
libraryDependencies ++= Seq(
@@@ -621,40 -593,34 +610,40 @@@
) ++ (
parallelCollectionsDependencies(scalaVersion.value)
)
- ).dependsOn(irProject).enableScalastyleInSharedSources
- )
+ ).dependsOn(irProject)
- lazy val toolsJS: Project = Project(
- id = "toolsJS",
- base = file("tools/js"),
- settings = myScalaJSSettings ++ commonToolsSettings ++ Seq(
+ lazy val toolsJS: Project = (project in file("tools/js")).enablePlugins(
+ MyScalaJSPlugin
+ ).settings(
+ commonToolsSettings,
crossVersion := ScalaJSCrossVersion.binary,
- /* We need RuntimeClassNameMapper.custom() in QuickLinker
- * TODO Remove this in 1.x.
- */
- scalacOptions in Test -= "-Xfatal-warnings",
+ scalaJSLinkerConfig in Test ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
- resourceGenerators in Test += Def.task {
- val base = (resourceManaged in Compile).value
- IO.createDirectory(base)
- val outFile = base / "js-test-definitions.js"
+ jsExecutionFiles in Test := {
+ val frameworks = (loadedTestFrameworks in testSuite in Test).value
+ val frameworkImplClassNames =
+ frameworks.toList.map(_._1.implClassNames.toList)
+
+ val taskDefs = for (td <- (definedTests in testSuite in Test).value) yield {
+ new sbt.testing.TaskDef(td.name, td.fingerprint,
+ td.explicitlySpecified, td.selectors)
+ }
val testDefinitions = {
- org.scalajs.build.HTMLRunnerTemplateAccess.renderTestDefinitions(
- (loadedTestFrameworks in testSuite in Test).value,
- (definedTests in testSuite in Test).value)
+ org.scalajs.build.HTMLRunnerBuilderAccess.renderTestDefinitions(
+ frameworkImplClassNames, taskDefs.toList)
}
- IO.write(outFile, testDefinitions)
- Seq(outFile)
- }.taskValue,
+ val testDefinitionsFile = {
+ new MemVirtualJSFile("js-test-definitions.js")
+ .withContent(testDefinitions)
+ }
+
+ testDefinitionsFile +: (jsExecutionFiles in Test).value
+ },
+
+ testSuiteJSExecutionFilesSetting,
// Give more memory to Node.js, and deactivate source maps
jsEnv := {
@@@ -747,22 -706,31 +736,22 @@@
}
}
).withScalaJSCompiler.dependsOn(
- javalibEx, testSuite % "test->test", irProjectJS
+ library, irProjectJS, jUnitRuntime % "test"
- ).enableScalastyleInSharedSources
+ )
- lazy val jsEnvs: Project = Project(
- id = "jsEnvs",
- base = file("js-envs"),
- settings = (
- commonSettings ++ publishSettings ++ fatalWarningsSettings
- ) ++ Seq(
+ lazy val jsEnvs: Project = (project in file("js-envs")).settings(
+ commonSettings,
+ publishSettings,
+ fatalWarningsSettings,
name := "Scala.js JS Envs",
- libraryDependencies ++= Seq(
- "io.apigee" % "rhino" % "1.7R5pre4",
- "org.webjars" % "envjs" % "1.2"
- ) ++ ScalaJSPluginInternal.phantomJSJettyModules.map(_ % "provided"),
previousArtifactSetting,
mimaBinaryIssueFilters ++= BinaryIncompatibilities.JSEnvs
- )
).dependsOn(tools)
- lazy val jsEnvsTestKit: Project = Project(
- id = "jsEnvsTestKit",
- base = file("js-envs-test-kit"),
- settings = (
- commonSettings ++ publishSettings ++ fatalWarningsSettings
- ) ++ Seq(
+ lazy val jsEnvsTestKit: Project = (project in file("js-envs-test-kit")).settings(
+ commonSettings,
+ publishSettings,
+ fatalWarningsSettings,
name := "Scala.js JS Envs Test Kit",
libraryDependencies +=
"junit" % "junit" % "4.8.2",
@@@ -796,15 -769,18 +785,15 @@@
baseDirectory.value.getParentFile / "test-common/src/main/scala",
unmanagedSourceDirectories in Test +=
baseDirectory.value.getParentFile / "test-common/src/test/scala"
- ).dependsOn(jsEnvs).enableScalastyleInSharedSources
- )
+ ).dependsOn(jsEnvs)
- lazy val plugin: Project = Project(
- id = "sbtPlugin",
- base = file("sbt-plugin"),
- settings = (
- commonSettings ++ publishIvySettings ++ fatalWarningsSettings
- ) ++ Seq(
+ lazy val plugin: Project = Project(id = "sbtPlugin", base = file("sbt-plugin")).settings(
+ commonSettings,
+ publishIvySettings,
+ fatalWarningsSettings,
name := "Scala.js sbt plugin",
normalizedName := "sbt-scalajs",
- name in bintray := "sbt-scalajs-plugin", // "sbt-scalajs" was taken
+ bintrayProjectName := "sbt-scalajs-plugin", // "sbt-scalajs" was taken
sbtPlugin := true,
scalaBinaryVersion :=
CrossVersion.binaryScalaVersion(scalaVersion.value),
@@@ -837,7 -806,8 +826,7 @@@
sbtJars.map(_.data -> docUrl).toMap
}
- ).dependsOn(tools, jsEnvs, nodeJSEnv, testAdapter).enableScalastyleInSharedSources
- )
- ).dependsOn(tools, jsEnvs, testAdapter)
++ ).dependsOn(tools, jsEnvs, nodeJSEnv, testAdapter)
lazy val delambdafySetting = {
scalacOptions ++= (
@@@ -1179,19 -1188,17 +1168,19 @@@
* stuff and JUnit does not support async tests. Therefore we need to
* block, so we cannot run on JS.
*/
- ).withScalaJSCompiler.dependsOn(library).enableScalastyleInSharedSources
- )
+ ).withScalaJSCompiler.dependsOn(library)
- lazy val jUnitRuntime = Project(
- id = "jUnitRuntime",
- base = file("junit-runtime"),
- settings = commonSettings ++ publishSettings ++ myScalaJSSettings ++
- fatalWarningsSettings ++ Seq(name := "Scala.js JUnit test runtime")
+ lazy val jUnitRuntime = (project in file("junit-runtime")).enablePlugins(
+ MyScalaJSPlugin
+ ).settings(
+ commonSettings,
+ publishSettings,
+ fatalWarningsSettings,
+ name := "Scala.js JUnit test runtime"
).withScalaJSCompiler.dependsOn(testInterface)
- val commonJUnitTestOutputsSettings = commonSettings ++ Seq(
+ val commonJUnitTestOutputsSettings = Def.settings(
+ commonSettings,
publishArtifact in Compile := false,
parallelExecution in Test := false,
unmanagedSourceDirectories in Test +=
@@@ -1202,29 -1209,33 +1191,29 @@@
)
)
- lazy val jUnitTestOutputsJS = Project(
- id = "jUnitTestOutputsJS",
- base = file("junit-test/output-js"),
- settings = commonJUnitTestOutputsSettings ++ myScalaJSSettings ++ Seq(
+ lazy val jUnitTestOutputsJS = (project in file("junit-test/output-js")).enablePlugins(
+ MyScalaJSPlugin
+ ).settings(
+ commonJUnitTestOutputsSettings,
name := "Tests for Scala.js JUnit output in JS."
- )
).withScalaJSCompiler.withScalaJSJUnitPlugin.dependsOn(
jUnitRuntime % "test", testInterface % "test"
- ).enableScalastyleInSharedSources
+ )
- lazy val jUnitTestOutputsJVM = Project(
- id = "jUnitTestOutputsJVM",
- base = file("junit-test/output-jvm"),
- settings = commonJUnitTestOutputsSettings ++ Seq(
+ lazy val jUnitTestOutputsJVM = (project in file("junit-test/output-jvm")).settings(
+ commonJUnitTestOutputsSettings,
name := "Tests for Scala.js JUnit output in JVM.",
libraryDependencies ++= Seq(
"org.scala-sbt" % "test-interface" % "1.0" % "test",
"com.novocode" % "junit-interface" % "0.11" % "test"
)
- ).enableScalastyleInSharedSources
+ )
- )
- lazy val jUnitPlugin = Project(
- id = "jUnitPlugin",
- base = file("junit-plugin"),
- settings = commonSettings ++ publishSettings ++ fatalWarningsSettings ++ Seq(
+ lazy val jUnitPlugin = (project in file("junit-plugin")).settings(
+ commonSettings,
+ publishSettings,
+ fatalWarningsSettings,
name := "Scala.js JUnit test plugin",
crossVersion := CrossVersion.full,
libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value,
@@@ -1596,16 -1649,16 +1585,16 @@@
ModuleInitializer.mainMethodWithArgs(
"org.scalajs.testsuite.compiler.ModuleInitializerInTestConfiguration",
"mainArgs2", List("foo", "bar"))
- }
- )
+ },
+
+ testSuiteTestHtmlSetting
).withScalaJSCompiler.withScalaJSJUnitPlugin.dependsOn(
library, jUnitRuntime
- ).enableScalastyleInSharedSources
+ )
- lazy val testSuiteJVM: Project = Project(
- id = "testSuiteJVM",
- base = file("test-suite/jvm"),
- settings = commonSettings ++ testSuiteCommonSettings(isJSTest = false) ++ Seq(
+ lazy val testSuiteJVM: Project = (project in file("test-suite/jvm")).settings(
+ commonSettings,
+ testSuiteCommonSettings(isJSTest = false),
name := "Scala.js test suite on JVM",
/* Scala.js always assumes en-US, UTF-8 and NL as line separator by
@@@ -1621,24 -1674,30 +1610,24 @@@
libraryDependencies +=
"com.novocode" % "junit-interface" % "0.11" % "test"
- ).enableScalastyleInSharedSources
+ )
- )
- lazy val noIrCheckTest: Project = Project(
- id = "noIrCheckTest",
- base = file("no-ir-check-test"),
- settings = commonSettings ++ myScalaJSSettings ++ testTagSettings ++ Seq(
- name := "Scala.js not IR checked tests",
- scalaJSOptimizerOptions ~= (_.
- withCheckScalaJSIR(false).
- withBypassLinkingErrors(true)
- ),
- testOptions += Tests.Argument(TestFrameworks.JUnit, "-v", "-a", "-s"),
- publishArtifact in Compile := false
- )
- ).withScalaJSCompiler.withScalaJSJUnitPlugin.dependsOn(library, jUnitRuntime)
-
- lazy val javalibExTestSuite: Project = Project(
- id = "javalibExTestSuite",
- base = file("javalib-ex-test-suite"),
- settings = (
- commonSettings ++ myScalaJSSettings ++ testTagSettings
- ) ++ Seq(
- name := "JavaLib Ex Test Suite",
+ /* Additional test suite, for tests that should not be part of the normal
+ * test suite for various reasons. The most common reason is that the tests
+ * in there "fail to fail" if they happen in the larger test suite, due to
+ * all the other code that's there (can have impact on dce, optimizations,
+ * GCC, etc.).
+ *
+ * TODO Ideally, we should have a mechanism to separately compile, link and
+ * test each file in this test suite, so that we're sure that do not
+ * interfere with other.
+ */
+ lazy val testSuiteEx: Project = (project in file("test-suite-ex")).enablePlugins(
+ MyScalaJSPlugin
+ ).settings(
+ commonSettings,
+ testTagSettings,
+ name := "Scala.js test suite ex",
publishArtifact in Compile := false,
testOptions += Tests.Argument(TestFrameworks.JUnit, "-v", "-a", "-s"),
scalacOptions in Test ~= (_.filter(_ != "-deprecation"))
diff --cc sbt-plugin/src/main/scala/org/scalajs/sbtplugin/ScalaJSPlugin.scala
index 0407f7c,fcf94df..0000000
--- a/sbt-plugin/src/main/scala/org/scalajs/sbtplugin/ScalaJSPlugin.scala
+++ b/sbt-plugin/src/main/scala/org/scalajs/sbtplugin/ScalaJSPlugin.scala
@@@ -9,56 -9,214 +9,54 @@@
package org.scalajs.sbtplugin
+import scala.language.implicitConversions
+
import sbt._
+ import sbt.Keys._
-import org.scalajs.core.tools.sem.Semantics
+import sbtcrossproject._
+
+import org.scalajs.core.ir.ScalaJSVersions
+
import org.scalajs.core.tools.io._
import org.scalajs.core.tools.linker._
import org.scalajs.core.tools.linker.standard._
-import org.scalajs.core.tools.jsdep.{JSDependencyManifest, ResolvedJSDependency}
-import org.scalajs.core.tools.jsdep.ManifestFilters.ManifestFilter
-import org.scalajs.core.tools.jsdep.DependencyResolver.DependencyFilter
-
-import org.scalajs.core.ir.ScalaJSVersions
-import org.scalajs.jsenv.{JSEnv, JSConsole}
-import org.scalajs.jsenv.rhino.RhinoJSEnv
-import org.scalajs.jsenv.nodejs.NodeJSEnv
-import org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv
-import org.scalajs.jsenv.phantomjs.PhantomJSEnv
+import org.scalajs.jsenv.JSEnv
object ScalaJSPlugin extends AutoPlugin {
- /** The global Scala.js IR cache */
- val globalIRCache: IRFileCache = new IRFileCache()
-
override def requires: Plugins = plugins.JvmPlugin
- /* The following module-case double definition is a workaround for a bug
- * somewhere in the sbt dependency macro - scala macro pipeline that affects
- * the %%% operator on dependencies (see #1331).
- *
- * If the object AutoImport is written lower-case, it is wrongly identified as
- * dynamic dependency (only if the usage code is generated by a macro). On the
- * other hand, only lower-case autoImport is automatically imported by sbt (in
- * an AutoPlugin, therefore the alias.
- *
- * We do not know *why* this fixes the issue, but it does.
- */
- val autoImport = AutoImport
-
- object AutoImport extends impl.DependencyBuilders
- with cross.CrossProjectExtra {
+ object autoImport {
import KeyRanks._
- // Some constants
+ /** The current version of the Scala.js sbt plugin and tool chain. */
val scalaJSVersion = ScalaJSVersions.current
- val scalaJSIsSnapshotVersion = ScalaJSVersions.currentIsSnapshot
- val scalaJSBinaryVersion = ScalaJSCrossVersion.currentBinaryVersion
-
- // Stage values
- @deprecated("Use FastOptStage instead", "0.6.6")
- val PreLinkStage = Stage.FastOpt
- val FastOptStage = Stage.FastOpt
- val FullOptStage = Stage.FullOpt
- // CrossType
- val CrossType = cross.CrossType
+ // The JS platform for sbt-crossproject
+ val JSPlatform = org.scalajs.sbtplugin.JSPlatform
- // Factory methods for JSEnvs
-
- /** A non-deprecated version of `RhinoJSEnv` for internal use. */
- private[sbtplugin]
- def RhinoJSEnvInternal(): Def.Initialize[Task[RhinoJSEnv]] = Def.task {
- /* We take the semantics from the linker, since they depend on the stage.
- * This way we are sure we agree on the semantics with the linker.
- */
- import ScalaJSPluginInternal.scalaJSRequestsDOMInternal
- val semantics = scalaJSLinker.value.semantics
- val withDOM = scalaJSRequestsDOMInternal.value
- new RhinoJSEnv(semantics, withDOM, internal = ())
+ implicit def JSCrossProjectBuilderOps(
+ builder: CrossProject.Builder): JSCrossProjectOps = {
+ new JSCrossProjectOps(builder.crossType(CrossType.Full))
}
- /** Creates a [[sbt.Def.Initialize Def.Initialize]] for a [[RhinoJSEnv]].
- *
- * Use this to explicitly specify in your build that you would like to run
- * with Rhino:
- *
- * {{{
- * Seq(Compile, Test).flatMap(c => inConfig(c)(jsEnv := RhinoJSEnv().value))
- * }}}
- *
- * The Rhino JS environment will support DOM through `env.js` if and only
- * if `scalaJSRequestsDOM.value` evaluates to `true`.
- *
- * Note that the resulting [[sbt.Def.Setting Setting]] must be scoped in a
- * project that has the `ScalaJSPlugin` enabled to work properly.
- * Therefore, either put the upper line in your project settings (common
- * case) or scope it manually, using
- * [[sbt.ProjectExtra.inScope[* Project.inScope]].
- */
- @deprecated(
- "The Rhino JS environment is being phased out. " +
- "It will be removed in Scala.js 1.0.0. ",
- "0.6.13")
- def RhinoJSEnv(): Def.Initialize[Task[RhinoJSEnv]] = RhinoJSEnvInternal()
-
- /**
- * Creates a [[sbt.Def.Initialize Def.Initialize]] for a NodeJSEnv. Use
- * this to explicitly specify in your build that you would like to run with Node.js:
- *
- * {{{
- * jsEnv := NodeJSEnv().value
- * }}}
- *
- * Note that the resulting [[sbt.Def.Setting Setting]] is not scoped at
- * all, but must be scoped in a project that has the ScalaJSPlugin enabled
- * to work properly.
- * Therefore, either put the upper line in your project settings (common
- * case) or scope it manually, using
- * [[sbt.ProjectExtra.inScope[* Project.inScope]].
- */
- @deprecated(
- "Use `jsEnv := new org.scalajs.jsenv.nodejs.NodeJSEnv(...)` instead.",
- "0.6.16")
- def NodeJSEnv(
- executable: String = "node",
- args: Seq[String] = Seq.empty,
- env: Map[String, String] = Map.empty
- ): Def.Initialize[Task[NodeJSEnv]] = Def.task {
- new NodeJSEnv(
- org.scalajs.jsenv.nodejs.NodeJSEnv.Config()
- .withExecutable(executable)
- .withArgs(args.toList)
- .withEnv(env))
- }
+ implicit class JSCrossProjectOps(project: CrossProject) {
+ def js: Project = project.projects(JSPlatform)
- /**
- * Creates a [[sbt.Def.Initialize Def.Initialize]] for a JSDOMNodeJSEnv. Use
- * this to explicitly specify in your build that you would like to run with
- * Node.js on a JSDOM window:
- *
- * {{{
- * jsEnv := JSDOMNodeJSEnv().value
- * }}}
- *
- * Note that the resulting [[sbt.Def.Setting Setting]] is not scoped at
- * all, but must be scoped in a project that has the ScalaJSPlugin enabled
- * to work properly.
- * Therefore, either put the upper line in your project settings (common
- * case) or scope it manually, using
- * [[sbt.ProjectExtra.inScope[* Project.inScope]].
- */
- @deprecated(
- "Use `jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv(...)` " +
- "instead.",
- "0.6.16")
- def JSDOMNodeJSEnv(
- executable: String = "node",
- args: Seq[String] = Seq.empty,
- env: Map[String, String] = Map.empty
- ): Def.Initialize[Task[JSDOMNodeJSEnv]] = Def.task {
- new JSDOMNodeJSEnv(
- org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv.Config()
- .withExecutable(executable)
- .withArgs(args.toList)
- .withEnv(env))
- }
+ def jsSettings(ss: Def.SettingsDefinition*): CrossProject =
+ jsConfigure(_.settings(ss: _*))
- /** Creates a [[sbt.Def.Initialize Def.Initialize]] for a PhantomJSEnv.
- *
- * Use this to explicitly specify in your build that you would like to run
- * with PhantomJS:
- *
- * {{{
- * jsEnv := PhantomJSEnv(...).value
- * }}}
- *
- * The specified `Config` is augmented with an appropriate Jetty class
- * loader (through `withJettyClassLoader`).
- *
- * Note that the resulting [[sbt.Def.Setting Setting]] is not scoped at
- * all, but must be scoped in a project that has the ScalaJSPlugin enabled
- * to work properly.
- * Therefore, either put the upper line in your project settings (common
- * case) or scope it manually, using
- * [[sbt.ProjectExtra.inScope[* Project.inScope]].
- */
- def PhantomJSEnv(
- config: org.scalajs.jsenv.phantomjs.PhantomJSEnv.Config
- ): Def.Initialize[Task[PhantomJSEnv]] = Def.task {
- val loader = scalaJSPhantomJSClassLoader.value
- new PhantomJSEnv(config.withJettyClassLoader(loader))
+ def jsConfigure(transformer: Project => Project): CrossProject =
+ project.configurePlatform(JSPlatform)(transformer)
}
- /** Creates a [[sbt.Def.Initialize Def.Initialize]] for a PhantomJSEnv
- * with the default configuration.
- *
- * This is equivalent to
- * {{{
- * PhantomJSEnv(org.scalajs.jsenv.phantomjs.PhantomJSEnv.Config())
- * }}}
- */
- def PhantomJSEnv(): Def.Initialize[Task[PhantomJSEnv]] =
- PhantomJSEnv(org.scalajs.jsenv.phantomjs.PhantomJSEnv.Config())
-
- /** Creates a [[sbt.Def.Initialize Def.Initialize]] for a PhantomJSEnv. */
- @deprecated("Use the overload with a PhantomJSEnv.Config.", "0.6.20")
- def PhantomJSEnv(
- executable: String = "phantomjs",
- args: Seq[String] = Seq.empty,
- env: Map[String, String] = Map.empty,
- autoExit: Boolean = true
- ): Def.Initialize[Task[PhantomJSEnv]] = {
- PhantomJSEnv(
- org.scalajs.jsenv.phantomjs.PhantomJSEnv.Config()
- .withExecutable(executable)
- .withArgs(args.toList)
- .withEnv(env)
- .withAutoExit(autoExit))
- }
+ // Stage values
+ val FastOptStage = Stage.FastOpt
+ val FullOptStage = Stage.FullOpt
// ModuleKind
- val ModuleKind = org.scalajs.core.tools.linker.backend.ModuleKind
+ val ModuleKind = org.scalajs.core.tools.linker.ModuleKind
// All our public-facing keys
@@@ -193,7 -512,31 +200,30 @@@
override def globalSettings: Seq[Setting[_]] = {
Seq(
scalaJSStage := Stage.FastOpt,
- ScalaJSPluginInternal.scalaJSClearCacheStats := globalIRCache.clearStats()
- scalaJSUseRhinoInternal := false,
+
+ ScalaJSPluginInternal.scalaJSClearCacheStatsInternal := {},
+
+ // Clear the IR cache stats every time a sequence of tasks ends
+ onComplete := {
+ val prev = onComplete.value
+
+ { () =>
+ prev()
+ ScalaJSPluginInternal.globalIRCache.clearStats()
+ }
+ },
+
+ /* When unloading the build, free all the IR caches.
+ * Note that this runs on `reload`s, for example, but not when we
+ * *exit* sbt. That is fine, though, since in that case the process
+ * is killed altogether.
+ */
+ onUnload := {
+ onUnload.value.andThen { state =>
+ ScalaJSPluginInternal.freeAllIRCaches()
+ state
+ }
+ }
)
}
diff --cc sbt-plugin/src/main/scala/org/scalajs/sbtplugin/ScalaJSPluginInternal.scala
index f98fee6,676c491..0000000
--- a/sbt-plugin/src/main/scala/org/scalajs/sbtplugin/ScalaJSPluginInternal.scala
+++ b/sbt-plugin/src/main/scala/org/scalajs/sbtplugin/ScalaJSPluginInternal.scala
@@@ -49,6 -83,13 +81,9 @@@ object ScalaJSPluginInternal
"Scala.js internal: Clear the global IR cache's statistics. Used to " +
"implement cache statistics.", KeyRanks.Invisible)
+ @deprecated("Not used anymore.", "0.6.20")
+ val scalaJSClearCacheStats = scalaJSClearCacheStatsInternal
+
- /** Dummy setting to ensure we do not fork in Scala.js run & test. */
- val scalaJSEnsureUnforked = SettingKey[Boolean]("ensureUnforked",
- "Scala.js internal: Fails if fork is true.", KeyRanks.Invisible)
-
val scalaJSLinker: SettingKey[ClearableLinker] =
ScalaJSPlugin.autoImport.scalaJSLinker
@@@ -299,19 -459,18 +339,14 @@@
}
}
) ++ Seq(
- /* Note: This cache only gets freed by its finalizer. Otherwise we'd need
- * to intercept reloads in sbt (see #2171).
- * Also note that it doesn't get cleared by the sbt's clean task.
- */
- scalaJSIRCacheHolder := globalIRCache.newCache,
- scalaJSIRCache := Def.task {
- scalaJSIRCacheHolder.value
- }.dependsOn(scalaJSClearCacheStats).value,
+ // Note: this cache is not cleared by the sbt's clean task.
+ scalaJSIRCacheHolderInternal := newIRCache,
+ scalaJSIRCache := scalaJSIRCacheHolderInternal.value,
scalaJSIR := {
- import IRFileCache.IRContainer
-
- val rawIR = collectFromClasspath(fullClasspath.value,
- "*.sjsir", collectJar = jar => IRContainer.Jar(jar) :: Nil,
- collectFile = { (file, relPath) =>
- IRContainer.File(FileVirtualScalaJSIRFile.relative(file, relPath))
- })
+ val rawIR = collectFromClasspath(fullClasspath.value, "*.sjsir",
+ collectJar = Seq(_),
+ collectFile = FileVirtualScalaJSIRFile.relative)
val cache = scalaJSIRCache.value
rawIR.map(cache.cached)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment