Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix #2299: Fix import into IDEs
Both IntelliJ and Eclipse fail horribly when trying to import a project using `unmanagedSourceDirectories` containing files (and not directories), but this is necessary for our build since we only want to compile a subset of the backend folder. We workaround this by linking (or copying on OS when symbolic links do not work) the files we want to compile in sbt `managedSources`. Make sure to run `sbt compile` at least once before running `sbt eclipse` or importing the project in IntelliJ.
  • Loading branch information
smarter committed Apr 27, 2017
commit 8cb4d43279426ab048a65e8e605ed80872f50b37
33 changes: 29 additions & 4 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import sbt._
import complete.DefaultParsers._
import java.io.{ RandomAccessFile, File }
import java.nio.channels.FileLock
import java.nio.file.Files
import scala.reflect.io.Path
import sbtassembly.AssemblyKeys.assembly

Expand Down Expand Up @@ -257,17 +258,41 @@ object Build {
// We do not compile the whole submodule, only the part of the Scala 2.11 GenBCode backend
// that we reuse for dotty.
// See http://dotty.epfl.ch/docs/contributing/backend.html for more information.
unmanagedSourceDirectories in Compile ++= {
val backendDir = baseDirectory.value / ".." / "scala-backend" / "src" / "compiler" / "scala" / "tools" / "nsc" / "backend"
//
// NOTE: We link (or copy if symbolic links are not supported) these sources in
// the current project using `sourceGenerators` instead of simply
// referencing them using `unmanagedSourceDirectories` because the latter
// breaks some IDEs.
sourceGenerators in Compile += Def.task {
val outputDir = (sourceManaged in Compile).value

val submoduleCompilerDir = baseDirectory.value / ".." / "scala-backend" / "src" / "compiler"
val backendDir = submoduleCompilerDir / "scala" / "tools" / "nsc" / "backend"
val allScalaFiles = GlobFilter("*.scala")

// NOTE: Keep these exclusions synchronized with the ones in the tests (CompilationTests.scala)
((backendDir *
val files = ((backendDir *
(allScalaFiles - "JavaPlatform.scala" - "Platform.scala" - "ScalaPrimitives.scala")) +++
(backendDir / "jvm") *
(allScalaFiles - "BCodeICodeCommon.scala" - "GenASM.scala" - "GenBCode.scala" - "ScalacBackendInterface.scala")
).get
},

val pairs = files.pair(sbt.Path.rebase(submoduleCompilerDir, outputDir))

try {
pairs.foreach { case (src, dst) =>
sbt.IO.createDirectory(dst.getParentFile)
if (!dst.exists)
Files.createSymbolicLink(/*link = */ dst.toPath, /*existing = */src.toPath)
}
} catch {
case e: UnsupportedOperationException =>
// If the OS doesn't support symbolic links, copy the directory instead.
sbt.IO.copy(pairs, overwrite = true, preserveLastModified = true)
}

pairs.map(_._2)
}.taskValue,

// Used by the backend
libraryDependencies += "org.scala-lang.modules" % "scala-asm" % "5.1.0-scala-2",
Expand Down