Skip to content

Commit

Permalink
Add means to shim out sbt-project-matrix for IntelliJ import
Browse files Browse the repository at this point in the history
  • Loading branch information
retronym authored and dwijnand committed Aug 19, 2020
1 parent 1a64c61 commit 3cca854
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 27 deletions.
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ with a newer version of them, you can do it with:
$ sbt -Dsbtio.path=../io -Dsbtutil.path=../util
```

### Working in IntelliJ

The SBT build for Zinc uses [sbt-project-matrix](https://github.com/sbt/sbt-projectmatrix) to cross build certain subprojects
selectively with different Scala versions. Unfortunately this confused the IntelliJ project import.

As a workaround, uncomment the import in the `== INTELLIJ IMPORT ==` section of `build.sbt` prior to importing
into IntelliJ. This will specialize the build structure to a single Scala version.

## Signing the CLA

Contributing to Zinc requires you or your employer to sign the
Expand Down
64 changes: 37 additions & 27 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import localzinc.Scripted, Scripted._
import com.typesafe.tools.mima.core._, ProblemFilters._
import com.github.os72.protocjar.Protoc

// == INTELLIJ IMPORT ==
//
// Uncomment this line to remove usage of sbt-project-matrix by specializing scalaVersion := 2.12
// Ideally we could replace this with: `SettingKey[Boolean]("ideSkipProject") := scalaVersion.value != defaultScalaVersion`
// in `commonSettings`, but when I tried this the IntelliJ import fails with `Cannot find project dependency: compilerBridgeJVM2_13`
// See: https://github.com/sbt/sbt-projectmatrix/issues/25
//
// This hack is documented in CONTRIBUTING.md, please keep that in sync.
// import ProjectMatrixShims.{ projectMatrix, _ }

def zincRootPath: File = file(sys.props.getOrElse("sbtzinc.path", ".")).getCanonicalFile
def internalPath = zincRootPath / "internal"

Expand Down Expand Up @@ -127,23 +137,23 @@ val noPublish: Seq[Setting[_]] = List(
)

// zincRoot is now only 2.12 (2.11.x is not supported anymore)
lazy val aggregated: Seq[ProjectReference] = compilerInterface.projectRefs ++
compilerBridge.projectRefs ++
zincApiInfo.projectRefs ++
zincBenchmarks.projectRefs ++
zincClasspath.projectRefs ++
zincClassfile.projectRefs ++
zincCompileCore.projectRefs ++
zincCompile.projectRefs ++
zincCore.projectRefs ++
zincPersist.projectRefs ++
Seq(zincPersistCore: ProjectReference) ++
zincPersistCoreAssembly.projectRefs ++
zincTesting.projectRefs ++
zinc.projectRefs

lazy val zincRoot: Project = (project in file("."))
.aggregate(
compilerInterface.projectRefs ++
compilerBridge.projectRefs ++
zincApiInfo.projectRefs ++
zincBenchmarks.projectRefs ++
zincClasspath.projectRefs ++
zincClassfile.projectRefs ++
zincCompileCore.projectRefs ++
zincCompile.projectRefs ++
zincCore.projectRefs ++
zincPersist.projectRefs ++
Seq(zincPersistCore: ProjectReference) ++
zincPersistCoreAssembly.projectRefs ++
zincTesting.projectRefs ++
zinc.projectRefs: _*
)
.aggregate(aggregated: _*)
.settings(
baseSettings,
name := "zinc Root",
Expand Down Expand Up @@ -205,7 +215,7 @@ lazy val zinc = (projectMatrix in (zincRootPath / "zinc"))
exclude[IncompatibleResultTypeProblem]("sbt.internal.*"),
)
)
.jvmPlatform(scalaVersions = List(scala212, scala213))
.jvmPlatform(scalaVersions = scala212_213)
.configure(addBaseSettingsAndTestDeps)

def resGenFile = (zincRootPath / "zinc" / "resGenerator").getAbsoluteFile
Expand Down Expand Up @@ -241,7 +251,7 @@ lazy val zincCompile = (projectMatrix in zincRootPath / "zinc-compile")
exclude[ReversedMissingMethodProblem]("sbt.inc.Doc*"),
),
)
.jvmPlatform(scalaVersions = List(scala212, scala213))
.jvmPlatform(scalaVersions = scala212_213)
.configure(addBaseSettingsAndTestDeps, addSbtUtilTracking)

// Persists the incremental data structures using Protobuf
Expand Down Expand Up @@ -277,7 +287,7 @@ lazy val zincPersist = (projectMatrix in internalPath / "zinc-persist")
exclude[IncompatibleTemplateDefProblem]("sbt.internal.inc.schema.*"),
),
)
.jvmPlatform(scalaVersions = List(scala212, scala213))
.jvmPlatform(scalaVersions = scala212_213)
.configure(addBaseSettingsAndTestDeps)

lazy val zincPersistCoreAssembly = (projectMatrix in internalPath / "zinc-persist-core-assembly")
Expand Down Expand Up @@ -351,7 +361,7 @@ lazy val zincCore = (projectMatrix in internalPath / "zinc-core")
}
},
)
.jvmPlatform(scalaVersions = List(scala212, scala213))
.jvmPlatform(scalaVersions = scala212_213)
.configure(addBaseSettingsAndTestDeps, addSbtIO, addSbtUtilLogging, addSbtUtilRelation)

lazy val zincBenchmarks = (projectMatrix in internalPath / "zinc-benchmarks")
Expand All @@ -367,7 +377,7 @@ lazy val zincBenchmarks = (projectMatrix in internalPath / "zinc-benchmarks")
),
Test / javaOptions ++= List("-Xmx600M", "-Xms600M"),
)
.jvmPlatform(scalaVersions = List(scala212, scala213))
.jvmPlatform(scalaVersions = scala212_213)

// sbt-side interface to compiler. Calls compiler-side interface reflectively
lazy val zincCompileCore = (projectMatrix in internalPath / "zinc-compile-core")
Expand Down Expand Up @@ -455,7 +465,7 @@ lazy val compilerInterface = (projectMatrix in internalPath / "compiler-interfac
),
)
.jvmPlatform(autoScalaLibrary = false)
.configure(addSbtUtilInterface)
.configure(addSbtUtilInterface(_))

/**
* Compiler-side interface to compiler that is compiled against the compiler being used either in advance or on the fly.
Expand Down Expand Up @@ -488,7 +498,7 @@ lazy val compilerBridge = (projectMatrix in internalPath / "compiler-bridge")
case (2, y) if y >= 13 => new File(scalaSource.value.getPath + "_2.13")
}.toList),
)
.jvmPlatform(scalaVersions = Seq(scala210, scala211, scala212, scala213))
.jvmPlatform(scalaVersions = allScalaVersions)

lazy val compilerBridge210 = compilerBridge.jvm(scala210)
lazy val compilerBridge211 = compilerBridge.jvm(scala211)
Expand Down Expand Up @@ -554,8 +564,8 @@ lazy val zincApiInfo = (projectMatrix in internalPath / "zinc-apiinfo")
exclude[DirectMissingMethodProblem]("sbt.internal.inc.ClassToAPI.handleMalformedNameOf*"),
),
)
.jvmPlatform(scalaVersions = List(scala212, scala213))
.configure(addBaseSettingsAndTestDeps)
.jvmPlatform(scalaVersions = scala212_213)
.configure(addBaseSettingsAndTestDeps(_))

// Utilities related to reflection, managing Scala versions, and custom class loaders
lazy val zincClasspath = (projectMatrix in internalPath / "zinc-classpath")
Expand Down Expand Up @@ -584,7 +594,7 @@ lazy val zincClasspath = (projectMatrix in internalPath / "zinc-classpath")
exclude[IncompatibleMethTypeProblem]("sbt.internal.inc.classpath.NativeCopyConfig.*"),
),
)
.jvmPlatform(scalaVersions = List(scala212, scala213))
.jvmPlatform(scalaVersions = scala212_213)
.configure(addBaseSettingsAndTestDeps, addSbtIO)

// class file reader and analyzer
Expand All @@ -606,7 +616,7 @@ lazy val zincClassfile = (projectMatrix in internalPath / "zinc-classfile")
),
mimaBinaryIssueFilters ++= Util.excludeInternalProblems,
)
.jvmPlatform(scalaVersions = List(scala212, scala213))
.jvmPlatform(scalaVersions = scala212_213)
.configure(addBaseSettingsAndTestDeps, addSbtIO, addSbtUtilLogging)

// re-implementation of scripted engine
Expand Down
3 changes: 3 additions & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ object Dependencies {
val scala211 = "2.11.12"
val scala212 = "2.12.12"
val scala213 = "2.13.3"
val defaultScalaVersion = scala212
val allScalaVersions = Seq(defaultScalaVersion, scala210, scala211, scala213)
val scala212_213 = Seq(defaultScalaVersion, scala213)

private val ioVersion = nightlyVersion.getOrElse("1.4.0-M3")
private val utilVersion = nightlyVersion.getOrElse("1.3.0")
Expand Down
21 changes: 21 additions & 0 deletions project/ProjectMatrixShims.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import sbt.Keys.scalaVersion
import sbt.Project.{ projectToLocalProject, projectToRef }
import sbt.{ Keys, LocalProject, Project, ProjectRef }
import scala.language.experimental.macros

object ProjectMatrixShims {

implicit def RichProject(p: Project) = new RichProject(p)

class RichProject(p: Project) {
def projectRefs: List[LocalProject] = projectToLocalProject(p) :: Nil
def jvmPlatform(scalaVersions: Seq[String]) = p.settings(scalaVersion := scalaVersions.head)
def jvmPlatform(autoScalaLibrary: Boolean) =
p.settings(Keys.autoScalaLibrary := autoScalaLibrary)
def jvm(version: String) = p
def jvm(version: Boolean) = p
}

def projectMatrix: Project = macro sbt.Project.projectMacroImpl

}

0 comments on commit 3cca854

Please sign in to comment.