Skip to content

Commit af76e79

Browse files
committed
Set plugin to unmanaged jars to make it faster
See scala/scala-dev#458.
1 parent 7efa187 commit af76e79

File tree

2 files changed

+113
-80
lines changed

2 files changed

+113
-80
lines changed

build.sbt

Lines changed: 98 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010
lazy val root = project
1111
.in(file("."))
1212
.aggregate(profiledb, plugin, profilingSbtPlugin)
13-
.settings(Seq(
14-
name := "profiling-root",
15-
publish := {},
16-
publishLocal := {},
17-
watchSources ++=
18-
(watchSources in plugin).value ++
19-
(watchSources in profiledb).value ++
20-
(watchSources in integrations).value
21-
))
13+
.settings(
14+
Seq(
15+
name := "profiling-root",
16+
publish := {},
17+
publishLocal := {},
18+
watchSources ++=
19+
(watchSources in plugin).value ++
20+
(watchSources in profiledb).value ++
21+
(watchSources in integrations).value
22+
)
23+
)
2224

2325
import build.BuildImplementation.BuildDefaults
2426
import com.trueaccord.scalapb.compiler.Version.scalapbVersion
@@ -44,21 +46,24 @@ lazy val plugin = project
4446
),
4547
libraryDependencies ++= testDependencies,
4648
testOptions in Test ++= List(Tests.Argument("-v"), Tests.Argument("-s")),
49+
allDepsForCompilerPlugin := {
50+
val jar = (Keys.packageBin in Compile).value
51+
val profileDbJar = (Keys.`package` in Compile in profiledb).value
52+
val absoluteJars = List(jar, profileDbJar).classpath
53+
val pluginDeps = (managedClasspath in Compile).value
54+
(absoluteJars ++ pluginDeps)
55+
},
4756
// Make the tests to compile with the plugin
4857
optionsForSourceCompilerPlugin := {
49-
val jar = (Keys.`package` in Compile).value
50-
val profileDbJar = (Keys.`package` in Compile in profiledb).value
51-
val absoluteJars = List(jar, profileDbJar).map(_.getAbsolutePath)
52-
// Should we filter out all the scala artifacts?
53-
val pluginDeps = (managedClasspath in Compile).value.files.toList
54-
val pluginAndDeps = (absoluteJars ++ pluginDeps).mkString(":")
58+
val jar = (Keys.packageBin in Compile).value
59+
val pluginAndDeps = allDepsForCompilerPlugin.value.map(_.data.getAbsolutePath()).mkString(":")
5560
val addPlugin = "-Xplugin:" + pluginAndDeps
5661
val dummy = "-Jdummy=" + jar.lastModified
5762
// Enable debugging information when necessary
5863
val debuggingPluginOptions =
5964
if (!enableStatistics.value) Nil
60-
else List("-Ystatistics")//, "-P:scalac-profiling:show-profiles")
61-
//else List("-Xlog-implicits", "-Ystatistics:typer")
65+
else List("-Ystatistics") //, "-P:scalac-profiling:show-profiles")
66+
//else List("-Xlog-implicits", "-Ystatistics:typer")
6267
Seq(addPlugin, dummy) ++ debuggingPluginOptions
6368
},
6469
scalacOptions in Test ++= optionsForSourceCompilerPlugin.value,
@@ -78,14 +83,13 @@ lazy val plugin = project
7883
case (2, y) if y >= 12 => new File(scalaSource.value.getPath + "-2.12")
7984
}.toList
8085
}),
81-
packageBin in Compile := (assembly in Compile).value,
86+
Keys.`package` in Compile := (assembly in Compile).value,
8287
test in assembly := {},
8388
assemblyOption in assembly :=
8489
(assemblyOption in assembly).value
8590
.copy(includeScala = false, includeDependency = true)
8691
)
8792

88-
8993
// Trick to copy profiledb with Scala 2.11.11 so that vscode can depend on it
9094
lazy val profiledb211 = profiledb
9195
.copy(id = "profiledb-211")
@@ -112,10 +116,13 @@ lazy val vscodeIntegration = project
112116
publish := (publish in VscodeImplementation).dependsOn(publish in profiledb211).value,
113117
publishLocal :=
114118
(publishLocal in VscodeImplementation).dependsOn(publishLocal in profiledb211).value,
115-
publishExtension := (Def.task {
116-
val scalaExtensionDir = (baseDirectory in VscodeScala).value./("scala")
117-
sys.process.Process(Seq("vsce", "package"), scalaExtensionDir).!!
118-
}).dependsOn(publishLocal).value
119+
publishExtension := (Def
120+
.task {
121+
val scalaExtensionDir = (baseDirectory in VscodeScala).value./("scala")
122+
sys.process.Process(Seq("vsce", "package"), scalaExtensionDir).!!
123+
})
124+
.dependsOn(publishLocal)
125+
.value
119126
)
120127

