Skip to content

Commit 3d3e149

Browse files
committed
Use scripted for concurrent linker test
This is so that the main sbt-plugin-test does not have a direct dependency on the Linker anymore (see scala-js#3805 for details).
1 parent 0d6be65 commit 3d3e149

File tree

8 files changed

+95
-45
lines changed

8 files changed

+95
-45
lines changed

Jenkinsfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ def Tasks = [
364364
linker/compile:doc jsEnvs/compile:doc \
365365
jsEnvsTestKit/compile:doc nodeJSEnv/compile:doc \
366366
testAdapter/compile:doc \
367-
sbtPlugin/compile:doc
367+
sbtPlugin/compile:doc &&
368+
sbt sbtPlugin/scripted
368369
''',
369370

370371
"partestc": '''
@@ -393,7 +394,7 @@ def Tasks = [
393394
noDOM/testHtml multiTestJS/testHtml \
394395
test \
395396
noDOM/testScalaJSModuleInitializers \
396-
noDOM/clean noDOM/concurrentUseOfLinkerTest \
397+
noDOM/clean \
397398
multiTestJS/test:testScalaJSSourceMapAttribute &&
398399
sbt 'set scalaJSStage in Global := FullOptStage' \
399400
noDOM/testHtml multiTestJS/testHtml

project/Build.scala

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Keys._
99

1010
import com.typesafe.tools.mima.plugin.MimaPlugin.autoImport._
1111
import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport._
12+
import ScriptedPlugin.autoImport._
1213

1314
import java.util.Arrays
1415

@@ -784,7 +785,8 @@ object Build {
784785
baseDirectory.value.getParentFile / "test-common/src/test/scala"
785786
).dependsOn(jsEnvs, jUnitAsyncJVM % "test")
786787

787-
lazy val plugin: Project = Project(id = "sbtPlugin", base = file("sbt-plugin")).settings(
788+
lazy val plugin: Project = Project(id = "sbtPlugin", base = file("sbt-plugin"))
789+
.enablePlugins(ScriptedPlugin).settings(
788790
commonSettings,
789791
publishIvySettings,
790792
fatalWarningsSettings,
@@ -801,6 +803,37 @@ object Build {
801803

802804
addSbtPlugin("org.portable-scala" % "sbt-platform-deps" % "1.0.0"),
803805

806+
scriptedLaunchOpts += "-Dplugin.version=" + version.value,
807+
808+
scriptedLaunchOpts ++= {
809+
// Forward Ivy home options.
810+
for {
811+
o <- Seq("sbt.boot.directory", "sbt.ivy.home", "ivy.home", "sbt.global.base")
812+
v <- sys.props.get(o)
813+
} yield {
814+
s"-D$o=$v"
815+
}
816+
},
817+
818+
scriptedDependencies := {
819+
scriptedDependencies.dependsOn(
820+
publishLocal in compiler,
821+
publishLocal in library,
822+
publishLocal in testInterface,
823+
publishLocal in testBridge,
824+
publishLocal in jUnitPlugin,
825+
publishLocal in jUnitRuntime,
826+
publishLocal in irProject,
827+
publishLocal in logging,
828+
publishLocal in linkerInterface,
829+
publishLocal in linker,
830+
publishLocal in jsEnvs,
831+
publishLocal in nodeJSEnv,
832+
publishLocal in testAdapter,
833+
publishLocal in jsEnvs,
834+
).value
835+
},
836+
804837
// Add API mappings for sbt (seems they don't export their API URL)
805838
apiMappings ++= {
806839
val deps = (externalDependencyClasspath in Compile).value

sbt-plugin-test/build.sbt

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
import scala.concurrent.Await
2-
import scala.concurrent.duration.Duration
3-
4-
import org.scalajs.linker.MemOutputFile
5-
import org.scalajs.linker.interface._
6-
import org.scalajs.sbtplugin.Loggers.sbtLogger2ToolsLogger
1+
import org.scalajs.linker.interface.ModuleInitializer
72
import org.scalajs.sbtplugin.ScalaJSCrossVersion
83

9-
lazy val concurrentFakeFullOptJS = taskKey[Any]("")
10-
lazy val concurrentUseOfLinkerTest = taskKey[Any]("")
11-
124
name := "Scala.js sbt test"
135

146
version := scalaJSVersion
@@ -56,39 +48,7 @@ lazy val noDOM = project.settings(baseSettings: _*).
5648
assert((scalaJSModuleInitializers in Test).value.size == 3,
5749
"Bad number of scalaJSModuleInitializers in Test")
5850
}
59-
).
60-
/* This hopefully exposes concurrent uses of the linker. If it fails/gets
61-
* flaky, there is a bug somewhere - #2202
62-
*/
63-
settings(inConfig(Compile)(Seq(
64-
// A fake fullOptJS that we will run concurrently with the true fullOptJS
65-
concurrentFakeFullOptJS := Def.taskDyn {
66-
val s = (streams in fullOptJS).value
67-
val log = s.log
68-
val ir = (scalaJSIR in fullOptJS).value.data
69-
val moduleInitializers = scalaJSModuleInitializers.value
70-
71-
Def.task {
72-
import scala.concurrent.ExecutionContext.Implicits.global
73-
74-
log.info("Fake full optimizing")
75-
val linker = (scalaJSLinker in fullOptJS).value
76-
val output = LinkerOutput(MemOutputFile())
77-
Await.result(
78-
linker.link(ir, moduleInitializers, output, sbtLogger2ToolsLogger(log)),
79-
Duration.Inf)
80-
}.tag((usesScalaJSLinkerTag in fullOptJS).value)
81-
}.value,
82-
83-
/* Depend on both fullOptJS and concurrentFakeFullOptJS, so that they
84-
* are hopefully executed in parallel (potentially, but they should be
85-
* blocked from actually doing so by the concurrent restrictions on
86-
* usesScalaJSLinkerTag).
87-
*/
88-
concurrentUseOfLinkerTest := {
89-
(fullOptJS.value, concurrentFakeFullOptJS.value)
90-
}
91-
)))
51+
)
9252

9353
lazy val testFrameworkCommonSettings = Def.settings(
9454
versionSettings,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.scalajs.sbtplugin.test
2+
3+
object Main {
4+
def main(args: Array[String]): Unit = println("Hello World")
5+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import scala.concurrent.Await
2+
import scala.concurrent.duration.Duration
3+
4+
import org.scalajs.linker.MemOutputFile
5+
import org.scalajs.linker.interface._
6+
import org.scalajs.sbtplugin.Loggers.sbtLogger2ToolsLogger
7+
8+
lazy val concurrentFakeFullOptJS = taskKey[Any]("")
9+
lazy val concurrentUseOfLinkerTest = taskKey[Any]("")
10+
11+
name := "Scala.js sbt test"
12+
13+
version := scalaJSVersion
14+
scalaVersion := "2.12.8"
15+
16+
enablePlugins(ScalaJSPlugin)
17+
18+
/* This hopefully exposes concurrent uses of the linker. If it fails/gets
19+
* flaky, there is a bug somewhere - #2202
20+
*/
21+
22+
// A fake fullOptJS that we will run concurrently with the true fullOptJS
23+
concurrentFakeFullOptJS := Def.taskDyn {
24+
val log = streams.value.log
25+
val ir = (scalaJSIR in Compile).value.data
26+
val moduleInitializers = (scalaJSModuleInitializers in Compile).value
27+
28+
Def.task {
29+
import scala.concurrent.ExecutionContext.Implicits.global
30+
31+
log.info("Fake full optimizing")
32+
val linker = (scalaJSLinker in Compile in fullOptJS).value
33+
val output = LinkerOutput(MemOutputFile())
34+
Await.result(
35+
linker.link(ir, moduleInitializers, output, sbtLogger2ToolsLogger(log)),
36+
Duration.Inf)
37+
}.tag((usesScalaJSLinkerTag in Compile in fullOptJS).value)
38+
}.value
39+
40+
/* Depend on both fullOptJS and concurrentFakeFullOptJS, so that they
41+
* are hopefully executed in parallel (potentially, but they should be
42+
* blocked from actually doing so by the concurrent restrictions on
43+
* usesScalaJSLinkerTag).
44+
*/
45+
concurrentUseOfLinkerTest := {
46+
(fullOptJS in Compile).value
47+
concurrentFakeFullOptJS.value
48+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.2.8
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % sys.props("plugin.version"))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
> concurrentUseOfLinkerTest

0 commit comments

Comments
 (0)