diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 237c6cd9a..e97f8f07a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -146,7 +146,7 @@ jobs: shell: bash run: | # ./sbt -v "dependencyTreeProj/publishLocal; scripted dependency-graph/*" - ./sbt -v --client "scripted dependency-management/* project-load/* java/* run/*" + ./sbt -v --client "scripted dependency-management/* project-load/* project-matrix/* java/* run/*" # ./sbt -v --client "scripted plugins/*" # ./sbt -v --client "scripted nio/*" - name: Build and test (4) diff --git a/build.sbt b/build.sbt index bab83f1a3..dcf98645b 100644 --- a/build.sbt +++ b/build.sbt @@ -11,7 +11,7 @@ import scala.util.Try // ThisBuild settings take lower precedence, // but can be shared across the multi projects. ThisBuild / version := { - val v = "2.0.0-alpha11-SNAPSHOT" + val v = "2.0.0-alpha12-SNAPSHOT" nightlyVersion.getOrElse(v) } ThisBuild / version2_13 := "2.0.0-alpha10-SNAPSHOT" diff --git a/main-settings/src/main/scala/sbt/std/KeyMacro.scala b/main-settings/src/main/scala/sbt/std/KeyMacro.scala index a2679140d..b59a4c534 100644 --- a/main-settings/src/main/scala/sbt/std/KeyMacro.scala +++ b/main-settings/src/main/scala/sbt/std/KeyMacro.scala @@ -57,7 +57,7 @@ private[sbt] object KeyMacro: private def errorMsg2: String = """project must be directly assigned to a val, such as `val x = project.in(file("core"))`.""" - private def definingValName(errorMsg: String)(using qctx: Quotes): Expr[String] = + private[sbt] def definingValName(errorMsg: String)(using qctx: Quotes): Expr[String] = val term = enclosingTerm if term.isValDef then Expr(term.name) else errorAndAbort(errorMsg) diff --git a/main/src/main/scala/sbt/BuildSyntax.scala b/main/src/main/scala/sbt/BuildSyntax.scala index 4226d358f..ad0825502 100644 --- a/main/src/main/scala/sbt/BuildSyntax.scala +++ b/main/src/main/scala/sbt/BuildSyntax.scala @@ -18,8 +18,8 @@ private[sbt] trait BuildSyntax: * Creates a new Project. This is a macro that expects to be assigned directly to a val. * The name of the val is used as the project ID and the name of the base directory of the project. */ - inline def project: Project = - ${ std.KeyMacro.projectImpl } + inline def project: Project = ${ std.KeyMacro.projectImpl } + inline def projectMatrix: ProjectMatrix = ${ ProjectMatrix.projectMatrixImpl } inline def settingKey[A1](inline description: String): SettingKey[A1] = ${ std.KeyMacro.settingKeyImpl[A1]('description) } inline def taskKey[A1](inline description: String): TaskKey[A1] = diff --git a/main/src/main/scala/sbt/Keys.scala b/main/src/main/scala/sbt/Keys.scala index edf906c26..a04d545b3 100644 --- a/main/src/main/scala/sbt/Keys.scala +++ b/main/src/main/scala/sbt/Keys.scala @@ -102,6 +102,10 @@ object Keys { val onComplete = Def.onComplete // settingKey[() => Unit]("Hook to run when task evaluation completes. The type of this setting is subject to change, pending the resolution of SI-2915.").withRank(DSetting) + // Project Matrix + val virtualAxes = settingKey[Seq[VirtualAxis]]("Virtual axes for the project") + val projectMatrixBaseDirectory = settingKey[File]("Base directory of the current project matrix") + // Command keys val historyPath = SettingKey(BasicKeys.historyPath) val shellPrompt = SettingKey(BasicKeys.shellPrompt) diff --git a/main/src/main/scala/sbt/ProjectMatrix.scala b/main/src/main/scala/sbt/ProjectMatrix.scala index 1e426bfdd..cca1bbafa 100644 --- a/main/src/main/scala/sbt/ProjectMatrix.scala +++ b/main/src/main/scala/sbt/ProjectMatrix.scala @@ -1,14 +1,20 @@ package sbt -package internal -import java.util.Locale +import sbt.* +import sbt.Keys.* +import sbt.io.IO +import sbt.librarymanagement.Configuration +import sbt.librarymanagement.Configurations.* +import sbt.librarymanagement.CrossVersion +import sbt.librarymanagement.ModuleID + +import java.io.File +import java.lang.reflect.InvocationTargetException import scala.collection.immutable.ListMap import scala.collection.mutable -import Keys._ +import scala.quoted.* +import scala.reflect.ClassTag import scala.util.Try -import sbt.internal.inc.ReflectUtilities - -import sbtprojectmatrix.ProjectMatrixKeys /** * A project matrix is an implementation of a composite project @@ -26,13 +32,13 @@ import sbtprojectmatrix.ProjectMatrixKeys sealed trait ProjectMatrix extends CompositeProject { def id: String - /** The base directory for the project matrix.*/ - def base: sbt.File + /** The base directory for the project matrix. */ + def base: File def withId(id: String): ProjectMatrix - /** Sets the base directory for this project matrix.*/ - def in(dir: sbt.File): ProjectMatrix + /** Sets the base directory for this project matrix. */ + def in(dir: File): ProjectMatrix /** Adds new configurations directly to this project. To override an existing configuration, use `overrideConfigs`. */ def configs(cs: Configuration*): ProjectMatrix @@ -41,7 +47,9 @@ sealed trait ProjectMatrix extends CompositeProject { def dependsOn(deps: MatrixClasspathDep[ProjectMatrixReference]*): ProjectMatrix /** Adds classpath dependencies on internal or external non-matrix projects. */ - def dependsOn(deps: ClasspathDep[ProjectReference]*)(implicit dummyImplicit: DummyImplicit): ProjectMatrix + def dependsOn(deps: ClasspathDep[ProjectReference]*)(implicit + dummyImplicit: DummyImplicit + ): ProjectMatrix /** * Adds projects to be aggregated. When a user requests a task to run on this project from the command line, @@ -78,54 +86,82 @@ sealed trait ProjectMatrix extends CompositeProject { * Otherwise, add custom rows for each scalaVersions. */ def customRow( - autoScalaLibrary: Boolean, - scalaVersions: Seq[String], - axisValues: Seq[VirtualAxis], - process: Project => Project + autoScalaLibrary: Boolean, + scalaVersions: Seq[String], + axisValues: Seq[VirtualAxis], + process: Project => Project ): ProjectMatrix def customRow( - scalaVersions: Seq[String], - axisValues: Seq[VirtualAxis], - process: Project => Project + scalaVersions: Seq[String], + axisValues: Seq[VirtualAxis], + process: Project => Project ): ProjectMatrix def customRow( - autoScalaLibrary: Boolean, - axisValues: Seq[VirtualAxis], - process: Project => Project + autoScalaLibrary: Boolean, + axisValues: Seq[VirtualAxis], + process: Project => Project ): ProjectMatrix def customRow( - scalaVersions: Seq[String], - axisValues: Seq[VirtualAxis], - settings: Seq[Setting[_]] + scalaVersions: Seq[String], + axisValues: Seq[VirtualAxis], + settings: Seq[Def.Setting[_]] ): ProjectMatrix def customRow( - autoScalaLibrary: Boolean, - axisValues: Seq[VirtualAxis], - settings: Seq[Setting[_]] + autoScalaLibrary: Boolean, + axisValues: Seq[VirtualAxis], + settings: Seq[Def.Setting[_]] ): ProjectMatrix def jvmPlatform(scalaVersions: Seq[String]): ProjectMatrix def jvmPlatform(autoScalaLibrary: Boolean): ProjectMatrix - def jvmPlatform(scalaVersions: Seq[String], settings: Seq[Setting[_]]): ProjectMatrix - def jvmPlatform(scalaVersions: Seq[String], axisValues: Seq[VirtualAxis], settings: Seq[Setting[_]]): ProjectMatrix - def jvmPlatform(scalaVersions: Seq[String], axisValues: Seq[VirtualAxis], configure: Project => Project): ProjectMatrix - def jvmPlatform(autoScalaLibrary: Boolean, scalaVersions: Seq[String], settings: Seq[Setting[_]]): ProjectMatrix + def jvmPlatform(scalaVersions: Seq[String], settings: Seq[Def.Setting[_]]): ProjectMatrix + def jvmPlatform( + scalaVersions: Seq[String], + axisValues: Seq[VirtualAxis], + settings: Seq[Def.Setting[_]] + ): ProjectMatrix + def jvmPlatform( + scalaVersions: Seq[String], + axisValues: Seq[VirtualAxis], + configure: Project => Project + ): ProjectMatrix + def jvmPlatform( + autoScalaLibrary: Boolean, + scalaVersions: Seq[String], + settings: Seq[Def.Setting[_]] + ): ProjectMatrix def jvm: ProjectFinder def jsPlatform(scalaVersions: Seq[String]): ProjectMatrix - def jsPlatform(scalaVersions: Seq[String], settings: Seq[Setting[_]]): ProjectMatrix - def jsPlatform(scalaVersions: Seq[String], axisValues: Seq[VirtualAxis], settings: Seq[Setting[_]]): ProjectMatrix - def jsPlatform(scalaVersions: Seq[String], axisValues: Seq[VirtualAxis], configure: Project => Project): ProjectMatrix + def jsPlatform(scalaVersions: Seq[String], settings: Seq[Def.Setting[_]]): ProjectMatrix + def jsPlatform( + scalaVersions: Seq[String], + axisValues: Seq[VirtualAxis], + settings: Seq[Def.Setting[_]] + ): ProjectMatrix + def jsPlatform( + scalaVersions: Seq[String], + axisValues: Seq[VirtualAxis], + configure: Project => Project + ): ProjectMatrix def js: ProjectFinder def nativePlatform(scalaVersions: Seq[String]): ProjectMatrix - def nativePlatform(scalaVersions: Seq[String], settings: Seq[Setting[_]]): ProjectMatrix - def nativePlatform(scalaVersions: Seq[String], axisValues: Seq[VirtualAxis], settings: Seq[Setting[_]]): ProjectMatrix - def nativePlatform(scalaVersions: Seq[String], axisValues: Seq[VirtualAxis], configure: Project => Project): ProjectMatrix + def nativePlatform(scalaVersions: Seq[String], settings: Seq[Def.Setting[_]]): ProjectMatrix + def nativePlatform( + scalaVersions: Seq[String], + axisValues: Seq[VirtualAxis], + settings: Seq[Def.Setting[_]] + ): ProjectMatrix + def nativePlatform( + scalaVersions: Seq[String], + axisValues: Seq[VirtualAxis], + configure: Project => Project + ): ProjectMatrix def native: ProjectFinder def defaultAxes(axes: VirtualAxis*): ProjectMatrix @@ -141,7 +177,8 @@ sealed trait ProjectMatrix extends CompositeProject { private[sbt] def resolveMatch(thatRow: ProjectMatrix.ProjectRow): ProjectReference } -/** Represents a reference to a project matrix with an optional configuration string. +/** + * Represents a reference to a project matrix with an optional configuration string. */ sealed trait MatrixClasspathDep[MR <: ProjectMatrixReference] { def matrix: MR; def configuration: Option[String] @@ -165,7 +202,8 @@ object ProjectMatrix { private[sbt] val allMatrices: mutable.Map[String, ProjectMatrix] = mutable.Map.empty - /** A row in the project matrix, typically representing a platform + Scala version. + /** + * A row in the project matrix, typically representing a platform + Scala version. */ final class ProjectRow( val autoScalaLibrary: Boolean, @@ -174,8 +212,8 @@ object ProjectMatrix { ) { def scalaVersionOpt: Option[String] = if (autoScalaLibrary) - (axisValues collect { - case sv: VirtualAxis.ScalaVersionAxis => sv.scalaVersion + (axisValues collect { case sv: VirtualAxis.ScalaVersionAxis => + sv.scalaVersion }).headOption else None @@ -203,7 +241,7 @@ object ProjectMatrix { private final class ProjectMatrixDef( val id: String, - val base: sbt.File, + val base: File, val scalaVersions: Seq[String], val rows: Seq[ProjectRow], val aggregate: Seq[ProjectMatrixReference], @@ -221,7 +259,8 @@ object ProjectMatrix { Map((for { r <- rows } yield { - val axes = r.axisValues.sortBy(_.suffixOrder) + val axes = r.axisValues + .sortBy(_.suffixOrder) .filterNot(isSortOfDefaultAxis) val idSuffix = axes.map(_.idSuffix).mkString("") val childId = self.id + idSuffix @@ -234,105 +273,110 @@ object ProjectMatrix { private def resolveMappings: ListMap[ProjectRow, Project] = { val projectIds = resolveProjectIds - - ListMap((for { - r <- rows - } yield { - val axes = r.axisValues.sortBy(_.suffixOrder) - val svDirSuffix = axes.map(_.directorySuffix).mkString("-") - val nonScalaDirSuffix = (axes filter { - case _: VirtualAxis.ScalaVersionAxis => false - case _ => true - }).map(_.directorySuffix).mkString("-") - - val platform = (axes collect { - case pa: VirtualAxis.PlatformAxis => pa - }).headOption.getOrElse(sys.error(s"platform axis is missing in $axes")) - val childId = projectIds(r) - val deps = dependencies.map { resolveMatrixDependency(_, r) } ++ nonMatrixDependencies - val aggs = aggregate.map { - case ref: LocalProjectMatrix => + def dirSuffix(axes: Seq[VirtualAxis]): String = + axes.map(_.directorySuffix).filter(_.nonEmpty).mkString("-") + val projects = + rows.map { r => + import VirtualAxis.* + val axes = r.axisValues.sortBy(_.suffixOrder) + val scalaDirSuffix = dirSuffix(axes) + val nonScalaDirSuffix = dirSuffix(axes.filterNot(_.isInstanceOf[ScalaVersionAxis])) + val nonScalaNorPlatformDirSuffix = + dirSuffix(axes.filterNot(_.isInstanceOf[ScalaVersionAxis | PlatformAxis])) + val platform = axes + .collect { case pa: VirtualAxis.PlatformAxis => + pa + } + .headOption + .getOrElse(sys.error(s"platform axis is missing in $axes")) + val childId = projectIds(r) + val deps = dependencies.map { resolveMatrixDependency(_, r) } ++ nonMatrixDependencies + val aggs = aggregate.map { case ref: LocalProjectMatrix => val other = lookupMatrix(ref) resolveMatrixAggregate(other, r) - } ++ nonMatrixAggregate - val dotSbtMatrix = new java.io.File(".sbt") / "matrix" - IO.createDirectory(dotSbtMatrix) - val p = Project(childId, dotSbtMatrix / childId) - .dependsOn(deps: _*) - .aggregate(aggs: _*) - .setPlugins(plugins) - .configs(configurations: _*) - .settings( - name := self.id - ) - .settings( - r.scalaVersionOpt match { - case Some(sv) => - List(Keys.scalaVersion := sv) - case _ => - List(Keys.autoScalaLibrary := false, Keys.crossPaths := false) - } - ) - .settings( - target := base.getAbsoluteFile / "target" / svDirSuffix.dropWhile(_ == '-'), - crossTarget := Keys.target.value, - sourceDirectory := base.getAbsoluteFile / "src", - unmanagedBase := base.getAbsoluteFile / "lib", - inConfig(Compile)(makeSources(nonScalaDirSuffix, svDirSuffix)), - inConfig(Test)(makeSources(nonScalaDirSuffix, svDirSuffix)), - projectDependencies := projectDependenciesTask.value, - ProjectMatrixKeys.virtualAxes := axes, - ProjectMatrixKeys.projectMatrixBaseDirectory := base, - ) - .settings(self.settings) - .configure(transforms: _*) + } ++ nonMatrixAggregate + val dotSbtMatrix = new java.io.File(".sbt") / "matrix" + IO.createDirectory(dotSbtMatrix) + val p = Project(childId, dotSbtMatrix / childId) + .dependsOn(deps: _*) + .aggregate(aggs: _*) + .setPlugins(plugins) + .configs(configurations: _*) + .settings( + name := self.id + ) + .settings( + r.scalaVersionOpt match { + case Some(sv) => + List(scalaVersion := sv) + case _ => + List(autoScalaLibrary := false, crossPaths := false) + } + ) + .settings( + outputPath := { + val o = outputPath.value + if nonScalaNorPlatformDirSuffix.nonEmpty then s"$o/$nonScalaNorPlatformDirSuffix" + else o + }, + sourceDirectory := base.getAbsoluteFile / "src", + unmanagedBase := base.getAbsoluteFile / "lib", + ProjectExtra.inConfig(Compile)(makeSources(nonScalaDirSuffix, scalaDirSuffix)), + ProjectExtra.inConfig(Test)(makeSources(nonScalaDirSuffix, scalaDirSuffix)), + projectDependencies := projectDependenciesTask.value, + virtualAxes := axes, + projectMatrixBaseDirectory := base, + ) + .settings(self.settings) + .configure(transforms: _*) - r -> r.process(p) - }): _*) + r -> r.process(p) + } + ListMap(projects*) } - // backport of https://github.com/sbt/sbt/pull/5767 - def projectDependenciesTask: Def.Initialize[Task[Seq[ModuleID]]] = - Def.task { - val orig = projectDependencies.value - val sbv = scalaBinaryVersion.value - val ref = thisProjectRef.value - val data = settingsData.value - val deps = buildDependencies.value - deps.classpath(ref) flatMap { dep => - for { - depProjId <- (dep.project / projectID).get(data) - depSBV <- (dep.project / scalaBinaryVersion).get(data) - depCross <- (dep.project / crossVersion).get(data) - } yield { - depCross match { - case b: CrossVersion.Binary if VirtualAxis.isScala2Scala3Sandwich(sbv, depSBV) => - depProjId - .withCrossVersion(CrossVersion.constant(depSBV)) - .withConfigurations(dep.configuration) - .withExplicitArtifacts(Vector.empty) - case _ => - depProjId.withConfigurations(dep.configuration).withExplicitArtifacts(Vector.empty) + // backport of https://github.com/sbt/sbt/pull/5767 + def projectDependenciesTask: Def.Initialize[Task[Seq[ModuleID]]] = + Def.task { + val orig = projectDependencies.value + val sbv = scalaBinaryVersion.value + val ref = thisProjectRef.value + val data = settingsData.value + val deps = buildDependencies.value + deps.classpath(ref) flatMap { dep => + for { + depProjId <- (dep.project / projectID).get(data) + depSBV <- (dep.project / scalaBinaryVersion).get(data) + depCross <- (dep.project / crossVersion).get(data) + } yield { + depCross match { + case b: CrossVersion.Binary if VirtualAxis.isScala2Scala3Sandwich(sbv, depSBV) => + depProjId + .withCrossVersion(CrossVersion.constant(depSBV)) + .withConfigurations(dep.configuration) + .withExplicitArtifacts(Vector.empty) + case _ => + depProjId.withConfigurations(dep.configuration).withExplicitArtifacts(Vector.empty) + } } } } - } override lazy val componentProjects: Seq[Project] = resolvedMappings.values.toList private def resolveMatrixAggregate( - other: ProjectMatrix, - thisRow: ProjectRow, + other: ProjectMatrix, + thisRow: ProjectRow, ): ProjectReference = other.resolveMatch(thisRow) private def resolveMatrixDependency( - dep: MatrixClasspathDep[ProjectMatrixReference], - thisRow: ProjectRow + dep: MatrixClasspathDep[ProjectMatrixReference], + thisRow: ProjectRow ): ClasspathDep[ProjectReference] = dep match { case MatrixClasspathDependency(matrix0: LocalProjectMatrix, configuration) => val other = lookupMatrix(matrix0) - ClasspathDependency(other.resolveMatch(thisRow), configuration) + ClasspathDep.ClasspathDependency(other.resolveMatch(thisRow), configuration) } // resolve to the closest match for the given row @@ -343,7 +387,7 @@ object ProjectMatrix { case _ => sys.error(s"no rows were found in $id matching $thatRow: $rows") } - private def makeSources(dirSuffix: String, svDirSuffix: String): Setting[_] = { + private def makeSources(dirSuffix: String, svDirSuffix: String): Def.Setting[_] = { unmanagedSourceDirectories ++= Seq( scalaSource.value.getParentFile / s"scala${dirSuffix}", scalaSource.value.getParentFile / s"scala$svDirSuffix", @@ -353,7 +397,7 @@ object ProjectMatrix { override def withId(id: String): ProjectMatrix = copy(id = id) - override def in(dir: sbt.File): ProjectMatrix = copy(base = dir) + override def in(dir: File): ProjectMatrix = copy(base = dir) override def configs(cs: Configuration*): ProjectMatrix = copy(configurations = configurations ++ cs) @@ -361,13 +405,17 @@ object ProjectMatrix { override def aggregate(refs: ProjectMatrixReference*): ProjectMatrix = copy(aggregate = (aggregate: Seq[ProjectMatrixReference]) ++ refs) - override def aggregate(refs: ProjectReference*)(implicit dummyImplicit: DummyImplicit): ProjectMatrix = + override def aggregate(refs: ProjectReference*)(implicit + dummyImplicit: DummyImplicit + ): ProjectMatrix = copy(nonMatrixAggregate = (nonMatrixAggregate: Seq[ProjectReference]) ++ refs) override def dependsOn(deps: MatrixClasspathDep[ProjectMatrixReference]*): ProjectMatrix = copy(dependencies = dependencies ++ deps) - override def dependsOn(deps: ClasspathDep[ProjectReference]*)(implicit dummyImplicit: DummyImplicit) = + override def dependsOn(deps: ClasspathDep[ProjectReference]*)(implicit + dummyImplicit: DummyImplicit + ) = copy(nonMatrixDependencies = nonMatrixDependencies ++ deps) /** Appends settings to the current settings sequence for this project. */ @@ -389,15 +437,30 @@ object ProjectMatrix { jvmPlatform(scalaVersions, Nil) override def jvmPlatform(autoScalaLibrary: Boolean): ProjectMatrix = jvmPlatform(autoScalaLibrary, Nil, Nil) - override def jvmPlatform(scalaVersions: Seq[String], settings: Seq[Setting[_]]): ProjectMatrix = + override def jvmPlatform( + scalaVersions: Seq[String], + settings: Seq[Def.Setting[_]] + ): ProjectMatrix = jvmPlatform(true, scalaVersions, settings) - override def jvmPlatform(autoScalaLibrary: Boolean, scalaVersions: Seq[String], settings: Seq[Setting[_]]): ProjectMatrix = + override def jvmPlatform( + autoScalaLibrary: Boolean, + scalaVersions: Seq[String], + settings: Seq[Def.Setting[_]] + ): ProjectMatrix = customRow(autoScalaLibrary, scalaVersions, Seq(VirtualAxis.jvm), { _.settings(settings) }) - - override def jvmPlatform(scalaVersions: Seq[String], axisValues: Seq[VirtualAxis], settings: Seq[Setting[_]]): ProjectMatrix = - customRow(true, scalaVersions, VirtualAxis.jvm +: axisValues, {_.settings(settings)}) - - override def jvmPlatform(scalaVersions: Seq[String], axisValues: Seq[VirtualAxis], configure: Project => Project): ProjectMatrix = + + override def jvmPlatform( + scalaVersions: Seq[String], + axisValues: Seq[VirtualAxis], + settings: Seq[Def.Setting[_]] + ): ProjectMatrix = + customRow(true, scalaVersions, VirtualAxis.jvm +: axisValues, { _.settings(settings) }) + + override def jvmPlatform( + scalaVersions: Seq[String], + axisValues: Seq[VirtualAxis], + configure: Project => Project + ): ProjectMatrix = customRow(true, scalaVersions, VirtualAxis.jvm +: axisValues, configure) override def jvm: ProjectFinder = new AxisBaseProjectFinder(Seq(VirtualAxis.jvm)) @@ -405,31 +468,57 @@ object ProjectMatrix { override def jsPlatform(scalaVersions: Seq[String]): ProjectMatrix = jsPlatform(scalaVersions, Nil) - private def enableScalaJSPlugin(project: Project): Project = - project.enablePlugins(scalajsPlugin(this.getClass.getClassLoader).getOrElse( - sys.error("""Scala.js plugin was not found. Add the sbt-scalajs plugin into project/plugins.sbt: + private def enableScalaJSPlugin(project: Project): Project = + project.enablePlugins( + scalajsPlugin(this.getClass.getClassLoader).getOrElse( + sys.error( + """Scala.js plugin was not found. Add the sbt-scalajs plugin into project/plugins.sbt: | addSbtPlugin("org.scala-js" % "sbt-scalajs" % "x.y.z") - |""".stripMargin) - )) + |""".stripMargin + ) + ) + ) + override def jsPlatform( + scalaVersions: Seq[String], + settings: Seq[Def.Setting[_]] + ): ProjectMatrix = + customRow( + true, + scalaVersions, + Seq(VirtualAxis.js), + project => enableScalaJSPlugin(project).settings(settings) + ) - override def jsPlatform(scalaVersions: Seq[String], settings: Seq[Setting[_]]): ProjectMatrix = - customRow(true, scalaVersions, Seq(VirtualAxis.js), - project => enableScalaJSPlugin(project).settings(settings)) - - override def jsPlatform(scalaVersions: Seq[String], axisValues: Seq[VirtualAxis], settings: Seq[Setting[_]]): ProjectMatrix = - customRow(true, scalaVersions, VirtualAxis.js +: axisValues, - project => enableScalaJSPlugin(project).settings(settings)) - - override def jsPlatform(scalaVersions: Seq[String], axisValues: Seq[VirtualAxis], configure: Project => Project): ProjectMatrix = - customRow(true, scalaVersions, VirtualAxis.js +: axisValues, - project => configure(enableScalaJSPlugin(project))) + override def jsPlatform( + scalaVersions: Seq[String], + axisValues: Seq[VirtualAxis], + settings: Seq[Def.Setting[_]] + ): ProjectMatrix = + customRow( + true, + scalaVersions, + VirtualAxis.js +: axisValues, + project => enableScalaJSPlugin(project).settings(settings) + ) + + override def jsPlatform( + scalaVersions: Seq[String], + axisValues: Seq[VirtualAxis], + configure: Project => Project + ): ProjectMatrix = + customRow( + true, + scalaVersions, + VirtualAxis.js +: axisValues, + project => configure(enableScalaJSPlugin(project)) + ) override def defaultAxes(axes: VirtualAxis*): ProjectMatrix = copy(defAxes = axes.toSeq) def scalajsPlugin(classLoader: ClassLoader): Try[AutoPlugin] = { - import sbtprojectmatrix.ReflectionUtil._ + import ReflectionUtil.* withContextClassloader(classLoader) { loader => getSingletonObject[AutoPlugin](loader, "org.scalajs.sbtplugin.ScalaJSPlugin$") } @@ -442,88 +531,126 @@ object ProjectMatrix { override def nativePlatform(scalaVersions: Seq[String]): ProjectMatrix = nativePlatform(scalaVersions, Nil) - private def enableScalaNativePlugin(project: Project): Project = - project.enablePlugins(nativePlugin(this.getClass.getClassLoader).getOrElse( - sys.error("""Scala Native plugin was not found. Add the sbt-scala-native plugin into project/plugins.sbt: + private def enableScalaNativePlugin(project: Project): Project = + project.enablePlugins( + nativePlugin(this.getClass.getClassLoader).getOrElse( + sys.error( + """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") - |""".stripMargin) - )) + |""".stripMargin + ) + ) + ) + override def nativePlatform( + scalaVersions: Seq[String], + settings: Seq[Def.Setting[_]] + ): ProjectMatrix = + customRow( + true, + scalaVersions, + Seq(VirtualAxis.native), + project => enableScalaNativePlugin(project).settings(settings) + ) - override def nativePlatform(scalaVersions: Seq[String], settings: Seq[Setting[_]]): ProjectMatrix = - customRow(true, scalaVersions, Seq(VirtualAxis.native), project => enableScalaNativePlugin(project).settings(settings)) - - override def nativePlatform(scalaVersions: Seq[String], axisValues: Seq[VirtualAxis], settings: Seq[Setting[_]]): ProjectMatrix = - customRow(true, scalaVersions, VirtualAxis.native +: axisValues, project => enableScalaNativePlugin(project).settings(settings)) + override def nativePlatform( + scalaVersions: Seq[String], + axisValues: Seq[VirtualAxis], + settings: Seq[Def.Setting[_]] + ): ProjectMatrix = + customRow( + true, + scalaVersions, + VirtualAxis.native +: axisValues, + project => enableScalaNativePlugin(project).settings(settings) + ) - override def nativePlatform(scalaVersions: Seq[String], axisValues: Seq[VirtualAxis], configure: Project => Project): ProjectMatrix = - customRow(true, scalaVersions, VirtualAxis.native +: axisValues, project => configure(enableScalaNativePlugin(project))) + override def nativePlatform( + scalaVersions: Seq[String], + axisValues: Seq[VirtualAxis], + configure: Project => Project + ): ProjectMatrix = + customRow( + true, + scalaVersions, + VirtualAxis.native +: axisValues, + project => configure(enableScalaNativePlugin(project)) + ) def nativePlugin(classLoader: ClassLoader): Try[AutoPlugin] = { - import sbtprojectmatrix.ReflectionUtil._ + import ReflectionUtil.* withContextClassloader(classLoader) { loader => getSingletonObject[AutoPlugin](loader, "scala.scalanative.sbtplugin.ScalaNativePlugin$") } } - override def projectRefs: Seq[ProjectReference] = - componentProjects map { case p => (p: ProjectReference) } + override def projectRefs: Seq[ProjectReference] = componentProjects.map(p => LocalProject(p.id)) override def filterProjects(axisValues: Seq[VirtualAxis]): Seq[Project] = resolvedMappings.toSeq collect { case (r, p) if axisValues.forall(v => r.axisValues.contains(v)) => p } - override def filterProjects(autoScalaLibrary: Boolean, axisValues: Seq[VirtualAxis]): Seq[Project] = + override def filterProjects( + autoScalaLibrary: Boolean, + axisValues: Seq[VirtualAxis] + ): Seq[Project] = resolvedMappings.toSeq collect { - case (r, p) if r.autoScalaLibrary == autoScalaLibrary && axisValues.forall(v => r.axisValues.contains(v)) => p + case (r, p) + if r.autoScalaLibrary == autoScalaLibrary && axisValues + .forall(v => r.axisValues.contains(v)) => + p } private final class AxisBaseProjectFinder(axisValues: Seq[VirtualAxis]) extends ProjectFinder { def get: Seq[Project] = filterProjects(axisValues) def apply(sv: String): Project = filterProjects(true, axisValues ++ Seq(VirtualAxis.scalaABIVersion(sv))).headOption - .getOrElse(sys.error(s"project matching $axisValues and $sv was not found")) + .getOrElse(sys.error(s"project matching $axisValues and $sv was not found")) def apply(autoScalaLibrary: Boolean): Project = filterProjects(autoScalaLibrary, axisValues).headOption - .getOrElse(sys.error(s"project matching $axisValues and $autoScalaLibrary was not found")) + .getOrElse(sys.error(s"project matching $axisValues and $autoScalaLibrary was not found")) } override def customRow( - scalaVersions: Seq[String], - axisValues: Seq[VirtualAxis], - settings: Seq[Setting[_]] + scalaVersions: Seq[String], + axisValues: Seq[VirtualAxis], + settings: Seq[Def.Setting[_]] ): ProjectMatrix = customRow(true, scalaVersions, axisValues, { _.settings(settings) }) override def customRow( - autoScalaLibrary: Boolean, - axisValues: Seq[VirtualAxis], - settings: Seq[Setting[_]] + autoScalaLibrary: Boolean, + axisValues: Seq[VirtualAxis], + settings: Seq[Def.Setting[_]] ): ProjectMatrix = customRow(autoScalaLibrary, Nil, axisValues, { _.settings(settings) }) override def customRow( - scalaVersions: Seq[String], - axisValues: Seq[VirtualAxis], - process: Project => Project + scalaVersions: Seq[String], + axisValues: Seq[VirtualAxis], + process: Project => Project ): ProjectMatrix = customRow(true, scalaVersions, axisValues, process) override def customRow( - autoScalaLibrary: Boolean, - scalaVersions: Seq[String], - axisValues: Seq[VirtualAxis], - process: Project => Project + autoScalaLibrary: Boolean, + scalaVersions: Seq[String], + axisValues: Seq[VirtualAxis], + process: Project => Project ): ProjectMatrix = if (autoScalaLibrary) { scalaVersions.foldLeft(this: ProjectMatrix) { (acc, sv) => - acc.customRow(autoScalaLibrary, axisValues ++ Seq(VirtualAxis.scalaABIVersion(sv)), process) + acc.customRow( + autoScalaLibrary, + axisValues ++ Seq(VirtualAxis.scalaABIVersion(sv)), + process + ) } } else { customRow(autoScalaLibrary, axisValues ++ Seq(VirtualAxis.jvm), process) } override def customRow( - autoScalaLibrary: Boolean, - axisValues: Seq[VirtualAxis], - process: Project => Project + autoScalaLibrary: Boolean, + axisValues: Seq[VirtualAxis], + process: Project => Project ): ProjectMatrix = { val newRow: ProjectRow = new ProjectRow(autoScalaLibrary, axisValues, process) copy(rows = this.rows :+ newRow) @@ -533,20 +660,20 @@ object ProjectMatrix { new AxisBaseProjectFinder(axisValues.toSeq) override def allProjects(): Seq[(Project, Seq[VirtualAxis])] = - resolvedMappings.map { case(row, project) => + resolvedMappings.map { case (row, project) => project -> row.axisValues }.toSeq def copy( id: String = id, - base: sbt.File = base, + base: File = base, scalaVersions: Seq[String] = scalaVersions, rows: Seq[ProjectRow] = rows, aggregate: Seq[ProjectMatrixReference] = aggregate, nonMatrixAggregate: Seq[ProjectReference] = nonMatrixAggregate, dependencies: Seq[MatrixClasspathDep[ProjectMatrixReference]] = dependencies, nonMatrixDependencies: Seq[ClasspathDep[ProjectReference]] = nonMatrixDependencies, - settings: Seq[Setting[_]] = settings, + settings: Seq[Def.Setting[_]] = settings, configurations: Seq[Configuration] = configurations, plugins: Plugins = plugins, transforms: Seq[Project => Project] = transforms, @@ -573,16 +700,30 @@ object ProjectMatrix { } // called by macro - def apply(id: String, base: sbt.File): ProjectMatrix = { + def apply(id: String, base: File): ProjectMatrix = { val defaultDefAxes = Seq(VirtualAxis.jvm, VirtualAxis.scalaABIVersion("2.13.3")) - val matrix = unresolved(id, base, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Plugins.Empty, Nil, defaultDefAxes) + val matrix = unresolved( + id, + base, + Nil, + Nil, + Nil, + Nil, + Nil, + Nil, + Nil, + Nil, + Plugins.Empty, + Nil, + defaultDefAxes + ) allMatrices(id) = matrix matrix } private[sbt] def unresolved( id: String, - base: sbt.File, + base: File, scalaVersions: Seq[String], rows: Seq[ProjectRow], aggregate: Seq[ProjectMatrixReference], @@ -618,16 +759,60 @@ object ProjectMatrix { implicit def projectMatrixToLocalProjectMatrix(m: ProjectMatrix): LocalProjectMatrix = LocalProjectMatrix(m.id) - import scala.reflect.macros._ + private object ReflectionUtil: + def getSingletonObject[A: ClassTag](classLoader: ClassLoader, className: String): Try[A] = + Try { + val clazz = classLoader.loadClass(className) + val t = implicitly[ClassTag[A]].runtimeClass + Option(clazz.getField("MODULE$").get(null)) match { + case None => + throw new ClassNotFoundException( + s"Unable to find $className using classloader: $classLoader" + ) + case Some(c) if !t.isInstance(c) => + throw new ClassCastException(s"${clazz.getName} is not a subtype of $t") + case Some(c) => c.asInstanceOf[A] + } + } + .recover { + case i: InvocationTargetException if i.getTargetException != null => + throw i.getTargetException + } - def projectMatrixMacroImpl(c: blackbox.Context): c.Expr[ProjectMatrix] = { - import c.universe._ - val enclosingValName = std.KeyMacro.definingValName( - c, - methodName => - s"""$methodName must be directly assigned to a val, such as `val x = $methodName`. Alternatively, you can use `sbt.ProjectMatrix.apply`""" + def objectExists(classLoader: ClassLoader, className: String): Boolean = + try { + classLoader.loadClass(className).getField("MODULE$").get(null) != null + } catch { + case _: Throwable => false + } + + def withContextClassloader[A](loader: ClassLoader)(body: ClassLoader => A): A = { + val current = Thread.currentThread().getContextClassLoader + try { + Thread.currentThread().setContextClassLoader(loader) + body(loader) + } finally Thread.currentThread().setContextClassLoader(current) + } + end ReflectionUtil + + def projectMatrixImpl(using Quotes): Expr[ProjectMatrix] = { + 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`" ) - val name = c.Expr[String](Literal(Constant(enclosingValName))) - reify { ProjectMatrix(name.splice, new sbt.File(name.splice)) } + '{ ProjectMatrix($name, new File($name)) } } } + +trait ProjectMatrixExtra: + given Conversion[ProjectMatrix, LocalProjectMatrix] = + m => LocalProjectMatrix(m.id) + + given [A](using + Conversion[A, ProjectMatrixReference] + ): Conversion[A, ProjectMatrix.MatrixClasspathDependency] = + ref => ProjectMatrix.MatrixClasspathDependency(ref, None) + + given [A](using + Conversion[A, ProjectMatrixReference] + ): Conversion[A, ProjectMatrix.ProjectMatrixReferenceSyntax] = + ref => ProjectMatrix.ProjectMatrixReferenceSyntax(ref) diff --git a/main/src/main/scala/sbt/ProjectMatrixPlugin.scala b/main/src/main/scala/sbt/ProjectMatrixPlugin.scala deleted file mode 100644 index 5fe5d8ac2..000000000 --- a/main/src/main/scala/sbt/ProjectMatrixPlugin.scala +++ /dev/null @@ -1,31 +0,0 @@ -package sbt - -import sbt._ -import internal._ -import java.util.concurrent.atomic.AtomicBoolean -import scala.language.experimental.macros - -trait ProjectMatrixKeys { - val virtualAxes = settingKey[Seq[VirtualAxis]]("Virtual axes for the project") - val projectMatrixBaseDirectory = settingKey[File]("Base directory of the current project matrix") -} - -object ProjectMatrixKeys extends ProjectMatrixKeys - -object ProjectMatrixPlugin extends AutoPlugin { - override val requires = sbt.plugins.CorePlugin - override val trigger = allRequirements - object autoImport extends ProjectMatrixKeys { - def projectMatrix: ProjectMatrix = macro ProjectMatrix.projectMatrixMacroImpl - - implicit def matrixClasspathDependency[T]( - m: T - )(implicit ev: T => ProjectMatrixReference): ProjectMatrix.MatrixClasspathDependency = - ProjectMatrix.MatrixClasspathDependency(m, None) - - implicit def matrixReferenceSyntax[T]( - m: T - )(implicit ev: T => ProjectMatrixReference): ProjectMatrix.ProjectMatrixReferenceSyntax = - new ProjectMatrix.ProjectMatrixReferenceSyntax(m) - } -} diff --git a/main/src/main/scala/sbt/ReflectionUtil.scala b/main/src/main/scala/sbt/ReflectionUtil.scala deleted file mode 100644 index 33c56d034..000000000 --- a/main/src/main/scala/sbt/ReflectionUtil.scala +++ /dev/null @@ -1,41 +0,0 @@ -package sbt - -import java.lang.reflect.InvocationTargetException -import scala.reflect.ClassTag -import scala.util.Try - -object ReflectionUtil { - def getSingletonObject[A: ClassTag](classLoader: ClassLoader, className: String): Try[A] = - Try { - val clazz = classLoader.loadClass(className) - val t = implicitly[ClassTag[A]].runtimeClass - Option(clazz.getField("MODULE$").get(null)) match { - case None => - throw new ClassNotFoundException( - s"Unable to find $className using classloader: $classLoader" - ) - case Some(c) if !t.isInstance(c) => - throw new ClassCastException(s"${clazz.getName} is not a subtype of $t") - case Some(c: A) => c - } - } - .recover { - case i: InvocationTargetException if i.getTargetException != null => - throw i.getTargetException - } - - def objectExists(classLoader: ClassLoader, className: String): Boolean = - try { - classLoader.loadClass(className).getField("MODULE$").get(null) != null - } catch { - case _: Throwable => false - } - - def withContextClassloader[A](loader: ClassLoader)(body: ClassLoader => A): A = { - val current = Thread.currentThread().getContextClassLoader - try { - Thread.currentThread().setContextClassLoader(loader) - body(loader) - } finally Thread.currentThread().setContextClassLoader(current) - } -} diff --git a/main/src/main/scala/sbt/internal/ProjectMatrixReference.scala b/main/src/main/scala/sbt/internal/ProjectMatrixReference.scala new file mode 100644 index 000000000..5ed710cda --- /dev/null +++ b/main/src/main/scala/sbt/internal/ProjectMatrixReference.scala @@ -0,0 +1,8 @@ +package sbt +package internal + +/** Identifies a project matrix. */ +sealed trait ProjectMatrixReference + +/** Identifies a project in the current build context. */ +final case class LocalProjectMatrix(id: String) extends ProjectMatrixReference diff --git a/sbt-app/src/main/scala/package.scala b/sbt-app/src/main/scala/package.scala index 9b9c3d9ab..c7c25051a 100644 --- a/sbt-app/src/main/scala/package.scala +++ b/sbt-app/src/main/scala/package.scala @@ -18,6 +18,7 @@ package object sbt with sbt.std.TaskExtra // with sbt.internal.util.Types with sbt.ProjectExtra + with sbt.ProjectMatrixExtra with sbt.librarymanagement.DependencyBuilders with sbt.librarymanagement.DependencyFilterExtra with sbt.librarymanagement.LibraryManagementSyntax diff --git a/sbt-app/src/sbt-test/project-matrix/custom/build.sbt b/sbt-app/src/sbt-test/project-matrix/custom/build.sbt index 10b14e863..d5bb325f5 100644 --- a/sbt-app/src/sbt-test/project-matrix/custom/build.sbt +++ b/sbt-app/src/sbt-test/project-matrix/custom/build.sbt @@ -4,7 +4,7 @@ ThisBuild / publishMavenStyle := true ThisBuild / ivyPaths := { val base = (ThisBuild / baseDirectory).value - IvyPaths(base, Some(base / "ivy-cache")) + IvyPaths(base.toString, s"$base/ivy-cache") } publish / skip := true diff --git a/sbt-app/src/sbt-test/project-matrix/custom/project/plugins.sbt b/sbt-app/src/sbt-test/project-matrix/custom/project/plugins.sbt deleted file mode 100644 index 4e80bbafc..000000000 --- a/sbt-app/src/sbt-test/project-matrix/custom/project/plugins.sbt +++ /dev/null @@ -1,5 +0,0 @@ -sys.props.get("plugin.version") match { - case Some(x) => addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % x) - case _ => sys.error("""|The system property 'plugin.version' is not defined. - |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) -} diff --git a/sbt-app/src/sbt-test/project-matrix/finder/test b/sbt-app/src/sbt-test/project-matrix/finder/pending similarity index 100% rename from sbt-app/src/sbt-test/project-matrix/finder/test rename to sbt-app/src/sbt-test/project-matrix/finder/pending diff --git a/sbt-app/src/sbt-test/project-matrix/finder/project/plugins.sbt b/sbt-app/src/sbt-test/project-matrix/finder/project/plugins.sbt index 60a69f1df..1a1034041 100644 --- a/sbt-app/src/sbt-test/project-matrix/finder/project/plugins.sbt +++ b/sbt-app/src/sbt-test/project-matrix/finder/project/plugins.sbt @@ -1,7 +1 @@ -sys.props.get("plugin.version") match { - case Some(x) => addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % x) - case _ => sys.error("""|The system property 'plugin.version' is not defined. - |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) -} - addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.3.0") diff --git a/sbt-app/src/sbt-test/project-matrix/java/build.sbt b/sbt-app/src/sbt-test/project-matrix/java/build.sbt index d4532995a..1b406f42c 100644 --- a/sbt-app/src/sbt-test/project-matrix/java/build.sbt +++ b/sbt-app/src/sbt-test/project-matrix/java/build.sbt @@ -4,7 +4,7 @@ ThisBuild / publishMavenStyle := true ThisBuild / ivyPaths := { val base = (ThisBuild / baseDirectory).value - IvyPaths(base, Some(base / "ivy-cache")) + IvyPaths(base.toString, s"$base/ivy-cache") } publish / skip := true diff --git a/sbt-app/src/sbt-test/project-matrix/java/project/plugins.sbt b/sbt-app/src/sbt-test/project-matrix/java/project/plugins.sbt deleted file mode 100644 index 4e80bbafc..000000000 --- a/sbt-app/src/sbt-test/project-matrix/java/project/plugins.sbt +++ /dev/null @@ -1,5 +0,0 @@ -sys.props.get("plugin.version") match { - case Some(x) => addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % x) - case _ => sys.error("""|The system property 'plugin.version' is not defined. - |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) -} diff --git a/sbt-app/src/sbt-test/project-matrix/js/test b/sbt-app/src/sbt-test/project-matrix/js/pending similarity index 100% rename from sbt-app/src/sbt-test/project-matrix/js/test rename to sbt-app/src/sbt-test/project-matrix/js/pending diff --git a/sbt-app/src/sbt-test/project-matrix/js/project/plugins.sbt b/sbt-app/src/sbt-test/project-matrix/js/project/plugins.sbt index 70858c7d8..e598c338c 100644 --- a/sbt-app/src/sbt-test/project-matrix/js/project/plugins.sbt +++ b/sbt-app/src/sbt-test/project-matrix/js/project/plugins.sbt @@ -1,6 +1 @@ -sys.props.get("plugin.version") match { - case Some(x) => addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % x) - case _ => sys.error("""|The system property 'plugin.version' is not defined. - |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) -} addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.27") diff --git a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/bar-app/D.scala b/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/bar-app/D.scala deleted file mode 100644 index b937ae06c..000000000 --- a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/bar-app/D.scala +++ /dev/null @@ -1,5 +0,0 @@ -package example - -object D { - val x = C.x -} diff --git a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/bar-core/C.scala b/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/bar-core/C.scala deleted file mode 100644 index 4d4fcc6df..000000000 --- a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/bar-core/C.scala +++ /dev/null @@ -1,5 +0,0 @@ -package example - -object C { - val x = 1 -} diff --git a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/baz-app/F.scala b/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/baz-app/F.scala deleted file mode 100644 index 5035ba457..000000000 --- a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/baz-app/F.scala +++ /dev/null @@ -1,5 +0,0 @@ -package example - -object F { - val x = E.x -} diff --git a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/baz-core/E.scala b/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/baz-core/E.scala deleted file mode 100644 index cdac7bd76..000000000 --- a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/baz-core/E.scala +++ /dev/null @@ -1,5 +0,0 @@ -package example - -object E { - val x = 1 -} diff --git a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/build.sbt b/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/build.sbt deleted file mode 100644 index 825f5215c..000000000 --- a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/build.sbt +++ /dev/null @@ -1,57 +0,0 @@ -lazy val check = taskKey[Unit]("") -lazy val scala3M1 = "3.0.0-M1" -lazy val scala3M2 = "3.0.0-M2" -lazy val scala213 = "2.13.4" - -lazy val fooApp = (projectMatrix in file("foo-app")) - .dependsOn(fooCore) - .settings( - name := "foo app", - ) - .jvmPlatform(scalaVersions = Seq(scala3M1, scala3M2)) - -lazy val fooApp3 = fooApp.jvm(scala3M1) - .settings( - test := { () }, - ) - -lazy val fooCore = (projectMatrix in file("foo-core")) - .settings( - name := "foo core", - ) - .jvmPlatform(scalaVersions = Seq(scala213, "2.12.12")) - -lazy val barApp = (projectMatrix in file("bar-app")) - .dependsOn(barCore) - .settings( - name := "bar app", - ) - .jvmPlatform(scalaVersions = Seq(scala213)) - -lazy val barCore = (projectMatrix in file("bar-core")) - .settings( - name := "bar core", - ) - .jvmPlatform(scalaVersions = Seq(scala3M2)) - -// choose 2.13 when bazCore offers both 2.13 and Dotty -lazy val bazApp = (projectMatrix in file("baz-app")) - .dependsOn(bazCore) - .settings( - name := "baz app", - check := { - val cp = (Compile / fullClasspath).value - .map(_.data.getName) - - assert(cp.contains("baz-core_2.13-0.1.0-SNAPSHOT.jar"), s"$cp") - assert(!cp.contains("baz-core_3.0.0-M1-0.1.0-SNAPSHOT.jar"), s"$cp") - }, - ) - .jvmPlatform(scalaVersions = Seq(scala213)) - -lazy val bazCore = (projectMatrix in file("baz-core")) - .settings( - name := "baz core", - exportJars := true, - ) - .jvmPlatform(scalaVersions = Seq(scala213, scala3M1)) diff --git a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/foo-app/B.scala b/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/foo-app/B.scala deleted file mode 100644 index ed82c07d1..000000000 --- a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/foo-app/B.scala +++ /dev/null @@ -1,5 +0,0 @@ -package example - -object B { - val x = A.x -} diff --git a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/foo-core/A.scala b/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/foo-core/A.scala deleted file mode 100644 index be4b82a9f..000000000 --- a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/foo-core/A.scala +++ /dev/null @@ -1,5 +0,0 @@ -package example - -object A { - val x = 1 -} diff --git a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/project/build.properties b/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/project/build.properties deleted file mode 100644 index c19c768d6..000000000 --- a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.4.2 diff --git a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/project/plugins.sbt b/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/project/plugins.sbt deleted file mode 100644 index 2db30a892..000000000 --- a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/project/plugins.sbt +++ /dev/null @@ -1,6 +0,0 @@ -sys.props.get("plugin.version") match { - case Some(x) => addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % x) - case _ => sys.error("""|The system property 'plugin.version' is not defined. - |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) -} -addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.4.5") diff --git a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/test b/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/test deleted file mode 100644 index 18ed59f1b..000000000 --- a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich-sbt-1.3/test +++ /dev/null @@ -1,7 +0,0 @@ -> projects - -> fooApp3_0_0_M1/compile - -> barApp/compile - -> bazApp/check diff --git a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich/build.sbt b/sbt-app/src/sbt-test/project-matrix/jvm-sandwich/build.sbt index 98c3f574a..41bac33a6 100644 --- a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich/build.sbt +++ b/sbt-app/src/sbt-test/project-matrix/jvm-sandwich/build.sbt @@ -35,12 +35,9 @@ lazy val bazApp = (projectMatrix in file("baz-app")) .settings( name := "baz app", check := { - val cp = (Compile / fullClasspath).value - .map(_.data.getName) - - streams.value.log.info(cp.toString) - assert(cp.contains("baz-core_2.13-0.1.0-SNAPSHOT.jar"), s"$cp") - assert(!cp.contains("baz-core_3.0.0-M1-0.1.0-SNAPSHOT.jar"), s"$cp") + val cp = (Compile / fullClasspath).value.map(_.data.id) + assert(cp.exists(_.endsWith("baz-core_2.13-0.1.0-SNAPSHOT.jar")), cp) + assert(!cp.exists(_.endsWith("baz-core_3.0.0-M1-0.1.0-SNAPSHOT.jar")), cp) assert(projectMatrixBaseDirectory.value == file("baz-app")) }, ) diff --git a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich/project/build.properties b/sbt-app/src/sbt-test/project-matrix/jvm-sandwich/project/build.properties deleted file mode 100644 index c19c768d6..000000000 --- a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.4.2 diff --git a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich/project/plugins.sbt b/sbt-app/src/sbt-test/project-matrix/jvm-sandwich/project/plugins.sbt deleted file mode 100644 index 2db30a892..000000000 --- a/sbt-app/src/sbt-test/project-matrix/jvm-sandwich/project/plugins.sbt +++ /dev/null @@ -1,6 +0,0 @@ -sys.props.get("plugin.version") match { - case Some(x) => addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % x) - case _ => sys.error("""|The system property 'plugin.version' is not defined. - |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) -} -addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.4.5") diff --git a/sbt-app/src/sbt-test/project-matrix/jvm-with-project-axes/build.sbt b/sbt-app/src/sbt-test/project-matrix/jvm-with-project-axes/build.sbt index 4a7e5f31b..fc47ace9f 100644 --- a/sbt-app/src/sbt-test/project-matrix/jvm-with-project-axes/build.sbt +++ b/sbt-app/src/sbt-test/project-matrix/jvm-with-project-axes/build.sbt @@ -1,11 +1,10 @@ -import sbt.internal.ProjectMatrix ThisBuild / organization := "com.example" ThisBuild / version := "0.1.0-SNAPSHOT" ThisBuild / publishMavenStyle := true ThisBuild / ivyPaths := { val base = (ThisBuild / baseDirectory).value - IvyPaths(base, Some(base / "ivy-cache")) + IvyPaths(base.toString, s"$base/ivy-cache") } publish / skip := true @@ -26,13 +25,14 @@ check := { lazy val app: ProjectMatrix = (projectMatrix in file("app")) .settings( name := "app", - ivyPaths := (ThisBuild / ivyPaths).value + ivyPaths := (ThisBuild / ivyPaths).value, + scalaVersion := scala212 ) .aggregate(domain) .dependsOn(domain) .customRow( autoScalaLibrary = false, - scalaVersions = Seq(scala212), + scalaVersions = Seq(), axisValues = Seq(config12, VirtualAxis.jvm), _.settings( libraryDependencies += "com.typesafe" % "config" % "1.2.1" @@ -40,7 +40,7 @@ lazy val app: ProjectMatrix = (projectMatrix in file("app")) ) .customRow( autoScalaLibrary = false, - scalaVersions = Seq(scala212), + scalaVersions = Seq(), axisValues = Seq(config13, VirtualAxis.jvm), _.settings( libraryDependencies += "com.typesafe" % "config" % "1.3.3" diff --git a/sbt-app/src/sbt-test/project-matrix/jvm-with-project-axes/project/plugins.sbt b/sbt-app/src/sbt-test/project-matrix/jvm-with-project-axes/project/plugins.sbt deleted file mode 100644 index 4e80bbafc..000000000 --- a/sbt-app/src/sbt-test/project-matrix/jvm-with-project-axes/project/plugins.sbt +++ /dev/null @@ -1,5 +0,0 @@ -sys.props.get("plugin.version") match { - case Some(x) => addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % x) - case _ => sys.error("""|The system property 'plugin.version' is not defined. - |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) -} diff --git a/sbt-app/src/sbt-test/project-matrix/jvm-with-project-axes/test b/sbt-app/src/sbt-test/project-matrix/jvm-with-project-axes/test index 29c0480b3..6c9a71daa 100644 --- a/sbt-app/src/sbt-test/project-matrix/jvm-with-project-axes/test +++ b/sbt-app/src/sbt-test/project-matrix/jvm-with-project-axes/test @@ -1,5 +1,5 @@ > compile -$ exists domain/target/scala-2.12/classes/a/DataType.class +$ exists target/out/jvm/scala-2.12.10/domain/backend/a/DataType.class > check diff --git a/sbt-app/src/sbt-test/project-matrix/jvm-with-scoping/project/plugins.sbt b/sbt-app/src/sbt-test/project-matrix/jvm-with-scoping/project/plugins.sbt deleted file mode 100644 index 4e80bbafc..000000000 --- a/sbt-app/src/sbt-test/project-matrix/jvm-with-scoping/project/plugins.sbt +++ /dev/null @@ -1,5 +0,0 @@ -sys.props.get("plugin.version") match { - case Some(x) => addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % x) - case _ => sys.error("""|The system property 'plugin.version' is not defined. - |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) -} diff --git a/sbt-app/src/sbt-test/project-matrix/jvm-with-scoping/test b/sbt-app/src/sbt-test/project-matrix/jvm-with-scoping/test index 4a2cee2d6..9c17bbfa5 100644 --- a/sbt-app/src/sbt-test/project-matrix/jvm-with-scoping/test +++ b/sbt-app/src/sbt-test/project-matrix/jvm-with-scoping/test @@ -1,6 +1,6 @@ > compile -$ exists core/target/jvm-2.13/classes/a/Core.class -$ exists core/target/jvm-2.12/classes/a/Core.class +$ exists target/out/jvm/scala-2.13.3/core/backend/a/Core.class +$ exists target/out/jvm/scala-2.12.12/core/backend/a/Core.class > core/check diff --git a/sbt-app/src/sbt-test/project-matrix/jvm/project/build.properties b/sbt-app/src/sbt-test/project-matrix/jvm/project/build.properties new file mode 100644 index 000000000..bfcd74646 --- /dev/null +++ b/sbt-app/src/sbt-test/project-matrix/jvm/project/build.properties @@ -0,0 +1 @@ +sbt.version=2.0.0-alpha12-SNAPSHOT diff --git a/sbt-app/src/sbt-test/project-matrix/jvm/project/plugins.sbt b/sbt-app/src/sbt-test/project-matrix/jvm/project/plugins.sbt deleted file mode 100644 index 4e80bbafc..000000000 --- a/sbt-app/src/sbt-test/project-matrix/jvm/project/plugins.sbt +++ /dev/null @@ -1,5 +0,0 @@ -sys.props.get("plugin.version") match { - case Some(x) => addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % x) - case _ => sys.error("""|The system property 'plugin.version' is not defined. - |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) -} diff --git a/sbt-app/src/sbt-test/project-matrix/jvm/test b/sbt-app/src/sbt-test/project-matrix/jvm/test index 4a2cee2d6..9c17bbfa5 100644 --- a/sbt-app/src/sbt-test/project-matrix/jvm/test +++ b/sbt-app/src/sbt-test/project-matrix/jvm/test @@ -1,6 +1,6 @@ > compile -$ exists core/target/jvm-2.13/classes/a/Core.class -$ exists core/target/jvm-2.12/classes/a/Core.class +$ exists target/out/jvm/scala-2.13.3/core/backend/a/Core.class +$ exists target/out/jvm/scala-2.12.12/core/backend/a/Core.class > core/check diff --git a/sbt-app/src/sbt-test/project-matrix/lib/build.sbt b/sbt-app/src/sbt-test/project-matrix/lib/build.sbt index 4ee7b633d..8a4cb65a2 100644 --- a/sbt-app/src/sbt-test/project-matrix/lib/build.sbt +++ b/sbt-app/src/sbt-test/project-matrix/lib/build.sbt @@ -13,3 +13,4 @@ lazy val ss = projectMatrix .jvmPlatform(scalaVersions = Seq("2.13.13")) lazy val strayJar = project + .settings(scalaVersion := "2.12.19") diff --git a/sbt-app/src/sbt-test/project-matrix/lib/project/plugins.sbt b/sbt-app/src/sbt-test/project-matrix/lib/project/plugins.sbt deleted file mode 100644 index 4e80bbafc..000000000 --- a/sbt-app/src/sbt-test/project-matrix/lib/project/plugins.sbt +++ /dev/null @@ -1,5 +0,0 @@ -sys.props.get("plugin.version") match { - case Some(x) => addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % x) - case _ => sys.error("""|The system property 'plugin.version' is not defined. - |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) -} diff --git a/sbt-app/src/sbt-test/project-matrix/lib/test b/sbt-app/src/sbt-test/project-matrix/lib/test index b55879894..5379ef8b1 100644 --- a/sbt-app/src/sbt-test/project-matrix/lib/test +++ b/sbt-app/src/sbt-test/project-matrix/lib/test @@ -6,10 +6,10 @@ # check root $ mkdir lib -$ copy-file strayJar/target/scala-2.12/strayjar_2.12-0.1.0-SNAPSHOT.jar lib/strayJar.jar +$ copy-file target/out/jvm/scala-2.12.19/strayjar/strayjar_2.12-0.1.0-SNAPSHOT.jar lib/strayJar.jar > root2_12/compile # check ss $ mkdir ss/lib -$ copy-file strayJar/target/scala-2.12/strayjar_2.12-0.1.0-SNAPSHOT.jar ss/lib/strayJar.jar +$ copy-file target/out/jvm/scala-2.12.19/strayjar/strayjar_2.12-0.1.0-SNAPSHOT.jar ss/lib/strayJar.jar > ss/compile diff --git a/sbt-app/src/sbt-test/project-matrix/native/test b/sbt-app/src/sbt-test/project-matrix/native/pending similarity index 100% rename from sbt-app/src/sbt-test/project-matrix/native/test rename to sbt-app/src/sbt-test/project-matrix/native/pending diff --git a/sbt-app/src/sbt-test/project-matrix/native/project/build.properties b/sbt-app/src/sbt-test/project-matrix/native/project/build.properties deleted file mode 100644 index dc8f331cc..000000000 --- a/sbt-app/src/sbt-test/project-matrix/native/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version = 1.4.3 diff --git a/sbt-app/src/sbt-test/project-matrix/native/project/plugins.sbt b/sbt-app/src/sbt-test/project-matrix/native/project/plugins.sbt index cb79d7dae..2f4e38aae 100644 --- a/sbt-app/src/sbt-test/project-matrix/native/project/plugins.sbt +++ b/sbt-app/src/sbt-test/project-matrix/native/project/plugins.sbt @@ -1,6 +1 @@ -sys.props.get("plugin.version") match { - case Some(x) => addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % x) - case _ => sys.error("""|The system property 'plugin.version' is not defined. - |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) -} addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.0") diff --git a/sbt-app/src/sbt-test/project-matrix/projectAxes/test b/sbt-app/src/sbt-test/project-matrix/projectAxes/pending similarity index 100% rename from sbt-app/src/sbt-test/project-matrix/projectAxes/test rename to sbt-app/src/sbt-test/project-matrix/projectAxes/pending diff --git a/sbt-app/src/sbt-test/project-matrix/projectAxes/project/plugins.sbt b/sbt-app/src/sbt-test/project-matrix/projectAxes/project/plugins.sbt index 60a69f1df..1a1034041 100644 --- a/sbt-app/src/sbt-test/project-matrix/projectAxes/project/plugins.sbt +++ b/sbt-app/src/sbt-test/project-matrix/projectAxes/project/plugins.sbt @@ -1,7 +1 @@ -sys.props.get("plugin.version") match { - case Some(x) => addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % x) - case _ => sys.error("""|The system property 'plugin.version' is not defined. - |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) -} - addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.3.0")