121128
lazy val profilingSbtPlugin = project
@@ -141,16 +148,19 @@ lazy val integrations = project
141148
scalaHome := BuildDefaults.setUpScalaHome.value,
142149
parallelExecution in Test := false,
143150
scalacOptions ++= BuildDefaults.scalacProfilingScalacOptions.value,
144-
clean := Def.sequential(
145-
clean,
146-
(clean in Test in CirceTests),
147-
(clean in Test in MonocleTests),
148-
(clean in Test in MonocleExample),
149-
(clean in Compile in ScalatestCore),
150-
(clean in Compile in MagnoliaTests),
151-
(clean in ScalacCompiler)
152-
).value,
153-
test := Def.sequential(
151+
clean := Def
152+
.sequential(
153+
clean,
154+
(clean in Test in CirceTests),
155+
(clean in Test in MonocleTests),
156+
(clean in Test in MonocleExample),
157+
(clean in Compile in ScalatestCore),
158+
(clean in Compile in MagnoliaTests),
159+
(clean in ScalacCompiler)
160+
)
161+
.value,
162+
test := Def
163+
.sequential(
154164
(showScalaInstances in ThisBuild),
155165
(profilingWarmupCompiler in Compile), // Warmup example, classloader is the same for all
156166
(compile in Compile),
@@ -160,54 +170,80 @@ lazy val integrations = project
160170
(compile in Compile in ScalatestCore),
161171
(compile in Compile in MagnoliaTests),
162172
(compile in ScalacCompiler)
163-
).value,
173+
)
174+
.value,
164175
testOnly := Def.inputTaskDyn {
165176
val keywords = keywordsSetting.parsed
166177
val emptyAnalysis = Def.task(sbt.inc.Analysis.Empty)
167178
val CirceTask = Def.taskDyn {
168-
if (keywords.contains(Keywords.Circe)) Def.sequential(
169-
(compile in Test in CirceTests)
170-
) else emptyAnalysis
179+
if (keywords.contains(Keywords.Circe))
180+
Def.sequential(
181+
(compile in Test in CirceTests)
182+
)
183+
else emptyAnalysis
171184
}
172185
val IntegrationTask = Def.taskDyn {
173-
if (keywords.contains(Keywords.Integration)) Def.sequential(
174-
(compile in Compile)
175-
) else emptyAnalysis
186+
if (keywords.contains(Keywords.Integration))
187+
Def.sequential(
188+
(compile in Compile)
189+
)
190+
else emptyAnalysis
176191
}
177192
val MonocleTask = Def.taskDyn {
178-
if (keywords.contains(Keywords.Monocle)) Def.sequential(
179-
(compile in Test in MonocleTests),
180-
(compile in Test in MonocleExample)
181-
) else emptyAnalysis
193+
if (keywords.contains(Keywords.Monocle))
194+
Def.sequential(
195+
(compile in Test in MonocleTests),
196+
(compile in Test in MonocleExample)
197+
)
198+
else emptyAnalysis
182199
}
183200
val ScalatestTask = Def.taskDyn {
184-
if (keywords.contains(Keywords.Scalatest)) Def.sequential(
185-
(compile in Compile in ScalatestCore),
186-
(compile in Compile in ScalatestTests)
187-
) else emptyAnalysis
201+
if (keywords.contains(Keywords.Scalatest))
202+
Def.sequential(
203+
(compile in Compile in ScalatestCore),
204+
(compile in Compile in ScalatestTests)
205+
)
206+
else emptyAnalysis
188207
}
189208
val ScalacTask = Def.taskDyn {
190-
if (keywords.contains(Keywords.Scalac)) Def.sequential(
191-
(compile in Compile in ScalacCompiler)
192-
) else emptyAnalysis
209+
if (keywords.contains(Keywords.Scalac))
210+
Def.sequential(
211+
(compile in Compile in ScalacCompiler)
212+
)
213+
else emptyAnalysis
193214
}
194215
val BetterFilesTask = Def.taskDyn {
195-
if (keywords.contains(Keywords.BetterFiles)) Def.sequential(
196-
(compile in Compile in BetterFilesCore)
197-
) else emptyAnalysis
216+
if (keywords.contains(Keywords.BetterFiles))
217+
Def.sequential(
218+
(compile in Compile in BetterFilesCore)
219+
)
220+
else emptyAnalysis
198221
}
199222
val ShapelessTask = Def.taskDyn {
200-
if (keywords.contains(Keywords.Shapeless)) Def.sequential(
201-
(compile in Compile in ShapelessCore),
202-
(compile in Test in ShapelessCore)
203-
) else emptyAnalysis
223+
if (keywords.contains(Keywords.Shapeless))
224+
Def.sequential(
225+
(compile in Compile in ShapelessCore),
226+
(compile in Test in ShapelessCore)
227+
)
228+
else emptyAnalysis
204229
}
205230
val MagnoliaTask = Def.taskDyn {
206-
if (keywords.contains(Keywords.Magnolia)) Def.sequential(
207-
(compile in Compile in MagnoliaTests)
208-
) else emptyAnalysis
231+
if (keywords.contains(Keywords.Magnolia))
232+
Def.sequential(
233+
(compile in Compile in MagnoliaTests)
234+
)
235+
else emptyAnalysis
209236
}
210-
Def.sequential(CirceTask, MonocleTask, IntegrationTask, ScalatestTask, ScalacTask, BetterFilesTask, ShapelessTask, MagnoliaTask)
237+
Def.sequential(
238+
CirceTask,
239+
MonocleTask,
240+
IntegrationTask,
241+
ScalatestTask,
242+
ScalacTask,
243+
BetterFilesTask,
244+
ShapelessTask,
245+
MagnoliaTask
246+
)
211247
}.evaluated
212248
)
213249

