Skip to content

Commit 0800f7f

Browse files
committed
scala3: wip
1 parent e2e1f80 commit 0800f7f

File tree

12 files changed

+195
-96
lines changed

12 files changed

+195
-96
lines changed

build.sbt

Lines changed: 59 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,24 +1623,18 @@ lazy val `distage-core-proxy-bytebuddy` = project.in(file("distage/distage-core-
16231623
)
16241624
.disablePlugins(AssemblyPlugin)
16251625

1626-
lazy val `distage-core` = project.in(file("distage/distage-core"))
1626+
lazy val `distage-framework-api` = project.in(file("distage/distage-framework-api"))
16271627
.dependsOn(
1628-
`distage-core-api` % "test->compile;compile->compile",
1629-
`distage-core-proxy-bytebuddy` % "test->compile;compile->compile"
1628+
`distage-core-api` % "test->compile;compile->compile"
16301629
)
16311630
.settings(
16321631
libraryDependencies ++= Seq(
16331632
"org.scala-lang.modules" %% "scala-collection-compat" % V.collection_compat,
1634-
"org.scalatest" %% "scalatest" % V.scalatest % Test,
1635-
"org.typelevel" %% "cats-core" % V.cats % Optional,
1636-
"org.typelevel" %% "cats-effect" % V.cats_effect % Optional,
1637-
"dev.zio" %% "zio" % V.zio % Optional excludeAll("dev.zio" %% "izumi-reflect"),
1638-
"dev.zio" %% "izumi-reflect" % V.izumi_reflect % Optional,
1639-
"dev.zio" %% "zio-interop-cats" % V.zio_interop_cats % Optional excludeAll("dev.zio" %% "izumi-reflect"),
1640-
"javax.inject" % "javax.inject" % "1" % Test
1633+
"org.scalatest" %% "scalatest" % V.scalatest % Test
16411634
),
16421635
libraryDependencies ++= { if (scalaVersion.value.startsWith("2.")) Seq(
1643-
compilerPlugin("org.typelevel" % "kind-projector" % V.kind_projector cross CrossVersion.full)
1636+
compilerPlugin("org.typelevel" % "kind-projector" % V.kind_projector cross CrossVersion.full),
1637+
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided
16441638
) else Seq.empty }
16451639
)
16461640
.settings(
@@ -1769,21 +1763,24 @@ lazy val `distage-core` = project.in(file("distage/distage-core"))
17691763
)
17701764
.disablePlugins(AssemblyPlugin)
17711765

1772-
lazy val `distage-extension-config` = project.in(file("distage/distage-extension-config"))
1766+
lazy val `distage-core` = project.in(file("distage/distage-core"))
17731767
.dependsOn(
17741768
`distage-core-api` % "test->compile;compile->compile",
1775-
`distage-core` % "test->compile"
1769+
`distage-core-proxy-bytebuddy` % "test->compile;compile->compile"
17761770
)
17771771
.settings(
17781772
libraryDependencies ++= Seq(
17791773
"org.scala-lang.modules" %% "scala-collection-compat" % V.collection_compat,
1780-
"org.scalatest" %% "scalatest" % V.scalatest % Test
1774+
"org.scalatest" %% "scalatest" % V.scalatest % Test,
1775+
"org.typelevel" %% "cats-core" % V.cats % Optional,
1776+
"org.typelevel" %% "cats-effect" % V.cats_effect % Optional,
1777+
"dev.zio" %% "zio" % V.zio % Optional excludeAll("dev.zio" %% "izumi-reflect"),
1778+
"dev.zio" %% "izumi-reflect" % V.izumi_reflect % Optional,
1779+
"dev.zio" %% "zio-interop-cats" % V.zio_interop_cats % Optional excludeAll("dev.zio" %% "izumi-reflect"),
1780+
"javax.inject" % "javax.inject" % "1" % Test
17811781
),
17821782
libraryDependencies ++= { if (scalaVersion.value.startsWith("2.")) Seq(
1783-
compilerPlugin("org.typelevel" % "kind-projector" % V.kind_projector cross CrossVersion.full),
1784-
"com.github.pureconfig" %% "pureconfig-magnolia" % V.pureconfig,
1785-
"com.propensive" %% "magnolia" % V.magnolia,
1786-
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided
1783+
compilerPlugin("org.typelevel" % "kind-projector" % V.kind_projector cross CrossVersion.full)
17871784
) else Seq.empty }
17881785
)
17891786
.settings(
@@ -1908,45 +1905,25 @@ lazy val `distage-extension-config` = project.in(file("distage/distage-extension
19081905
"-opt-inline-from:izumi.**"
19091906
)
19101907
case (_, _) => Seq.empty
1911-
} },
1912-
Compile / unmanagedSourceDirectories ++= {
1913-
val version = scalaVersion.value
1914-
val crossVersions = crossScalaVersions.value
1915-
import Ordering.Implicits._
1916-
val ltEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ <= CrossVersion.partialVersion(version)).flatten
1917-
(Compile / unmanagedSourceDirectories).value.flatMap {
1918-
case dir if dir.getPath.endsWith("scala") => ltEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n+") }
1919-
case _ => Seq.empty
1920-
}
1921-
},
1922-
Test / unmanagedSourceDirectories ++= {
1923-
val version = scalaVersion.value
1924-
val crossVersions = crossScalaVersions.value
1925-
import Ordering.Implicits._
1926-
val ltEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ <= CrossVersion.partialVersion(version)).flatten
1927-
(Test / unmanagedSourceDirectories).value.flatMap {
1928-
case dir if dir.getPath.endsWith("scala") => ltEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n+") }
1929-
case _ => Seq.empty
1930-
}
1931-
}
1908+
} }
19321909
)
19331910
.disablePlugins(AssemblyPlugin)
19341911

1935-
lazy val `distage-extension-plugins` = project.in(file("distage/distage-extension-plugins"))
1912+
lazy val `distage-extension-config` = project.in(file("distage/distage-extension-config"))
19361913
.dependsOn(
19371914
`distage-core-api` % "test->compile;compile->compile",
1938-
`distage-core` % "test->compile",
1939-
`distage-extension-config` % "test->compile",
1940-
`logstage-core` % "test->compile"
1915+
`distage-core` % "test->compile"
19411916
)
19421917
.settings(
19431918
libraryDependencies ++= Seq(
19441919
"org.scala-lang.modules" %% "scala-collection-compat" % V.collection_compat,
19451920
"org.scalatest" %% "scalatest" % V.scalatest % Test,
1946-
"io.github.classgraph" % "classgraph" % V.classgraph
1921+
"com.github.pureconfig" %% "pureconfig-core" % V.pureconfig
19471922
),
19481923
libraryDependencies ++= { if (scalaVersion.value.startsWith("2.")) Seq(
19491924
compilerPlugin("org.typelevel" % "kind-projector" % V.kind_projector cross CrossVersion.full),
1925+
"com.github.pureconfig" %% "pureconfig-magnolia" % V.pureconfig,
1926+
"com.propensive" %% "magnolia" % V.magnolia,
19501927
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided
19511928
) else Seq.empty }
19521929
)
@@ -2072,25 +2049,46 @@ lazy val `distage-extension-plugins` = project.in(file("distage/distage-extensio
20722049
"-opt-inline-from:izumi.**"
20732050
)
20742051
case (_, _) => Seq.empty
2075-
} }
2052+
} },
2053+
Compile / unmanagedSourceDirectories ++= {
2054+
val version = scalaVersion.value
2055+
val crossVersions = crossScalaVersions.value
2056+
import Ordering.Implicits._
2057+
val ltEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ <= CrossVersion.partialVersion(version)).flatten
2058+
(Compile / unmanagedSourceDirectories).value.flatMap {
2059+
case dir if dir.getPath.endsWith("scala") => ltEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n+") }
2060+
case _ => Seq.empty
2061+
}
2062+
},
2063+
Test / unmanagedSourceDirectories ++= {
2064+
val version = scalaVersion.value
2065+
val crossVersions = crossScalaVersions.value
2066+
import Ordering.Implicits._
2067+
val ltEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ <= CrossVersion.partialVersion(version)).flatten
2068+
(Test / unmanagedSourceDirectories).value.flatMap {
2069+
case dir if dir.getPath.endsWith("scala") => ltEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n+") }
2070+
case _ => Seq.empty
2071+
}
2072+
}
20762073
)
20772074
.disablePlugins(AssemblyPlugin)
20782075

