mirror of https://github.com/sbt/sbt.git
Merge pull request #7708 from adpi2/2.x-fix-7706
[2.x] Fix loading of `ScalaJSPlugin` in `ProjectMatrix`
This commit is contained in:
commit
a4ef38c5da
|
|
@ -347,8 +347,6 @@ object Scoped:
|
||||||
protected def onTask[A2](f: Task[A1] => Task[A2]): Initialize[Task[A2]] =
|
protected def onTask[A2](f: Task[A1] => Task[A2]): Initialize[Task[A2]] =
|
||||||
init.apply(f)
|
init.apply(f)
|
||||||
|
|
||||||
def dependsOn(tasks: Initialize[? <: Task[?]]*): Initialize[Task[A1]] =
|
|
||||||
init.zipWith(tasks.asInstanceOf[Seq[Initialize[Task[?]]]].join)(_.dependsOn(_*))
|
|
||||||
def flatMapTaskValue[T](f: A1 => Task[T]): Initialize[Task[T]] =
|
def flatMapTaskValue[T](f: A1 => Task[T]): Initialize[Task[T]] =
|
||||||
onTask(_.result flatMap (f compose successM))
|
onTask(_.result flatMap (f compose successM))
|
||||||
def map[A2](f: A1 => A2): Initialize[Task[A2]] =
|
def map[A2](f: A1 => A2): Initialize[Task[A2]] =
|
||||||
|
|
@ -363,6 +361,8 @@ object Scoped:
|
||||||
def tagw(tags: (Tag, Int)*): Initialize[Task[A1]] = onTask(_.tagw(tags: _*))
|
def tagw(tags: (Tag, Int)*): Initialize[Task[A1]] = onTask(_.tagw(tags: _*))
|
||||||
|
|
||||||
// Task-specific extensions
|
// Task-specific extensions
|
||||||
|
def dependsOn(tasks: Initialize[? <: Task[?]]*): Initialize[Task[A1]] =
|
||||||
|
init.zipWith(tasks.asInstanceOf[Seq[Initialize[Task[?]]]].join)(_.dependsOn(_*))
|
||||||
def dependsOnTask[A2](task1: Initialize[Task[A2]]): Initialize[Task[A1]] =
|
def dependsOnTask[A2](task1: Initialize[Task[A2]]): Initialize[Task[A1]] =
|
||||||
dependsOnSeq(Seq[AnyInitTask](task1.asInstanceOf[AnyInitTask]))
|
dependsOnSeq(Seq[AnyInitTask](task1.asInstanceOf[AnyInitTask]))
|
||||||
def dependsOnSeq(tasks: Seq[AnyInitTask]): Initialize[Task[A1]] =
|
def dependsOnSeq(tasks: Seq[AnyInitTask]): Initialize[Task[A1]] =
|
||||||
|
|
@ -408,6 +408,11 @@ object Scoped:
|
||||||
def tagw(tags: (Tag, Int)*): Initialize[InputTask[A1]] = onTask(_.tagw(tags: _*))
|
def tagw(tags: (Tag, Int)*): Initialize[InputTask[A1]] = onTask(_.tagw(tags: _*))
|
||||||
|
|
||||||
// InputTask specific extensions
|
// InputTask specific extensions
|
||||||
|
@targetName("dependsOnInitializeInputTask")
|
||||||
|
def dependsOn(tasks: Initialize[? <: Task[?]]*): Initialize[InputTask[A1]] =
|
||||||
|
init.zipWith(tasks.asInstanceOf[Seq[Initialize[Task[?]]]].join)((thisTask, deps) =>
|
||||||
|
thisTask.mapTask(_.dependsOn(deps*))
|
||||||
|
)
|
||||||
@targetName("dependsOnTaskInitializeInputTask")
|
@targetName("dependsOnTaskInitializeInputTask")
|
||||||
def dependsOnTask[B1](task1: Initialize[Task[B1]]): Initialize[InputTask[A1]] =
|
def dependsOnTask[B1](task1: Initialize[Task[B1]]): Initialize[InputTask[A1]] =
|
||||||
dependsOnSeq(Seq[AnyInitTask](task1.asInstanceOf[AnyInitTask]))
|
dependsOnSeq(Seq[AnyInitTask](task1.asInstanceOf[AnyInitTask]))
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,11 @@ private[sbt] object KeyMacro:
|
||||||
if term.isValDef then Expr(term.name)
|
if term.isValDef then Expr(term.name)
|
||||||
else errorAndAbort(errorMsg)
|
else errorAndAbort(errorMsg)
|
||||||
|
|
||||||
def enclosingTerm(using qctx: Quotes) =
|
private[sbt] def callerThis(using Quotes): Expr[Any] =
|
||||||
|
import quotes.reflect.*
|
||||||
|
This(enclosingClass).asExpr
|
||||||
|
|
||||||
|
private def enclosingTerm(using qctx: Quotes) =
|
||||||
import qctx.reflect._
|
import qctx.reflect._
|
||||||
def enclosingTerm0(sym: Symbol): Symbol =
|
def enclosingTerm0(sym: Symbol): Symbol =
|
||||||
sym match
|
sym match
|
||||||
|
|
@ -70,4 +74,11 @@ private[sbt] object KeyMacro:
|
||||||
case sym if !sym.isTerm => enclosingTerm0(sym.owner)
|
case sym if !sym.isTerm => enclosingTerm0(sym.owner)
|
||||||
case _ => sym
|
case _ => sym
|
||||||
enclosingTerm0(Symbol.spliceOwner)
|
enclosingTerm0(Symbol.spliceOwner)
|
||||||
|
|
||||||
|
private def enclosingClass(using Quotes) =
|
||||||
|
import quotes.reflect.*
|
||||||
|
def rec(sym: Symbol): Symbol =
|
||||||
|
if sym.isClassDef then sym
|
||||||
|
else rec(sym.owner)
|
||||||
|
rec(Symbol.spliceOwner)
|
||||||
end KeyMacro
|
end KeyMacro
|
||||||
|
|
|
||||||
|
|
@ -253,6 +253,7 @@ object ProjectMatrix {
|
||||||
val plugins: Plugins,
|
val plugins: Plugins,
|
||||||
val transforms: Seq[Project => Project],
|
val transforms: Seq[Project => Project],
|
||||||
val defAxes: Seq[VirtualAxis],
|
val defAxes: Seq[VirtualAxis],
|
||||||
|
val pluginClassLoader: ClassLoader
|
||||||
) extends ProjectMatrix { self =>
|
) extends ProjectMatrix { self =>
|
||||||
lazy val resolvedMappings: ListMap[ProjectRow, Project] = resolveMappings
|
lazy val resolvedMappings: ListMap[ProjectRow, Project] = resolveMappings
|
||||||
private def resolveProjectIds: Map[ProjectRow, String] = {
|
private def resolveProjectIds: Map[ProjectRow, String] = {
|
||||||
|
|
@ -470,7 +471,7 @@ object ProjectMatrix {
|
||||||
|
|
||||||
private def enableScalaJSPlugin(project: Project): Project =
|
private def enableScalaJSPlugin(project: Project): Project =
|
||||||
project.enablePlugins(
|
project.enablePlugins(
|
||||||
scalajsPlugin(this.getClass.getClassLoader).getOrElse(
|
scalajsPlugin.getOrElse(
|
||||||
sys.error(
|
sys.error(
|
||||||
"""Scala.js plugin was not found. Add the sbt-scalajs plugin into project/plugins.sbt:
|
"""Scala.js plugin was not found. Add the sbt-scalajs plugin into project/plugins.sbt:
|
||||||
| addSbtPlugin("org.scala-js" % "sbt-scalajs" % "x.y.z")
|
| addSbtPlugin("org.scala-js" % "sbt-scalajs" % "x.y.z")
|
||||||
|
|
@ -517,9 +518,9 @@ object ProjectMatrix {
|
||||||
override def defaultAxes(axes: VirtualAxis*): ProjectMatrix =
|
override def defaultAxes(axes: VirtualAxis*): ProjectMatrix =
|
||||||
copy(defAxes = axes.toSeq)
|
copy(defAxes = axes.toSeq)
|
||||||
|
|
||||||
def scalajsPlugin(classLoader: ClassLoader): Try[AutoPlugin] = {
|
def scalajsPlugin: Try[AutoPlugin] = {
|
||||||
import ReflectionUtil.*
|
import ReflectionUtil.*
|
||||||
withContextClassloader(classLoader) { loader =>
|
withContextClassloader(pluginClassLoader) { loader =>
|
||||||
getSingletonObject[AutoPlugin](loader, "org.scalajs.sbtplugin.ScalaJSPlugin$")
|
getSingletonObject[AutoPlugin](loader, "org.scalajs.sbtplugin.ScalaJSPlugin$")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -533,7 +534,7 @@ object ProjectMatrix {
|
||||||
|
|
||||||
private def enableScalaNativePlugin(project: Project): Project =
|
private def enableScalaNativePlugin(project: Project): Project =
|
||||||
project.enablePlugins(
|
project.enablePlugins(
|
||||||
nativePlugin(this.getClass.getClassLoader).getOrElse(
|
nativePlugin.getOrElse(
|
||||||
sys.error(
|
sys.error(
|
||||||
"""Scala Native plugin was not found. Add the sbt-scala-native plugin into project/plugins.sbt:
|
"""Scala Native plugin was not found. Add the sbt-scala-native plugin into project/plugins.sbt:
|
||||||
| addSbtPlugin("org.scala-native" % "sbt-scala-native" % "x.y.z")
|
| addSbtPlugin("org.scala-native" % "sbt-scala-native" % "x.y.z")
|
||||||
|
|
@ -577,9 +578,9 @@ object ProjectMatrix {
|
||||||
project => configure(enableScalaNativePlugin(project))
|
project => configure(enableScalaNativePlugin(project))
|
||||||
)
|
)
|
||||||
|
|
||||||
def nativePlugin(classLoader: ClassLoader): Try[AutoPlugin] = {
|
def nativePlugin: Try[AutoPlugin] = {
|
||||||
import ReflectionUtil.*
|
import ReflectionUtil.*
|
||||||
withContextClassloader(classLoader) { loader =>
|
withContextClassloader(pluginClassLoader) { loader =>
|
||||||
getSingletonObject[AutoPlugin](loader, "scala.scalanative.sbtplugin.ScalaNativePlugin$")
|
getSingletonObject[AutoPlugin](loader, "scala.scalanative.sbtplugin.ScalaNativePlugin$")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -678,6 +679,7 @@ object ProjectMatrix {
|
||||||
plugins: Plugins = plugins,
|
plugins: Plugins = plugins,
|
||||||
transforms: Seq[Project => Project] = transforms,
|
transforms: Seq[Project => Project] = transforms,
|
||||||
defAxes: Seq[VirtualAxis] = defAxes,
|
defAxes: Seq[VirtualAxis] = defAxes,
|
||||||
|
pluginClassLoader: ClassLoader = pluginClassLoader,
|
||||||
): ProjectMatrix = {
|
): ProjectMatrix = {
|
||||||
val matrix = unresolved(
|
val matrix = unresolved(
|
||||||
id,
|
id,
|
||||||
|
|
@ -693,6 +695,7 @@ object ProjectMatrix {
|
||||||
plugins,
|
plugins,
|
||||||
transforms,
|
transforms,
|
||||||
defAxes,
|
defAxes,
|
||||||
|
pluginClassLoader
|
||||||
)
|
)
|
||||||
allMatrices(id) = matrix
|
allMatrices(id) = matrix
|
||||||
matrix
|
matrix
|
||||||
|
|
@ -700,7 +703,7 @@ object ProjectMatrix {
|
||||||
}
|
}
|
||||||
|
|
||||||
// called by macro
|
// called by macro
|
||||||
def apply(id: String, base: File): ProjectMatrix = {
|
def apply(id: String, base: File, pluginClassLoader: ClassLoader): ProjectMatrix = {
|
||||||
val defaultDefAxes = Seq(VirtualAxis.jvm, VirtualAxis.scalaABIVersion("3.3.3"))
|
val defaultDefAxes = Seq(VirtualAxis.jvm, VirtualAxis.scalaABIVersion("3.3.3"))
|
||||||
val matrix = unresolved(
|
val matrix = unresolved(
|
||||||
id,
|
id,
|
||||||
|
|
@ -715,7 +718,8 @@ object ProjectMatrix {
|
||||||
Nil,
|
Nil,
|
||||||
Plugins.Empty,
|
Plugins.Empty,
|
||||||
Nil,
|
Nil,
|
||||||
defaultDefAxes
|
defaultDefAxes,
|
||||||
|
pluginClassLoader
|
||||||
)
|
)
|
||||||
allMatrices(id) = matrix
|
allMatrices(id) = matrix
|
||||||
matrix
|
matrix
|
||||||
|
|
@ -735,6 +739,7 @@ object ProjectMatrix {
|
||||||
plugins: Plugins,
|
plugins: Plugins,
|
||||||
transforms: Seq[Project => Project],
|
transforms: Seq[Project => Project],
|
||||||
defAxes: Seq[VirtualAxis],
|
defAxes: Seq[VirtualAxis],
|
||||||
|
pluginClassLoader: ClassLoader
|
||||||
): ProjectMatrix =
|
): ProjectMatrix =
|
||||||
new ProjectMatrixDef(
|
new ProjectMatrixDef(
|
||||||
id,
|
id,
|
||||||
|
|
@ -750,6 +755,7 @@ object ProjectMatrix {
|
||||||
plugins,
|
plugins,
|
||||||
transforms,
|
transforms,
|
||||||
defAxes,
|
defAxes,
|
||||||
|
pluginClassLoader
|
||||||
)
|
)
|
||||||
|
|
||||||
def lookupMatrix(local: LocalProjectMatrix): ProjectMatrix = {
|
def lookupMatrix(local: LocalProjectMatrix): ProjectMatrix = {
|
||||||
|
|
@ -799,7 +805,8 @@ object ProjectMatrix {
|
||||||
val name = std.KeyMacro.definingValName(
|
val name = std.KeyMacro.definingValName(
|
||||||
"projectMatrix must be directly assigned to a val, such as `val x = projectMatrix`. Alternatively, you can use `sbt.ProjectMatrix.apply`"
|
"projectMatrix must be directly assigned to a val, such as `val x = projectMatrix`. Alternatively, you can use `sbt.ProjectMatrix.apply`"
|
||||||
)
|
)
|
||||||
'{ ProjectMatrix($name, new File($name)) }
|
val callerThis = std.KeyMacro.callerThis
|
||||||
|
'{ ProjectMatrix($name, new File($name), $callerThis.getClass.getClassLoader) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue