Skip to content

Commit

Permalink
Merge pull request #1317 from tofu-tf/fix_scala3_publish_for_logging_…
Browse files Browse the repository at this point in the history
…modules

fix: include logging3 into tofu aggregted modules
  • Loading branch information
dos65 committed Aug 8, 2024
2 parents bcaf8a2 + fde55ba commit 4c85346
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 37 deletions.
85 changes: 51 additions & 34 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -241,41 +241,58 @@ lazy val loggingEnumeratum = projectMatrix
.jvmPlatform(scala2And3Versions)
.dependsOn(loggingStr)

lazy val logging = projectMatrix
.in(modules / "logging")
.aggregate(
loggingStr,
loggingDer,
loggingLayout,
loggingShapeless,
loggingRefined,
loggingLog4Cats,
loggingLog4CatsLegacy,
loggingLogstashLogback,
)
.settings(
defaultSettings,
name := "tofu-logging"
)
.dependsOn(loggingStr, loggingDer, loggingLayout, loggingShapeless, loggingRefined, loggingLog4Cats)
.jvmPlatform(scala2Versions)
lazy val logging = {
def projectRefFromMatrix(pm: ProjectMatrix, scalaVersion: String): ProjectReference = {
val projects = pm.filterProjects(Seq(VirtualAxis.jvm, VirtualAxis.scalaABIVersion(scalaVersion)))
projects.headOption match {
case Some(p) => p
case None => throw new Exception(s"Can't found $scalaVersion axis for ${pm}")
}
}

lazy val logging3 = projectMatrix
.in(modules / "logging")
.aggregate(
loggingStr,
loggingDer,
loggingLayout,
loggingRefined,
loggingLog4Cats,
loggingLogstashLogback,
)
.settings(
defaultSettings,
name := "tofu-logging"
)
.dependsOn(loggingStr, loggingDer, loggingLayout, loggingRefined, loggingLog4Cats)
.jvmPlatform(List(Version.scala3))
val modulesSettings =
List(
// ($project, $haScala3, $dependsOn)
(loggingStr, true, true),
(loggingDer, true, true),
(loggingLayout, true, true),
(loggingShapeless, false, true),
(loggingRefined, true, true),
(loggingLog4Cats, true, true),
(loggingLogstashLogback, true, true),
)

val initial = ProjectMatrix("logging", modules / "logging")
scala2And3Versions.foldLeft(initial) { case (prMatrix, scalaVersionValue) =>
val scalaAxis = VirtualAxis.scalaABIVersion(scalaVersionValue)
prMatrix.customRow(
autoScalaLibrary = true,
axisValues = Seq(VirtualAxis.jvm, scalaAxis),
process = (pr: Project) => {
val filterScala =
if (scalaVersionValue.startsWith("3")) identity[Boolean](_)
else (_: Boolean) => true
val (aggModules, dependsOnModules) =
modulesSettings.foldLeft((List.empty[ProjectReference], List.empty[ClasspathDependency])) {
case ((agg, dependsOn), (prM, hasScala3, isInDependsOn)) if filterScala(hasScala3) =>
val ref = projectRefFromMatrix(prM, scalaVersionValue)
val nextAgg = ref :: agg
val nextDependsOn = if (isInDependsOn) ClasspathDependency(ref, None) :: dependsOn else dependsOn
(nextAgg, nextDependsOn)
case (acc, _) => acc
}

pr.aggregate(aggModules: _*)
.settings(
defaultSettings,
scalaVersion := scalaVersionValue,
name := "tofu-logging"
)
.dependsOn(dependsOnModules: _*)
}
)
}
}

val util = modules / "util"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import ch.qos.logback.classic.Logger
import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.core.read.ListAppender
import com.fasterxml.jackson.core.{JsonFactory, JsonGenerator}
import derevo.derive
import org.scalatest.funsuite.AnyFunSuite
import org.slf4j.LoggerFactory
import tofu.Delay
Expand Down Expand Up @@ -55,11 +54,15 @@ class TofuLoggingProviderSuite extends AnyFunSuite {
}

object TofuLoggingProviderSuite {
@derive(tofu.logging.derivation.loggable)
final case class LoggingContext(inner: LoggingContextInner, what: String)
object LoggingContext {
implicit val loggable: Loggable[LoggingContext] = tofu.logging.derivation.loggable.instance
}

@derive(tofu.logging.derivation.loggable)
final case class LoggingContextInner(keks: Int, shreks: Int)
object LoggingContextInner {
implicit val loggable: Loggable[LoggingContextInner] = tofu.logging.derivation.loggable.instance
}

val ExampleCtx = LoggingContext(LoggingContextInner(2, 3), "swamp")
}

0 comments on commit 4c85346

Please sign in to comment.