Skip to content

Commit

Permalink
The binary breaking bonanza
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidGregory084 committed May 6, 2022
1 parent 74b0d62 commit d460f7b
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 51 deletions.
13 changes: 0 additions & 13 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,9 @@ ThisBuild / scalafixDependencies += "com.github.liancheng" %% "organize-imports"
ThisBuild / versionScheme := Some(VersionScheme.EarlySemVer)

mimaPreviousArtifacts := Set(
projectID.value.withRevision("0.3.0")
)

mimaBinaryIssueFilters ++= Seq(
ProblemFilters.exclude[ReversedMissingMethodProblem](
"io.github.davidgregory084.ScalacOptions.privatePartialUnification"
),
ProblemFilters.exclude[ReversedMissingMethodProblem](
"io.github.davidgregory084.ScalacOptions.async"
),
ProblemFilters.exclude[ReversedMissingMethodProblem](
"io.github.davidgregory084.ScalacOptions.io$github$davidgregory084$ScalacOptions$_setter_$privatePartialUnification_="
),
ProblemFilters.exclude[ReversedMissingMethodProblem](
"io.github.davidgregory084.ScalacOptions.io$github$davidgregory084$ScalacOptions$_setter_$async_="
)
)

// Testing
Expand Down
23 changes: 16 additions & 7 deletions src/main/scala/io/github/davidgregory084/ScalacOption.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,34 @@ package io.github.davidgregory084

/** A Scala compiler option.
*
* @param tokens
* The tokens which must be provided to declare this option.
* @param option The flag that is used to declare this option.
* @param args The arguments provided to this option.
* @param isSupported
* A predicate function determining whether the provided Scala compiler version supports this
* option.
*/
class ScalacOption(
val tokens: List[String],
val isSupported: ScalaVersion => Boolean = _ => true
val option: String,
val args: List[String],
val isSupported: ScalaVersion => Boolean
) {
override def hashCode(): Int =
41 * tokens.hashCode
41 * option.hashCode

override def equals(other: Any): Boolean =
other match {
case that: ScalacOption => this.tokens == that.tokens
case that: ScalacOption => this.option == that.option
case _ => false
}

override def toString =
"ScalacOption(" + tokens.mkString(" ") + ")"
(option :: args).mkString("ScalacOption(", " ", ")")
}

object ScalacOption {
def apply(option: String, isSupported: ScalaVersion => Boolean): ScalacOption =
new ScalacOption(option, Nil, isSupported)

def apply(option: String, args: List[String], isSupported: ScalaVersion => Boolean): ScalacOption =
new ScalacOption(option, args, isSupported)
}
38 changes: 24 additions & 14 deletions src/main/scala/io/github/davidgregory084/ScalacOptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,41 @@ package io.github.davidgregory084
import scala.Ordering.Implicits._
import scala.collection.immutable.ListSet

