|
1 | 1 | package dotty.tools.sbtplugin
|
2 | 2 |
|
3 | 3 | import sbt._
|
| 4 | +import sbt.Def.Initialize |
4 | 5 | import sbt.Keys._
|
5 | 6 | import java.io._
|
6 | 7 | import java.lang.ProcessBuilder
|
@@ -196,34 +197,38 @@ object DottyIDEPlugin extends AutoPlugin {
|
196 | 197 | origState
|
197 | 198 | }
|
198 | 199 |
|
| 200 | + private def projectConfigTask(config: Configuration): Initialize[Task[Option[ProjectConfig]]] = Def.task { |
| 201 | + if ((sources in config).value.isEmpty) None |
| 202 | + else { |
| 203 | + // Not needed to generate the config, but this guarantees that the |
| 204 | + // generated config is usable by an IDE without any extra compilation |
| 205 | + // step. |
| 206 | + val _ = (compile in config).value |
| 207 | + |
| 208 | + val id = s"${thisProject.value.id}/${config.name}" |
| 209 | + val compilerVersion = (scalaVersion in config).value |
| 210 | + val compilerArguments = (scalacOptions in config).value |
| 211 | + val sourceDirectories = (unmanagedSourceDirectories in config).value ++ (managedSourceDirectories in config).value |
| 212 | + val depClasspath = Attributed.data((dependencyClasspath in config).value) |
| 213 | + val classDir = (classDirectory in config).value |
| 214 | + |
| 215 | + Some(new ProjectConfig( |
| 216 | + id, |
| 217 | + compilerVersion, |
| 218 | + compilerArguments.toArray, |
| 219 | + sourceDirectories.toArray, |
| 220 | + depClasspath.toArray, |
| 221 | + classDir |
| 222 | + )) |
| 223 | + } |
| 224 | + } |
| 225 | + |
199 | 226 | override def projectSettings: Seq[Setting[_]] = Seq(
|
200 |
| - // Use Def.derive so `projectConfig` is only defined in the configurations where the |
201 |
| - // tasks/settings it depends on are defined. |
202 |
| - Def.derive(projectConfig := { |
203 |
| - if (sources.value.isEmpty) None |
204 |
| - else { |
205 |
| - // Not needed to generate the config, but this guarantees that the |
206 |
| - // generated config is usable by an IDE without any extra compilation |
207 |
| - // step. |
208 |
| - val _ = compile.value |
209 |
| - |
210 |
| - val id = s"${thisProject.value.id}/${configuration.value.name}" |
211 |
| - val compilerVersion = scalaVersion.value |
212 |
| - val compilerArguments = scalacOptions.value |
213 |
| - val sourceDirectories = unmanagedSourceDirectories.value ++ managedSourceDirectories.value |
214 |
| - val depClasspath = Attributed.data(dependencyClasspath.value) |
215 |
| - val classDir = classDirectory.value |
216 |
| - |
217 |
| - Some(new ProjectConfig( |
218 |
| - id, |
219 |
| - compilerVersion, |
220 |
| - compilerArguments.toArray, |
221 |
| - sourceDirectories.toArray, |
222 |
| - depClasspath.toArray, |
223 |
| - classDir |
224 |
| - )) |
225 |
| - } |
226 |
| - }) |
| 227 | + // TODO: It would be better to use Def.derive to define projectConfig in |
| 228 | + // every configuration where the keys it depends on exist, however this |
| 229 | + // currently breaks aggregated tasks: https://github.com/sbt/sbt/issues/3580 |
| 230 | + projectConfig in Compile := projectConfigTask(Compile).value, |
| 231 | + projectConfig in Test := projectConfigTask(Test).value |
227 | 232 | )
|
228 | 233 |
|
229 | 234 | override def buildSettings: Seq[Setting[_]] = Seq(
|
|
0 commit comments