Skip to content

Commit d3d21ce

Browse files
authored
Merge pull request #185 from lolgab/scala-native-scala-3
Support Scala Native + Scala 3
2 parents 462e49c + 6232a9d commit d3d21ce

File tree

10 files changed

+83
-91
lines changed

10 files changed

+83
-91
lines changed

build.sbt

+41-56
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import sbtcrossproject.CrossPlugin.autoImport.crossProject
33
import com.typesafe.tools.mima.core._
44

55
lazy val V = new {
6-
def munit = "0.7.29"
6+
def munit = "1.0.0-M10"
7+
def scalacheck = "1.17.0"
78
}
89
val scala212 = "2.12.15"
910
val scala213 = "2.13.8"
10-
val scala3 = "3.1.3"
11+
val scala3 = "3.3.1"
1112
val ScalaVersions = List(scala213, scala212, scala3)
1213
inThisBuild(
1314
List(
1415
useSuperShell := false,
15-
scalacOptions += "-Yrangepos",
1616
organization := "com.geirsson",
1717
version ~= { old => old.replace('+', '-') },
1818
licenses := Seq(
@@ -27,7 +27,7 @@ inThisBuild(
2727
"olafurpg@gmail.com",
2828
url("https://geirsson.com")
2929
),
30-
resolvers += Resolver.sonatypeRepo("snapshots"),
30+
resolvers ++= Resolver.sonatypeOssRepos("snapshots"),
3131
versionScheme := Some("early-semver")
3232
)
3333
)
@@ -53,10 +53,16 @@ commands += Command.command("taskready") { s =>
5353
}
5454

5555
lazy val warnUnusedImport = Def.setting {
56-
if (scalaVersion.value.startsWith("2.13")) "-Wunused:imports"
56+
if (scalaVersion.value.startsWith("2.13") ||
57+
scalaVersion.value.startsWith("3.")) "-Wunused:imports"
5758
else "-Ywarn-unused-import"
5859
}
5960

61+
lazy val yRangePos = Def.setting {
62+
if (scalaVersion.value.startsWith("3.")) Seq.empty[String]
63+
else Seq("-Yrangepos")
64+
}
65+
6066
val languageAgnosticCompatibilityPolicy: ProblemFilter = (problem: Problem) => {
6167
val (ref, fullName) = problem match {
6268
case problem: TemplateProblem => (problem.ref, problem.ref.fullName)
@@ -70,26 +76,30 @@ val languageAgnosticCompatibilityPolicy: ProblemFilter = (problem: Problem) => {
7076
}
7177

7278
lazy val sharedSettings = List[Setting[_]](
73-
scalacOptions ++= List(
74-
"-Yrangepos",
79+
scalacOptions ++= yRangePos.value,
80+
scalacOptions ++= Seq(
7581
"-deprecation",
7682
warnUnusedImport.value
7783
),
7884
mimaBinaryIssueFilters ++= List[ProblemFilter](
7985
languageAgnosticCompatibilityPolicy
8086
),
81-
mimaPreviousArtifacts := Set("com.geirsson" %% moduleName.value % "0.9.10"),
8287
crossScalaVersions := ScalaVersions,
8388
scalaVersion := scala213
8489
)
8590

86-
skip.in(publish) := true
91+
lazy val mimaSettings = List[Setting[_]](
92+
mimaPreviousArtifacts := Set("com.geirsson" %% moduleName.value % "0.9.10")
93+
)
94+
95+
publish / skip := true
8796
disablePlugins(MimaPlugin)
8897

8998
lazy val pprint = crossProject(JVMPlatform, JSPlatform, NativePlatform)
9099
.in(file("metaconfig-pprint"))
91100
.settings(
92101
sharedSettings,
102+
mimaSettings,
93103
moduleName := "metaconfig-pprint",
94104
libraryDependencies += "com.lihaoyi" %%% "fansi" % "0.4.0",
95105
libraryDependencies ++= {
@@ -101,18 +111,16 @@ lazy val pprint = crossProject(JVMPlatform, JSPlatform, NativePlatform)
101111
else Nil
102112
}
103113
)
104-
.nativeSettings(
105-
crossScalaVersions -= scala3
106-
)
107114

108115
lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform)
109116
.in(file("metaconfig-core"))
110117
.settings(
111118
sharedSettings,
119+
mimaSettings,
112120
moduleName := "metaconfig-core",
113121
libraryDependencies ++= List(
114-
"org.typelevel" %%% "paiges-core" % "0.4.2",
115-
"org.scala-lang.modules" %%% "scala-collection-compat" % "2.5.0"
122+
"org.typelevel" %%% "paiges-core" % "0.4.3",
123+
"org.scala-lang.modules" %%% "scala-collection-compat" % "2.11.0"
116124
)
117125
)
118126
.settings(
@@ -131,69 +139,56 @@ lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform)
131139
else Seq.empty
132140
}
133141
)
134-
.nativeSettings(
135-
crossScalaVersions -= scala3
136-
)
137142
.dependsOn(pprint)
138143

139-
lazy val coreJVM = core.jvm
140-
lazy val coreJS = core.js
141-
lazy val coreNative = core.native
142-
143144
lazy val typesafe = project
144145
.in(file("metaconfig-typesafe-config"))
145146
.settings(
146147
sharedSettings,
148+
mimaSettings,
147149
moduleName := "metaconfig-typesafe-config",
148150
description := "Integration for HOCON using typesafehub/config.",
149151
libraryDependencies += "com.typesafe" % "config" % "1.4.1"
150152
)
151-
.dependsOn(coreJVM)
153+
.dependsOn(core.jvm)
152154

153155
lazy val sconfig = crossProject(JVMPlatform, JSPlatform, NativePlatform)
154156
.in(file("metaconfig-sconfig"))
155157
.settings(
156158
sharedSettings,
159+
mimaSettings,
157160
moduleName := "metaconfig-sconfig",
158161
description := "Integration for HOCON using ekrich/sconfig.",
159162
libraryDependencies ++= List(
160-
"org.ekrich" %%% "sconfig" % "1.4.4"
163+
"org.ekrich" %%% "sconfig" % "1.5.1"
161164
)
162165
)
163-
.jsSettings(
166+
.platformsSettings(JSPlatform, NativePlatform)(
164167
libraryDependencies ++= List(
165-
"org.ekrich" %%% "sjavatime" % "1.1.5"
168+
"org.ekrich" %%% "sjavatime" % "1.1.9"
166169
)
167170
)
168-
.nativeSettings(
169-
libraryDependencies ++= List(
170-
"org.ekrich" %%% "sjavatime" % "1.1.3"
171-
),
172-
crossScalaVersions -= scala3
173-
)
174171
.dependsOn(core)
175-
lazy val sconfigJVM = sconfig.jvm
176-
lazy val sconfigJS = sconfig.js
177-
lazy val sconfigNative = sconfig.native
178172

179173
lazy val tests = crossProject(JVMPlatform, JSPlatform, NativePlatform)
180174
.in(file("metaconfig-tests"))
181175
.disablePlugins(MimaPlugin)
182176
.settings(
183177
sharedSettings,
184-
skip in publish := true,
185-
publishArtifact.in(Compile, packageDoc) := false,
178+
publish / skip := true,
179+
Compile / packageDoc / publishArtifact := false,
186180
testFrameworks := List(new TestFramework("munit.Framework")),
187181
libraryDependencies ++= List(
188-
"org.scalameta" %%% "munit-scalacheck" % V.munit
182+
"org.scalacheck" %%% "scalacheck" % V.scalacheck,
183+
"org.scalameta" %%% "munit-scalacheck" % V.munit % Test
189184
)
190185
)
191186
.jsSettings(
192187
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule))
193188
)
194189
.jvmSettings(
195-
mainClass in GraalVMNativeImage := Some("metaconfig.tests.ExampleMain"),
196-
sources.in(Compile, doc) := Seq.empty,
190+
GraalVMNativeImage / mainClass := Some("metaconfig.tests.ExampleMain"),
191+
Compile / doc / sources := Seq.empty,
197192
libraryDependencies ++= {
198193
if (scalaVersion.value.startsWith("2."))
199194
Seq(
@@ -203,7 +198,7 @@ lazy val tests = crossProject(JVMPlatform, JSPlatform, NativePlatform)
203198
},
204199
graalVMNativeImageOptions ++= {
205200
val reflectionFile =
206-
Keys.sourceDirectory.in(Compile).value./("graal")./("reflection.json")
201+
(Compile / Keys.sourceDirectory).value / "graal" / "reflection.json"
207202
assert(reflectionFile.exists, "no such file: " + reflectionFile)
208203
List(
209204
"-H:+ReportUnsupportedElementsAtRuntime",
@@ -223,39 +218,29 @@ lazy val tests = crossProject(JVMPlatform, JSPlatform, NativePlatform)
223218
)
224219
.jvmConfigure(
225220
_.enablePlugins(GraalVMNativeImagePlugin)
226-
.dependsOn(typesafe, sconfigJVM)
227-
)
228-
.nativeSettings(
229-
crossScalaVersions -= scala3
221+
.dependsOn(typesafe, sconfig.jvm)
230222
)
231223
.dependsOn(core)
232224

233-
lazy val testsJVM = tests.jvm
234-
lazy val testsJS = tests.js
235-
lazy val testsNative = tests.native
236-
237225
lazy val docs = project
238226
.in(file("metaconfig-docs"))
239227
.settings(
240228
sharedSettings,
241-
crossScalaVersions -= scala3,
242229
libraryDependencies ++= List(
243-
"org.scalameta" %%% "munit-scalacheck" % V.munit
230+
"com.lihaoyi" %%% "scalatags" % "0.12.0",
231+
"org.scalacheck" %%% "scalacheck" % V.scalacheck,
232+
"org.scalameta" %%% "munit-scalacheck" % V.munit % Test
244233
),
245234
moduleName := "metaconfig-docs",
246-
libraryDependencies ++= List(
247-
"com.lihaoyi" %% "scalatags" % "0.9.4"
248-
).filter(_ => scalaVersion.value.startsWith("2.")),
249235
mdocVariables := Map(
250236
"VERSION" -> version.value.replaceFirst("\\+.*", ""),
251237
"SCALA_VERSION" -> scalaVersion.value
252238
),
253-
mdocOut :=
254-
baseDirectory.in(ThisBuild).value / "website" / "target" / "docs",
239+
mdocOut := (ThisBuild / baseDirectory).value / "website" / "target" / "docs",
255240
mdocExtraArguments := List("--no-link-hygiene"),
256241
// mdoc's metaconfig might (and will eventually) lag behind the current version, causing eviction errors
257242
evictionErrorLevel := Level.Warn
258243
)
259-
.dependsOn(coreJVM, typesafe, sconfigJVM)
244+
.dependsOn(core.jvm, typesafe, sconfig.jvm)
260245
.enablePlugins(DocusaurusPlugin)
261246
.disablePlugins(MimaPlugin)

metaconfig-core/shared/src/main/scala-3/metaconfig/generic/package.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private[generic] def deriveConfDecoderImpl[T: Type](default: Expr[T])(using
9999

100100
if paramss.head.isEmpty then '{ ConfDecoder.constant($default) }
101101
else
102-
val (head :: params) :: Nil = paramss
102+
val (head :: params) :: Nil = paramss : @unchecked
103103
val vds = paramss.head.map(_.tree).collect { case vd: ValDef =>
104104
next(vd)
105105
}
@@ -176,7 +176,7 @@ private[generic] def deriveConfDecoderExImpl[T: Type](default: Expr[T])(using
176176
Configured.Ok(state.getOrElse($default))
177177
}
178178
else
179-
val (head :: params) :: Nil = paramss
179+
val (head :: params) :: Nil = paramss : @unchecked
180180
val vds = paramss.head.map(_.tree).collect { case vd: ValDef =>
181181
next(vd)
182182
}

metaconfig-core/shared/src/main/scala/metaconfig/Position.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ sealed abstract class Position { pos =>
1818
/** Returns a formatted string of this position including filename/line/caret. */
1919
final def pretty(severity: String, message: String): String = {
2020
// Predef.augmentString = work around scala/bug#11125 on JDK 11
21-
val content = augmentString(lineContent).lines
21+
val content = augmentString(lineContent).linesIterator
2222
val sb = new StringBuilder()
2323
sb.append(lineInput(severity, message))
2424
.append("\n")

metaconfig-core/shared/src/main/scala/metaconfig/internal/Case.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object Case {
99
while (m.find()) {
1010
m.appendReplacement(
1111
sb,
12-
m.group().charAt(1).toUpper + m.group().substring(2)
12+
m.group().charAt(1).toUpper.toString + m.group().substring(2)
1313
)
1414
}
1515
m.appendTail(sb)

metaconfig-pprint/shared/src/main/scala-2/metaconfig/pprint/TPrintImpl.scala

+10-7
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ object TPrintLowPri {
8282
val g = cas.global
8383
val gName = s.name.asInstanceOf[g.Name]
8484
val lookedUps =
85-
for (n <- Stream(gName.toTermName, gName.toTypeName)) yield {
85+
for (n <- Iterator(gName.toTermName, gName.toTypeName)) yield {
8686
cas.callsiteTyper.context
8787
.lookupSymbol(n, _ => true)
8888
.symbol
@@ -186,7 +186,7 @@ object TPrintLowPri {
186186
}
187187
}
188188
if (stmts.length == 0) None
189-
else Some(stmts.reduceLeft((l, r) => l + "; " + r))
189+
else Some(stmts.reduceLeft((l, r) => s"$l; $r"))
190190
}
191191

192192
tpe match {
@@ -195,8 +195,10 @@ object TPrintLowPri {
195195
(fansi.Str("_") ++ res, WrapType.NoWrap)
196196
case ThisType(sym) =>
197197
(
198-
printSymFull(sym) + (if (sym.isPackage || sym.isModuleClass) ""
199-
else ".this.type"),
198+
printSymFull(sym).toString +
199+
(if (sym.isPackage || sym.isModuleClass)
200+
""
201+
else ".this.type"),
200202
WrapType.NoWrap
201203
)
202204

@@ -273,11 +275,11 @@ object TPrintLowPri {
273275
)
274276
case AnnotatedType(annots, tp) =>
275277
val mapped = annots
276-
.map(x => " @" + typePrintImplRec(c)(x.tpe, true))
278+
.map(x => " @" + typePrintImplRec(c)(x.tree.tpe, true))
277279
.reduceLeft((x, y) => x + y)
278280

279281
(
280-
typePrintImplRec(c)(tp, true) + mapped,
282+
typePrintImplRec(c)(tp, true).toString + mapped,
281283
WrapType.NoWrap
282284
)
283285
case RefinedType(parents, defs) =>
@@ -288,7 +290,8 @@ object TPrintLowPri {
288290
.map(typePrintImplRec(c)(_, true))
289291
.reduceLeft[fansi.Str]((l, r) => l ++ " with " ++ r)
290292
(
291-
pre + (if (defs.isEmpty) "" else "{" ++ defs.mkString(";") ++ "}"),
293+
pre.toString + (if (defs.isEmpty) ""
294+
else "{" ++ defs.mkString(";") ++ "}"),
292295
WrapType.NoWrap
293296
)
294297
case ConstantType(value) =>

metaconfig-pprint/shared/src/main/scala-3/metaconfig/pprint/TPrintImpl.scala

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ object TPrintLowPri{
4343
def typePrintImpl[T](using Quotes, Type[T]): Expr[TPrint[T]] = {
4444

4545
import quotes.reflect._
46-
import util._
4746

4847
def literalColor(s: fansi.Str): fansi.Str = {
4948
fansi.Color.Green(s)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package metaconfig
2+
3+
import java.io.File
4+
5+
class DeriveSurfaceFileSuite extends munit.FunSuite {
6+
7+
case class WithFile(file: File)
8+
test("toString") {
9+
val surface = generic.deriveSurface[WithFile]
10+
val obtained = surface.toString
11+
assertNoDiff(
12+
obtained,
13+
"Surface(List(List(Field(name=\"file\",tpe=\"File\",annotations=List(@TabCompleteAsPath()),underlying=List()))))"
14+
)
15+
}
16+
}

0 commit comments

Comments
 (0)