Skip to content

Commit db7d705

Browse files
authored
Merge pull request #187 from mdedetrich/only-enable-optimizer-in-ci
Only enable optimizer in CI
2 parents c409c84 + ace58c0 commit db7d705

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

Diff for: src/main/scala/ScalaModulePlugin.scala

+18-9
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,26 @@ object ScalaModulePlugin extends AutoPlugin {
4646
)
4747

4848
/**
49-
* Enable `-opt:l:inline`, `-opt:l:project` or `-optimize`, depending on the scala version.
49+
* Enable `-opt:l:inline`, `-opt:l:project` or `-optimize`, depending on the Scala version.
50+
*
51+
* Note that the optimizer is only enabled in CI and not during local development.
52+
* Thus, for consistent results, release artifacts must only be built on CI --
53+
* which is the expected norm for Scala modules, anyway.
5054
*/
5155
lazy val enableOptimizer: Setting[_] = Compile / compile / scalacOptions ++= {
52-
val Ver = """(\d+)\.(\d+)\.(\d+).*""".r
53-
val Ver(epic, maj, min) = scalaVersion.value
54-
(epic, maj.toInt, min.toInt) match {
55-
case ("2", m, _) if m < 12 => Seq("-optimize")
56-
case ("2", 12, n) if n < 3 => Seq("-opt:l:project")
57-
case ("2", _, _) => Seq("-opt:l:inline", "-opt-inline-from:" + scalaModuleEnableOptimizerInlineFrom.value)
58-
case ("3", _, _) => Nil // Optimizer not yet available for Scala3, see https://docs.scala-lang.org/overviews/compiler-options/optimizer.html
59-
}
56+
if (insideCI.value) {
57+
val log = sLog.value
58+
val inlineFrom = scalaModuleEnableOptimizerInlineFrom.value
59+
log.info(s"Running in CI, enabling Scala2 optimizer for module: ${name.value} with -opt-inline-from: $inlineFrom")
60+
val Ver = """(\d+)\.(\d+)\.(\d+).*""".r
61+
val Ver(epic, maj, min) = scalaVersion.value
62+
(epic, maj.toInt, min.toInt) match {
63+
case ("2", m, _) if m < 12 => Seq("-optimize")
64+
case ("2", 12, n) if n < 3 => Seq("-opt:l:project")
65+
case ("2", _, _) => Seq("-opt:l:inline", "-opt-inline-from:" + inlineFrom)
66+
case ("3", _, _) => Nil // Optimizer not yet available for Scala3, see https://docs.scala-lang.org/overviews/compiler-options/optimizer.html
67+
}
68+
} else Nil
6069
}
6170

6271
/**

0 commit comments

Comments
 (0)