2079-
lazy val `distage-extension-logstage` = project.in(file("distage/distage-extension-logstage"))
2076+
lazy val `distage-extension-plugins` = project.in(file("distage/distage-extension-plugins"))
20802077
.dependsOn(
2081-
`distage-extension-config` % "test->compile;compile->compile",
20822078
`distage-core-api` % "test->compile;compile->compile",
20832079
`distage-core` % "test->compile",
2084-
`logstage-core` % "test->test;compile->compile"
2080+
`distage-extension-config` % "test->compile",
2081+
`logstage-core` % "test->compile"
20852082
)
20862083
.settings(
20872084
libraryDependencies ++= Seq(
20882085
"org.scala-lang.modules" %% "scala-collection-compat" % V.collection_compat,
20892086
"org.scalatest" %% "scalatest" % V.scalatest % Test,
2090-
"dev.zio" %% "zio" % V.zio % Test excludeAll("dev.zio" %% "izumi-reflect")
2087+
"io.github.classgraph" % "classgraph" % V.classgraph
20912088
),
20922089
libraryDependencies ++= { if (scalaVersion.value.startsWith("2.")) Seq(
2093-
compilerPlugin("org.typelevel" % "kind-projector" % V.kind_projector cross CrossVersion.full)
2090+
compilerPlugin("org.typelevel" % "kind-projector" % V.kind_projector cross CrossVersion.full),
2091+
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided
20942092
) else Seq.empty }
20952093
)
20962094
.settings(
@@ -2219,18 +2217,21 @@ lazy val `distage-extension-logstage` = project.in(file("distage/distage-extensi
22192217
)
22202218
.disablePlugins(AssemblyPlugin)
22212219

2222-
lazy val `distage-framework-api` = project.in(file("distage/distage-framework-api"))
2220+
lazy val `distage-extension-logstage` = project.in(file("distage/distage-extension-logstage"))
22232221
.dependsOn(
2224-
`distage-core-api` % "test->compile;compile->compile"
2222+
`distage-extension-config` % "test->compile;compile->compile",
2223+
`distage-core-api` % "test->compile;compile->compile",
2224+
`distage-core` % "test->compile",
2225+
`logstage-core` % "test->test;compile->compile"
22252226
)
22262227
.settings(
22272228
libraryDependencies ++= Seq(
22282229
"org.scala-lang.modules" %% "scala-collection-compat" % V.collection_compat,
2229-
"org.scalatest" %% "scalatest" % V.scalatest % Test
2230+
"org.scalatest" %% "scalatest" % V.scalatest % Test,
2231+
"dev.zio" %% "zio" % V.zio % Test excludeAll("dev.zio" %% "izumi-reflect")
22302232
),
22312233
libraryDependencies ++= { if (scalaVersion.value.startsWith("2.")) Seq(
2232-
compilerPlugin("org.typelevel" % "kind-projector" % V.kind_projector cross CrossVersion.full),
2233-
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided
2234+
compilerPlugin("org.typelevel" % "kind-projector" % V.kind_projector cross CrossVersion.full)
22342235
) else Seq.empty }
22352236
)
22362237
.settings(
@@ -3555,11 +3556,11 @@ lazy val `microsite` = project.in(file("doc/microsite"))
35553556
`fundamentals-bio` % "test->compile;compile->compile",
35563557
`distage-core-api` % "test->compile;compile->compile",
35573558
`distage-core-proxy-bytebuddy` % "test->compile;compile->compile",
3559+
`distage-framework-api` % "test->compile;compile->compile",
35583560
`distage-core` % "test->compile;compile->compile",
35593561
`distage-extension-config` % "test->compile;compile->compile",
35603562
`distage-extension-plugins` % "test->compile;compile->compile",
35613563
`distage-extension-logstage` % "test->compile;compile->compile",
3562-
`distage-framework-api` % "test->compile;compile->compile",
35633564
`distage-framework` % "test->compile;compile->compile",
35643565
`distage-framework-docker` % "test->compile;compile->compile",
35653566
`distage-testkit-core` % "test->compile;compile->compile",
@@ -3966,11 +3967,11 @@ lazy val `distage` = (project in file(".agg/distage-distage"))
39663967
.aggregate(
39673968
`distage-core-api`,
39683969
`distage-core-proxy-bytebuddy`,
3970+
`distage-framework-api`,
39693971
`distage-core`,
39703972
`distage-extension-config`,
39713973
`distage-extension-plugins`,
39723974
`distage-extension-logstage`,
3973-
`distage-framework-api`,
39743975
`distage-framework`,
39753976
`distage-framework-docker`,
39763977
`distage-testkit-core`,
@@ -3990,11 +3991,11 @@ lazy val `distage-jvm` = (project in file(".agg/distage-distage-jvm"))
39903991
.aggregate(
39913992
`distage-core-api`,
39923993
`distage-core-proxy-bytebuddy`,
3994+
`distage-framework-api`,
39933995
`distage-core`,
39943996
`distage-extension-config`,
39953997
`distage-extension-plugins`,
39963998
`distage-extension-logstage`,
3997-
`distage-framework-api`,
39983999
`distage-framework`,
39994000
`distage-framework-docker`,
40004001
`distage-testkit-core`,

distage/distage-extension-config/src/main/scala/izumi/distage/config/codec/PureconfigAutoDerive.scala renamed to distage/distage-extension-config/src/main/scala-2/izumi/distage/config/codec/PureconfigAutoDerive.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ object PureconfigAutoDerive {
4444

4545
object PureconfigAutoDeriveMacro {
4646
def materializeImpl[A: c.WeakTypeTag](c: blackbox.Context): c.Expr[PureconfigAutoDerive[A]] = {
47-
import c.universe._
47+
import c.universe.*
4848
c.Expr[PureconfigAutoDerive[A]] {
4949
// Yes, this is legal /_\ !! We add an import so that implicit scope is enhanced
5050
// by new config codecs that aren't in ConfigReader companion object

distage/distage-extension-config/src/main/scala/izumi/distage/config/codec/PureconfigInstances.scala renamed to distage/distage-extension-config/src/main/scala-2/izumi/distage/config/codec/PureconfigInstances.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package izumi.distage.config.codec
22

33
import com.typesafe.config.{ConfigMemorySize, ConfigValue}
4+
import pureconfig.*
45
import pureconfig.ConfigReader.Result
5-
import pureconfig._
66
import pureconfig.error.{CannotConvert, ConfigReaderFailures, ThrowableFailure}
77
import pureconfig.generic.error.{InvalidCoproductOption, NoValidCoproductOptionFound}
88
import pureconfig.generic.{CoproductHint, ProductHint}
@@ -74,7 +74,7 @@ object PureconfigInstances extends PureconfigInstances {
7474
} yield res
7575
}
7676
override def to(cv: ConfigValue, name: String): ConfigValue = {
77-
import pureconfig.syntax._
77+
import pureconfig.syntax.*
7878
Map(name -> cv).toConfig
7979
}
8080
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package izumi.distage.config.codec
2+
3+
import pureconfig.ConfigReader
4+
5+
6+
/**
7+
* Derive `pureconfig.ConfigReader` for A and for its fields recursively with `pureconfig-magnolia`
8+
*
9+
* This differs from just using [[pureconfig.module.magnolia.auto.reader.exportReader]] by using
10+
* different configuration, defined in [[PureconfigInstances]], specifically:
11+
*
12+
* 1. Field name remapping is disabled, `camelCase` fields will remain camelCase, not `kebab-case`
13+
* 2. Sealed traits are rendered as in `circe`, using a wrapper object with a single field, instead of using a `type` field. Example:
14+
*
15+
* {{{
16+
* sealed trait AorB
17+
* final case class A(a: Int) extends AorB
18+
* final case class B(b: String) extends AorB
19+
*
20+
* final case class Config(values: List[AorB])
21+
* }}}
22+
*
23+
* in config:
24+
*
25+
* {{{
26+
* config {
27+
* values = [
28+
* { A { a = 123 } },
29+
* { B { b = cba } }
30+
* ]
31+
* }
32+
* }}}
33+
*/
34+
final class PureconfigAutoDerive[A](val value: ConfigReader[A]) extends AnyVal
35+
36+
object PureconfigAutoDerive {
37+
@inline def apply[A](implicit ev: PureconfigAutoDerive[A]): ConfigReader[A] = ev.value
38+
39+
@inline def derived[A](implicit ev: PureconfigAutoDerive[A]): ConfigReader[A] = ev.value
40+
41+
implicit def materialize[A]: PureconfigAutoDerive[A] = ???
42+
}

distage/distage-extension-plugins/src/main/scala/izumi/distage/plugins/ForcedRecompilationToken.scala renamed to distage/distage-extension-plugins/src/main/scala-2/izumi/distage/plugins/ForcedRecompilationToken.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object ForcedRecompilationToken {
3232
var cachedTypedTree: Universe#Tree = null
3333

3434
def whiteboxMaterializeImpl(c: whitebox.Context): c.Tree = {
35-
import c.universe._
35+
import c.universe.*
3636

3737
UniqueRecompilationTokenMacro.synchronized {
3838
if (cachedTypedTree eq null) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package izumi.distage.plugins
2+
3+
import izumi.distage.plugins.StaticPluginLoader.StaticPluginLoaderMacro
4+
import scala.language.experimental.macros
5+
6+
trait PluginConfigStatic {
7+
/** Scan the specified package *at compile-time* for classes and objects that inherit [[PluginBase]]
8+
*
9+
* WARN: may interact badly with incremental compilation
10+
* WARN: will _not_ find plugins defined in the current module, only those defined in dependency modules
11+
* (similarly to how you cannot call Scala macros defined in the current module)
12+
*/
13+
def compileTime(pluginsPackage: String): PluginConfig = macro StaticPluginLoaderMacro.scanCompileTimeConfig
14+
15+
/** Scan the the current source file's package *at compile-time* for classes and objects that inherit [[PluginBase]]
16+
*
17+
* WARN: may interact badly with incremental compilation
18+
* WARN: will _not_ find plugins defined in the current module, only those defined in dependency modules
19+
* (similarly to how you cannot call Scala macros defined in the current module)
20+
*/
21+
def compileTimeThisPkg: PluginConfig = macro StaticPluginLoaderMacro.scanCompileTimeConfigThisPkg
22+
}

distage/distage-extension-plugins/src/main/scala/izumi/distage/plugins/StaticPluginLoader.scala renamed to distage/distage-extension-plugins/src/main/scala-2/izumi/distage/plugins/StaticPluginLoader.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package izumi.distage.plugins
22

3-
import scala.language.experimental.macros
43
import izumi.distage.plugins.load.{LoadedPlugins, PluginLoaderDefaultImpl}
54
import izumi.fundamentals.platform.language.SourcePackageMaterializer.SourcePackageMaterializerMacro
65
import izumi.fundamentals.reflection.ReflectionUtil
76

87
import scala.reflect.macros.blackbox
9-
import scala.reflect.runtime.{universe => ru}
108

119
/** Scan the specified package *at compile-time* for classes and objects that inherit [[PluginBase]]
1210
*
@@ -43,7 +41,7 @@ object StaticPluginLoader {
4341
}
4442

4543
def scanCompileTimeImpl(c: blackbox.Context)(pluginPath: String): c.Expr[List[PluginBase]] = {
46-
import c.universe._
44+
import c.universe.*
4745

4846
val loadedPlugins = if (pluginPath == "") {
4947
LoadedPlugins.empty
@@ -57,7 +55,7 @@ object StaticPluginLoader {
5755
}
5856

5957
def instantiatePluginsInCode(c: blackbox.Context)(loadedPlugins: Seq[PluginBase]): List[c.Tree] = {
60-
import c.universe._
58+
import c.universe.*
6159
val runtimeMirror = ru.runtimeMirror(this.getClass.getClassLoader)
6260
loadedPlugins.map {
6361
plugin =>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package izumi.distage.plugins
2+
3+
import scala.annotation.implicitNotFound
4+
5+
/**
6+
* This macro allows `distage`'s compile-time checks to cooperate with Scala's incremental compilation:
7+
* it forces recompilation of the macro that performs compile-time plan checking every time a PluginDef's body changes.
8+
*
9+
* It does that by generating a new unique type for each compiler session and assigning it to the class that inherits PluginDef.
10+
* The "change of super type" of a plugin forces recompilation of all code that references it, and specifically of the
11+
* code generated by [[izumi.distage.framework.PlanCheckMacro]].
12+
*
13+
* This allows compile-time checking macro to re-run on relevant changes and provide rapid feedback during development.
14+
*
15+
* @see [[https://izumi.7mind.io/distage/distage-framework.html#compile-time-checks Compile-time checks]]
16+
*/
17+
@implicitNotFound("""Could not find implicit for `izumi.distage.plugins.ForcedRecompilationToken[${T}]`.
18+
This is supposed to be impossible, but is sometimes observed under mdoc & scaladoc,
19+
in which case you'll have to put a dummy implicit in scope, such as by using:
20+
21+
import izumi.distage.plugins.ForcedRecompilationToken.disabled._""")
22+
final abstract class ForcedRecompilationToken[T]
23+
24+
object ForcedRecompilationToken {
25+
implicit def materialize[T]: ForcedRecompilationToken[T] = ???
26+
27+
object disabled {
28+
implicit def disable: ForcedRecompilationToken[Unit] = null
29+
}
30+
}

0 commit comments

Comments
 (0)