Skip to content

Commit

Permalink
Better filtering of scalacOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
WojciechMazur committed Jan 10, 2024
1 parent 6358335 commit c746d32
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion project-builder/build-revision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ scalaBinaryVersionMajor=`echo $scalaVersion | cut -d . -f 1`
scalaBinaryVersionMinor=`echo $scalaVersion | cut -d . -f 2`
echo "Scala binary version found: $scalaBinaryVersion"

commonAppendScalacOptions="-source:$scalaBinaryVersion-migration,-Wconf:msg=can be rewritten automatically under -rewrite -source $scalaBinaryVersion-migration:s"
commonAppendScalacOptions="-source:$scalaBinaryVersion-migration,-Wconf:msg=can be rewritten automatically under:s"
commonRemoveScalacOptions="-deprecation,-feature,-Xfatal-warnings,-Werror,MATCH:.*-Wconf.*any:e,-migration,"
echo "Would try to apply common scalacOption (best-effort, sbt/mill only):"
echo "Append: $commonAppendScalacOptions"
Expand Down
23 changes: 18 additions & 5 deletions project-builder/shared/CommunityBuildCore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,29 @@ object Scala3CommunityBuild {
val matchPatterns = removeMatchSettings.map(_.stripPrefix("MATCH:"))

def isSourceVersion(v: String) = v.matches(raw"^-?-source(:(future|(\d\.\d+))(-migration)?)?")
val definedSourceVersion = current.find(isSourceVersion)
val SourceVersionPattern = raw"^((3\.\d+|future)(-migration)?)$$".r
val definedSourceSetting = current.find(isSourceVersion)
lazy val definedSourceVersion: Option[String] =
definedSourceSetting.flatMap(_.split(":").drop(1).headOption) // -source:version
.orElse(current.find(SourceVersionPattern.findFirstIn(_).isDefined)) // -source version
.flatMap(SourceVersionPattern.findFirstMatchIn(_))
.flatMap(m => Option(m.group(1)))
val forceFutureMigrationVersion = definedSourceVersion.contains("future")

val appendSettings = {
def check(setting: String, expr: Boolean, reason: => String) = {
def excludeIf(setting: String, expr: Boolean, reason: => String) = {
if(expr) logOnce(s"Would not apply setting `$setting`: $reason")
expr
}
val forcedAppendSettings: Seq[String] = Seq(
if(forceFutureMigrationVersion) Some("-source:future-migration") else None
).flatten
append.filterNot{ setting =>
check(setting, definedSourceVersion.nonEmpty && isSourceVersion(setting), s"Project has predefined source version: ${definedSourceVersion.get}")
}
excludeIf(setting,
isSourceVersion(setting) && (definedSourceSetting.nonEmpty || forceFutureMigrationVersion),
s"Project has predefined source version: ${definedSourceSetting.get}"
)
} ++ forcedAppendSettings
}
val normalizedExcludePatterns = (appendSettings ++ removeSettings).distinct.map { setting =>
Seq[String => String](
Expand All @@ -378,7 +392,6 @@ object Scala3CommunityBuild {
).reduce(_.andThen(_))
.apply(setting)
}
val SourceVersionPattern = raw"^(3\.\d+|future)(-migration)?$$".r
current
.filterNot { s =>
def isMatching(reason: String, found: Option[String]): Boolean = found match {
Expand Down

0 comments on commit c746d32

Please sign in to comment.