trait ScalacOptions {
private[davidgregory084] trait ScalacOptions {
import ScalaVersion._

/** Provide another option that is not declared by the ScalacOptions DSL.
*/
def other(option: String, isSupported: ScalaVersion => Boolean = _ => true): ScalacOption =
ScalacOption(option, isSupported)

/** Provide another option that is not declared by the ScalacOptions DSL.
*/
def other(option: String, args: List[String], isSupported: ScalaVersion => Boolean): ScalacOption =
ScalacOption(option, args, isSupported)

/** Specify character encoding used by source files.
*/
def encoding(enc: String) =
new ScalacOption(List("-encoding", enc))
ScalacOption("-encoding", List(enc), _ => true)

/** Emit warning and location for usages of deprecated APIs.
*/
val deprecation = new ScalacOption(
List("-deprecation"),
val deprecation = ScalacOption(
"-deprecation",
version => version < V2_13_0 || version >= V3_0_0
)

/** Emit warning and location for usages of features that should be imported explicitly.
*/
val feature =
new ScalacOption(List("-feature"))
ScalacOption("-feature", _ => true)

/** Enable features that will be available in a future version of Scala, for purposes of early
* migration and alpha testing.
*/
def scala3Source(version: String, isSupported: ScalaVersion => Boolean = _ >= V3_0_0) =
new ScalacOption(List("-source", version), isSupported)
ScalacOption("-source", List(version), isSupported)

/** Enable features that will be available in Scala 3.0.x with Scala 2.x compatibility mode, for
* purposes of early migration and alpha testing.
Expand Down Expand Up @@ -82,8 +92,8 @@ trait ScalacOptions {
/** Enable or disable language features
*/
def languageFeatureOption(name: String, isSupported: ScalaVersion => Boolean = _ => true) =
new ScalacOption(
List(s"-language:$name"),
ScalacOption(
s"-language:$name",
isSupported
)

Expand Down Expand Up @@ -119,12 +129,12 @@ trait ScalacOptions {
/** Enable additional warnings where generated code depends on assumptions.
*/
val unchecked =
new ScalacOption(List("-unchecked"))
ScalacOption("-unchecked", _ => true)

/** Advanced options (-X)
*/
def advancedOption(name: String, isSupported: ScalaVersion => Boolean = _ => true): ScalacOption =
new ScalacOption(List(s"-X$name"), isSupported)
ScalacOption(s"-X$name", isSupported)

/** Wrap field accessors to throw an exception on uninitialized access.
*/
Expand Down Expand Up @@ -342,7 +352,7 @@ trait ScalacOptions {
/** Private options (-Y)
*/
def privateOption(name: String, isSupported: ScalaVersion => Boolean = _ => true) =
new ScalacOption(List(s"-Y$name"), isSupported)
ScalacOption(s"-Y$name", isSupported)

/** Produce an error if an argument list is modified to match the receiver.
*/
Expand Down Expand Up @@ -485,7 +495,7 @@ trait ScalacOptions {
/** Warning options (-W)
*/
def warnOption(name: String, isSupported: ScalaVersion => Boolean = _ => true) =
new ScalacOption(List(s"-W$name"), isSupported)
ScalacOption(s"-W$name", isSupported)

/** Warn when dead code is identified.
*/
Expand Down Expand Up @@ -515,7 +525,7 @@ trait ScalacOptions {
/** Unused warning options (-Wunused:)
*/
def warnUnusedOption(name: String, isSupported: ScalaVersion => Boolean = _ => true) =
new ScalacOption(List(s"-Wunused:$name"), isSupported)
ScalacOption(s"-Wunused:$name", isSupported)

/** Warn if a @nowarn annotation did not suppress at least one warning.
*/
Expand Down Expand Up @@ -600,7 +610,7 @@ trait ScalacOptions {
/** Optimizer options (-opt)
*/
def optimizerOption(name: String, isSupported: ScalaVersion => Boolean = _ => true) =
new ScalacOption(List(s"-opt$name"), isSupported)
ScalacOption(s"-opt$name", isSupported)

/** Enable intra-method optimizations:
* unreachable-code,simplify-jumps,compact-locals,copy-propagation,redundant-casts,box-unbox,nullness-tracking,closure-invocations,allow-skip-core-module-init,assume-modules-non-null,allow-skip-class-loading.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ object TpolecatPlugin extends AutoPlugin {
Nil
}

supportedOptions.toList.flatMap(_.tokens)
supportedOptions.toList.flatMap(opt => opt.option :: opt.args)
}

val tpolecatDefaultOptionsMode = settingKey[OptionsMode](
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-tpolecat/scalacOptions/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ TaskKey[Unit]("checkReleaseMode") := {
}

TaskKey[Unit]("checkConsoleScalacOptions") := {
val shouldBeMissing = ScalacOptions.defaultConsoleExclude.flatMap(_.tokens).toSet
val shouldBeMissing = ScalacOptions.defaultConsoleExclude.flatMap(opt => opt.option :: opt.args).toSet
val testConsoleOptions = (Test / console / scalacOptions).value
val compileConsoleOptions = (Compile / console / scalacOptions).value

Expand Down
30 changes: 15 additions & 15 deletions src/test/scala/io/github/davidgregory084/TpolecatPluginSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TpolecatPluginSuite extends AnyFunSuite with ScalaCheckDrivenPropertyCheck
forAll(versionGen, versionGen, versionGen) {
(currentMaj: Long, currentMin: Long, currentPatch: Long) =>
val currentVersion = ScalaVersion(currentMaj, currentMin, currentPatch)
val scalacOption = new ScalacOption(List("-some-opt"))
val scalacOption = ScalacOption("-some-opt", _ => true)
assert(
scalacOption.isSupported(currentVersion),
"Should be valid when neither addedIn nor removedIn"
Expand All @@ -42,7 +42,7 @@ class TpolecatPluginSuite extends AnyFunSuite with ScalaCheckDrivenPropertyCheck
(currentMaj: Long, currentMin: Long, currentPatch: Long) =>
val currentVersion = ScalaVersion(currentMaj, currentMin, currentPatch)
val addedVersion = ScalaVersion(currentMaj - 1, 0, 0)
val scalacOption = new ScalacOption(List("-some-opt"), version => version >= addedVersion)
val scalacOption = ScalacOption("-some-opt", version => version >= addedVersion)
assert(
scalacOption.isSupported(currentVersion),
"Should be valid when addedIn matches past major release"
Expand All @@ -55,7 +55,7 @@ class TpolecatPluginSuite extends AnyFunSuite with ScalaCheckDrivenPropertyCheck
(currentMaj: Long, currentMin: Long, currentPatch: Long) =>
val currentVersion = ScalaVersion(currentMaj, currentMin, currentPatch)
val addedVersion = ScalaVersion(currentMaj, currentMin - 1, 0)
val scalacOption = new ScalacOption(List("-some-opt"), version => version >= addedVersion)
val scalacOption = ScalacOption("-some-opt", version => version >= addedVersion)
assert(
scalacOption.isSupported(currentVersion),
"Should be valid when addedIn matches past minor release"
Expand All @@ -68,7 +68,7 @@ class TpolecatPluginSuite extends AnyFunSuite with ScalaCheckDrivenPropertyCheck
(currentMaj: Long, currentMin: Long, currentPatch: Long) =>
val currentVersion = ScalaVersion(currentMaj, currentMin, currentPatch)
val addedVersion = ScalaVersion(currentMaj, currentMin, currentPatch - 1)
val scalacOption = new ScalacOption(List("-some-opt"), version => version >= addedVersion)
val scalacOption = ScalacOption("-some-opt", version => version >= addedVersion)
assert(
scalacOption.isSupported(currentVersion),
"Should be valid when addedIn matches past patch release"
Expand All @@ -80,7 +80,7 @@ class TpolecatPluginSuite extends AnyFunSuite with ScalaCheckDrivenPropertyCheck
forAll(versionGen, versionGen, versionGen) {
(currentMaj: Long, currentMin: Long, currentPatch: Long) =>
val currentVersion = ScalaVersion(currentMaj, currentMin, currentPatch)
val scalacOption = new ScalacOption(List("-some-opt"), version => version >= currentVersion)
val scalacOption = ScalacOption("-some-opt", version => version >= currentVersion)
assert(
scalacOption.isSupported(currentVersion),
"Should be valid when addedIn matches this minor/patch release"
Expand All @@ -93,7 +93,7 @@ class TpolecatPluginSuite extends AnyFunSuite with ScalaCheckDrivenPropertyCheck
(currentMaj: Long, currentMin: Long, currentPatch: Long) =>
val currentVersion = ScalaVersion(currentMaj, currentMin, currentPatch)
val addedVersion = ScalaVersion(currentMaj + 1, currentMin, currentPatch)
val scalacOption = new ScalacOption(List("-some-opt"), version => version >= addedVersion)
val scalacOption = ScalacOption("-some-opt", version => version >= addedVersion)
assert(
!scalacOption.isSupported(currentVersion),
"Should not be valid when addedIn matches a future major release"
Expand All @@ -106,7 +106,7 @@ class TpolecatPluginSuite extends AnyFunSuite with ScalaCheckDrivenPropertyCheck
(currentMaj: Long, currentMin: Long, currentPatch: Long) =>
val currentVersion = ScalaVersion(currentMaj, currentMin, currentPatch)
val addedVersion = ScalaVersion(currentMaj, currentMin + 1, currentPatch)
val scalacOption = new ScalacOption(List("-some-opt"), version => version >= addedVersion)
val scalacOption = ScalacOption("-some-opt", version => version >= addedVersion)
assert(
!scalacOption.isSupported(currentVersion),
"Should not be valid when addedIn matches a future minor release"
Expand All @@ -119,7 +119,7 @@ class TpolecatPluginSuite extends AnyFunSuite with ScalaCheckDrivenPropertyCheck
(currentMaj: Long, currentMin: Long, currentPatch: Long) =>
val currentVersion = ScalaVersion(currentMaj, currentMin, currentPatch)
val addedVersion = ScalaVersion(currentMaj, currentMin, currentPatch + 1)
val scalacOption = new ScalacOption(List("-some-opt"), version => version >= addedVersion)
val scalacOption = ScalacOption("-some-opt", version => version >= addedVersion)
assert(
!scalacOption.isSupported(currentVersion),
"Should not be valid when addedIn matches a future patch release"
Expand All @@ -132,7 +132,7 @@ class TpolecatPluginSuite extends AnyFunSuite with ScalaCheckDrivenPropertyCheck
(currentMaj: Long, currentMin: Long, currentPatch: Long) =>
val currentVersion = ScalaVersion(currentMaj, currentMin, currentPatch)
val removedVersion = ScalaVersion(currentMaj + 1, 0, 0)
val scalacOption = new ScalacOption(List("-some-opt"), version => version < removedVersion)
val scalacOption = ScalacOption("-some-opt", version => version < removedVersion)
assert(
scalacOption.isSupported(currentVersion),
"Should be valid when removedIn matches next major release"
Expand All @@ -145,7 +145,7 @@ class TpolecatPluginSuite extends AnyFunSuite with ScalaCheckDrivenPropertyCheck
(currentMaj: Long, currentMin: Long, currentPatch: Long) =>
val currentVersion = ScalaVersion(currentMaj, currentMin, currentPatch)
val removedVersion = ScalaVersion(currentMaj, currentMin + 1, currentPatch)
val scalacOption = new ScalacOption(List("-some-opt"), version => version < removedVersion)
val scalacOption = ScalacOption("-some-opt", version => version < removedVersion)
assert(
scalacOption.isSupported(currentVersion),
"Should be valid when removedIn matches next minor release"
Expand All @@ -158,7 +158,7 @@ class TpolecatPluginSuite extends AnyFunSuite with ScalaCheckDrivenPropertyCheck
(currentMaj: Long, currentMin: Long, currentPatch: Long) =>
val currentVersion = ScalaVersion(currentMaj, currentMin, currentPatch)
val removedVersion = ScalaVersion(currentMaj, currentMin, currentPatch + 1)
val scalacOption = new ScalacOption(List("-some-opt"), version => version < removedVersion)
val scalacOption = ScalacOption("-some-opt", version => version < removedVersion)
assert(
scalacOption.isSupported(currentVersion),
"Should be valid when removedIn matches next patch release"
Expand All @@ -170,7 +170,7 @@ class TpolecatPluginSuite extends AnyFunSuite with ScalaCheckDrivenPropertyCheck
forAll(versionGen, versionGen, versionGen) {
(currentMaj: Long, currentMin: Long, currentPatch: Long) =>
val currentVersion = ScalaVersion(currentMaj, currentMin, currentPatch)
val scalacOption = new ScalacOption(List("-some-opt"), version => version < currentVersion)
val scalacOption = ScalacOption("-some-opt", version => version < currentVersion)
assert(
!scalacOption.isSupported(currentVersion),
"Should not be valid when removedIn matches this minor/patch release"
Expand All @@ -183,7 +183,7 @@ class TpolecatPluginSuite extends AnyFunSuite with ScalaCheckDrivenPropertyCheck
(currentMaj: Long, currentMin: Long, currentPatch: Long) =>
val currentVersion = ScalaVersion(currentMaj, currentMin, currentPatch)
val removedVersion = ScalaVersion(currentMaj - 1, currentMin, currentPatch)
val scalacOption = new ScalacOption(List("-some-opt"), version => version < removedVersion)
val scalacOption = ScalacOption("-some-opt", version => version < removedVersion)
assert(
!scalacOption.isSupported(currentVersion),
"Should not be valid when removedIn matches an old major release"
Expand All @@ -196,7 +196,7 @@ class TpolecatPluginSuite extends AnyFunSuite with ScalaCheckDrivenPropertyCheck
(currentMaj: Long, currentMin: Long, currentPatch: Long) =>
val currentVersion = ScalaVersion(currentMaj, currentMin, currentPatch)
val removedVersion = ScalaVersion(currentMaj, currentMin - 1, currentPatch)
val scalacOption = new ScalacOption(List("-some-opt"), version => version < removedVersion)
val scalacOption = ScalacOption("-some-opt", version => version < removedVersion)
assert(
!scalacOption.isSupported(currentVersion),
"Should not be valid when removedIn matches an old minor release"
Expand All @@ -209,7 +209,7 @@ class TpolecatPluginSuite extends AnyFunSuite with ScalaCheckDrivenPropertyCheck
(currentMaj: Long, currentMin: Long, currentPatch: Long) =>
val currentVersion = ScalaVersion(currentMaj, currentMin, currentPatch)
val removedVersion = ScalaVersion(currentMaj, currentMin, currentPatch - 1)
val scalacOption = new ScalacOption(List("-some-opt"), version => version < removedVersion)
val scalacOption = ScalacOption("-some-opt", version => version < removedVersion)
assert(
!scalacOption.isSupported(currentVersion),
"Should not be valid when removedIn matches an old patch release"
Expand Down

0 comments on commit d460f7b

Please sign in to comment.