project/BuildPlugin.scala

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ object BuildKeys {
3131
settingKey[Boolean]("Enable performance debugging if true.")
3232
final val optionsForSourceCompilerPlugin =
3333
taskKey[Seq[String]]("Generate scalac options for source compiler plugin")
34+
final val allDepsForCompilerPlugin =
35+
taskKey[Def.Classpath]("Return all dependencies for the source compiler plugin.")
3436
final val showScalaInstances = taskKey[Unit]("Show versions of all integration tests")
3537
final val useScalacFork =
3638
settingKey[Boolean]("Make every module use the Scala fork instead latest Scala 2.12.x.")
@@ -282,23 +284,6 @@ object BuildImplementation {
282284
}
283285
}
284286

285-
import sbt.ModuleID
286-
287-
/**
288-
* Removes scala version from those modules that use full cross version and injects
289-
* the manual Scala version in the library dependency name assuming that the library
290-
* will not use any binary incompatible change in the compiler sources (or assuming
291-
* that there is none, which is even better!).
292-
*/
293-
def trickLibraryDependency(dependency: ModuleID, validVersion: String): ModuleID = {
294-
dependency.crossVersion match {
295-
case fullVersion: sbt.CrossVersion.Full =>
296-
val manualNameWithScala = s"${dependency.name}_$validVersion"
297-
dependency.copy(name = manualNameWithScala).copy(crossVersion = sbt.CrossVersion.Disabled)
298-
case _ => dependency
299-
}
300-
}
301-
302287
private[build] val MinimumScalaVersion = "2.12.4"
303288
def pickScalaVersion: Def.Initialize[String] = Def.settingDyn {
304289
if (!BuildKeys.useScalacFork.value) Def.setting(MinimumScalaVersion)
@@ -323,11 +308,19 @@ object BuildImplementation {
323308
}
324309
}
325310

311+
def setUpUnmanagedJars: Def.Initialize[sbt.Task[Def.Classpath]] = Def.task {
312+
val previousJars = Keys.unmanagedJars.in(Compile).value
313+
val allPluginDeps = BuildKeys.allDepsForCompilerPlugin.in(PluginProject).value
314+
previousJars ++ allPluginDeps
315+
}
316+
326317
object MethodRefs {
327318
final val scalacProfilingScalacOptionsRef: String =
328319
"build.BuildImplementation.BuildDefaults.scalacProfilingScalacOptions"
329320
final val setUpScalaHomeRef: String =
330321
"build.BuildImplementation.BuildDefaults.setUpScalaHome"
322+
final val setUpUnmanagedJarsRef: String =
323+
"build.BuildImplementation.BuildDefaults.setUpUnmanagedJars"
331324
}
332325

333326
def setUpSourceDependenciesCmd(refs: List[String]): Def.Initialize[String] = {
@@ -339,10 +332,14 @@ object BuildImplementation {
339332
s"""${Keys.scalacOptions.key.label} in $ref := ${MethodRefs.scalacProfilingScalacOptionsRef}.value"""
340333
def setScalaHome(ref: String) =
341334
s"""${Keys.scalaHome.key.label} in $ref := ${MethodRefs.setUpScalaHomeRef}.value"""
335+
def setUnmanagedJars(ref: String, config: String) =
336+
s"""${Keys.unmanagedJars.key.label} in $config in $ref := ${MethodRefs.setUpUnmanagedJarsRef}.value"""
342337
val msg = s"The build integrations are using a local Scalac home."
343338
val setLoadMessage = s"""${Keys.onLoadMessage.key.label} in sbt.Global := "$msg""""
344339
val allSettingsRedefinitions = refs.flatMap { ref =>
345-
List(setScalaVersion(ref), setScalacOptions(ref), setScalaHome(ref))
340+
val setsUnmanagedJars =
341+
List(setUnmanagedJars(ref, "Compile"), setUnmanagedJars(ref, "Test"))
342+
List(setScalaVersion(ref), setScalacOptions(ref), setScalaHome(ref)) ++ setsUnmanagedJars
346343
} ++ List(setLoadMessage)
347344

348345
s"set List(${allSettingsRedefinitions.mkString(",")})"

0 commit comments

Comments
 (0)