Skip to content

Fix #2299: Fix import into IDEs #2316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 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 @@ -150,6 +151,8 @@ object Build {
crossPaths := false,
// Do not depend on the Scala library
autoScalaLibrary := false,
// Let the sbt eclipse plugin now that this is a Java-only project
EclipseKeys.projectFlavor := EclipseProjectFlavor.Java,
//Remove javac invalid options in Compile doc
javacOptions in (Compile, doc) --= Seq("-Xlint:unchecked", "-Xlint:deprecation")
).
Expand Down Expand Up @@ -255,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