@@ -3,6 +3,7 @@ import sbt._
3
3
import complete .DefaultParsers ._
4
4
import java .io .{ RandomAccessFile , File }
5
5
import java .nio .channels .FileLock
6
+ import java .nio .file .Files
6
7
import scala .reflect .io .Path
7
8
import sbtassembly .AssemblyKeys .assembly
8
9
@@ -150,6 +151,8 @@ object Build {
150
151
crossPaths := false ,
151
152
// Do not depend on the Scala library
152
153
autoScalaLibrary := false ,
154
+ // Let the sbt eclipse plugin now that this is a Java-only project
155
+ EclipseKeys .projectFlavor := EclipseProjectFlavor .Java ,
153
156
// Remove javac invalid options in Compile doc
154
157
javacOptions in (Compile , doc) --= Seq (" -Xlint:unchecked" , " -Xlint:deprecation" )
155
158
).
@@ -255,17 +258,41 @@ object Build {
255
258
// We do not compile the whole submodule, only the part of the Scala 2.11 GenBCode backend
256
259
// that we reuse for dotty.
257
260
// 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"
260
271
val allScalaFiles = GlobFilter (" *.scala" )
261
272
262
273
// NOTE: Keep these exclusions synchronized with the ones in the tests (CompilationTests.scala)
263
- ((backendDir *
274
+ val files = ((backendDir *
264
275
(allScalaFiles - " JavaPlatform.scala" - " Platform.scala" - " ScalaPrimitives.scala" )) +++
265
276
(backendDir / " jvm" ) *
266
277
(allScalaFiles - " BCodeICodeCommon.scala" - " GenASM.scala" - " GenBCode.scala" - " ScalacBackendInterface.scala" )
267
278
).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,
269
296
270
297
// Used by the backend
271
298
libraryDependencies += " org.scala-lang.modules" % " scala-asm" % " 5.1.0-scala-2" ,
0 commit comments