Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Allow to specify required source version in project config #295

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions coordinator/configs/projects-config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ armanbilge_feral.projects.exclude = [
"com.armanbilge%feral-lambda-api-gateway-proxy-http4s"
]
armanbilge_gcp4s.tests = compile-only
armanbilge_van-cats.source-version=3.4 // override -source:future
assist-iot-sripas_scala-mqtt-wrapper {
sbt.commands = [
"excludeLibraryDependency org.wartremover:wartremover_{scalaVersion}",
Expand Down Expand Up @@ -203,6 +204,13 @@ disneystreaming_smithy4s {
smithy4s-dynamic.tests = compile-only
}
}
disneystreaming_smithy-translate {
source-patches = [{
path = "buildSetup.sc"
pattern = "case ZincWorkerUtil.DottyVersion("0","
replace-with = "case ZincWorkerUtil.Scala3Version("
}]
}
disneystreaming_weaver-test {
sbt.options=["-Dcommunitybuild.dualVersion=minor:+1"]
}
Expand Down
3 changes: 3 additions & 0 deletions coordinator/src/main/resources/buildPlan.reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ projects {
overrides = {}
}

// A fixed Scala `-source` setting to be applied to the project.
source-version = null

// Mode of tests execution one of disabled|compile-only|full
tests = full

Expand Down
1 change: 1 addition & 0 deletions coordinator/src/main/scala/core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ case class ProjectBuildConfig(
sbt: SbtConfig = SbtConfig(),
mill: MillConfig = MillConfig(),
tests: TestingMode = TestingMode.Full,
sourceVersion: Option[String] = None,
// We should use Option[Int] here, but json4s fails to resolve signature https://github.com/json4s/json4s/issues/1035
sourcePatches: List[SourcePatch] = Nil
) derives ConfigReader
Expand Down
13 changes: 12 additions & 1 deletion project-builder/build-revision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@ 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:s"
sourceVersion=`echo $projectConfig | jq -r '.sourceVersion // ""'`
sourceVersionSetting=""
if [[ -z "$sourceVersion" ]]; then
sourceVersion="$scalaBinaryVersion-migration"
sourceVersionSetting="-source:$sourceVersion"
echo "Implicitly using source version $sourceVersion"
else
echo "Using configured source version: $sourceVersion"
sourceVersionSetting="REQUIRE:-source:$sourceVersion"
fi

commonAppendScalacOptions="$sourceVersionSetting,-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
18 changes: 13 additions & 5 deletions project-builder/shared/CommunityBuildCore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -349,32 +349,40 @@ object Scala3CommunityBuild {
): Seq[String] = {
val (removeMatchSettings, removeSettings) = remove.partition { _.startsWith("MATCH:") }
val matchPatterns = removeMatchSettings.map(_.stripPrefix("MATCH:"))

val (required, standardAppendSettings) = append.partition(_.startsWith("REQUIRE:"))
val requiredAppendSettings = required.map(_.stripPrefix("REQUIRE:"))

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

val appendSettings = {
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
if(forceSourceVersion) Some(s"-source:${requiredSourceVersion.getOrElse("future-migration")}") else None
).flatten
append.filterNot{ setting =>

standardAppendSettings.filterNot{ setting =>
excludeIf(setting,
isSourceVersion(setting) && (definedSourceSetting.nonEmpty || forceFutureMigrationVersion),
isSourceVersion(setting) && (definedSourceSetting.nonEmpty || forceSourceVersion),
s"Project has predefined source version: ${definedSourceSetting.get}"
)
} ++ forcedAppendSettings
}

val normalizedExcludePatterns = (appendSettings ++ removeSettings).distinct.map { setting =>
Seq[String => String](
setting => if (setting.startsWith("--")) setting.tail else setting,
Expand Down