Skip to content

Commit 28d4057

Browse files
authored
Merge pull request #2316 from dotty-staging/fix/ide-import
Fix #2299: Fix import into IDEs
2 parents 8c73189 + 8cb4d43 commit 28d4057

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

project/Build.scala

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import sbt._
33
import complete.DefaultParsers._
44
import java.io.{ RandomAccessFile, File }
55
import java.nio.channels.FileLock
6+
import java.nio.file.Files
67
import scala.reflect.io.Path
78
import sbtassembly.AssemblyKeys.assembly
89

@@ -150,6 +151,8 @@ object Build {
150151
crossPaths := false,
151152
// Do not depend on the Scala library
152153
autoScalaLibrary := false,
154+
// Let the sbt eclipse plugin now that this is a Java-only project
155+
EclipseKeys.projectFlavor := EclipseProjectFlavor.Java,
153156
//Remove javac invalid options in Compile doc
154157
javacOptions in (Compile, doc) --= Seq("-Xlint:unchecked", "-Xlint:deprecation")
155158
).
@@ -255,17 +258,41 @@ object Build {
255258
// We do not compile the whole submodule, only the part of the Scala 2.11 GenBCode backend
256259
// that we reuse for dotty.
257260
// See http://dotty.epfl.ch/docs/contributing/backend.html for more information.
258-
unmanagedSourceDirectories in Compile ++= {
259-
val backendDir = baseDirectory.value / ".." / "scala-backend" / "src" / "compiler" / "scala" / "tools" / "nsc" / "backend"
261+
//
262+
// NOTE: We link (or copy if symbolic links are not supported) these sources in
263+
// the current project using `sourceGenerators` instead of simply
264+
// referencing them using `unmanagedSourceDirectories` because the latter
265+
// breaks some IDEs.
266+
sourceGenerators in Compile += Def.task {
267+
val outputDir = (sourceManaged in Compile).value
268+
269+
val submoduleCompilerDir = baseDirectory.value / ".." / "scala-backend" / "src" / "compiler"
270+
val backendDir = submoduleCompilerDir / "scala" / "tools" / "nsc" / "backend"
260271
val allScalaFiles = GlobFilter("*.scala")
261272

262273
// NOTE: Keep these exclusions synchronized with the ones in the tests (CompilationTests.scala)
263-
((backendDir *
274+
val files = ((backendDir *
264275
(allScalaFiles - "JavaPlatform.scala" - "Platform.scala" - "ScalaPrimitives.scala")) +++
265276
(backendDir / "jvm") *
266277
(allScalaFiles - "BCodeICodeCommon.scala" - "GenASM.scala" - "GenBCode.scala" - "ScalacBackendInterface.scala")
267278
).get
268-
},
279+
280+
val pairs = files.pair(sbt.Path.rebase(submoduleCompilerDir, outputDir))
281+
282+
try {
283+
pairs.foreach { case (src, dst) =>
284+
sbt.IO.createDirectory(dst.getParentFile)
285+
if (!dst.exists)
286+
Files.createSymbolicLink(/*link = */ dst.toPath, /*existing = */src.toPath)
287+
}
288+
} catch {
289+
case e: UnsupportedOperationException =>
290+
// If the OS doesn't support symbolic links, copy the directory instead.
291+
sbt.IO.copy(pairs, overwrite = true, preserveLastModified = true)
292+
}
293+
294+
pairs.map(_._2)
295+
}.taskValue,
269296

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

0 commit comments

Comments
 (0)