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

Update versions to support Scala Native #104

Merged
merged 7 commits into from
Apr 8, 2021
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
56 changes: 32 additions & 24 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import sbtcrossproject.CrossPlugin.autoImport.crossProject
import com.typesafe.tools.mima.core._

lazy val V = new {
def munit = "0.7.2"
def munit = "0.7.23"
}
val scala211 = "2.11.12"
val scala212 = "2.12.11"
val scala213 = "2.13.1"
val ScalaVersions = List(scala212, scala211, scala213)
val scala212 = "2.12.13"
val scala213 = "2.13.5"
val ScalaVersions = List(scala212, scala213)
inThisBuild(
List(
useSuperShell := false,
Expand Down Expand Up @@ -73,6 +72,7 @@ val languageAgnosticCompatibilityPolicy: ProblemFilter = (problem: Problem) => {
lazy val sharedSettings = List[Setting[_]](
scalacOptions ++= List(
"-Yrangepos",
"-deprecation",
warnUnusedImport.value
),
mimaBinaryIssueFilters ++= List[ProblemFilter](
Expand All @@ -84,22 +84,21 @@ lazy val sharedSettings = List[Setting[_]](
skip.in(publish) := true
disablePlugins(MimaPlugin)

lazy val core = crossProject(JVMPlatform, JSPlatform)
lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.in(file("metaconfig-core"))
.settings(
sharedSettings,
moduleName := "metaconfig-core",
libraryDependencies ++= List(
"org.typelevel" %%% "paiges-core" % "0.3.0",
"org.scala-lang.modules" %%% "scala-collection-compat" % "2.1.2",
scalaOrganization.value % "scala-reflect" % scalaVersion.value % Provided
) :+ (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 11)) => "com.lihaoyi" %%% "pprint" % "0.5.4"
case _ => "com.lihaoyi" %%% "pprint" % "0.5.9"
})
"org.typelevel" %%% "paiges-core" % "0.4.1",
"org.scala-lang.modules" %%% "scala-collection-compat" % "2.4.3",
scalaOrganization.value % "scala-reflect" % scalaVersion.value % Provided,
"com.lihaoyi" %%% "pprint" % "0.6.4"
)
)
lazy val coreJVM = core.jvm
lazy val coreJS = core.js
lazy val coreNative = core.native

lazy val json = project
.in(file("metaconfig-json"))
Expand All @@ -118,27 +117,34 @@ lazy val typesafe = project
sharedSettings,
moduleName := "metaconfig-typesafe-config",
description := "Integration for HOCON using typesafehub/config.",
libraryDependencies += "com.typesafe" % "config" % "1.2.1"
libraryDependencies += "com.typesafe" % "config" % "1.4.1"
)
.dependsOn(coreJVM)

lazy val sconfig = crossProject(JVMPlatform)
lazy val sconfig = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.in(file("metaconfig-sconfig"))
.settings(
sharedSettings,
moduleName := "metaconfig-sconfig",
description := "Integration for HOCON using ekrich/sconfig.",
libraryDependencies ++= List(
"org.ekrich" %%% "sconfig" % "1.0.0"
"org.ekrich" %%% "sconfig" % "1.4.2"
)
)
.jsSettings(
libraryDependencies ++= List(
"org.ekrich" %%% "sjavatime" % "1.1.3"
)
)
.nativeSettings(
libraryDependencies ++= List(
"org.ekrich" %%% "sjavatime" % "1.1.3"
)
)
.dependsOn(core)
lazy val sconfigJVM = sconfig.jvm

val scalatagsVersion = Def.setting {
if (scalaVersion.value.startsWith("2.11")) "0.6.7"
else "0.7.0"
}
lazy val sconfigJS = sconfig.js
lazy val sconfigNative = sconfig.native

lazy val tests = crossProject(JVMPlatform, JSPlatform)
.in(file("metaconfig-tests"))
Expand All @@ -150,10 +156,12 @@ lazy val tests = crossProject(JVMPlatform, JSPlatform)
testFrameworks := List(new TestFramework("munit.Framework")),
libraryDependencies ++= List(
"org.scalameta" %%% "munit-scalacheck" % V.munit,
"com.github.alexarchambault" %%% "scalacheck-shapeless_1.14" % "1.2.3"
"com.github.alexarchambault" %%% "scalacheck-shapeless_1.14" % "1.2.5" // no native
)
)
.jsSettings(scalaJSModuleKind := ModuleKind.CommonJSModule)
.jsSettings(
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule))
)
.jvmSettings(
mainClass in GraalVMNativeImage := Some("metaconfig.tests.ExampleMain"),
sources.in(Compile, doc) := Seq.empty,
Expand Down Expand Up @@ -191,7 +199,7 @@ lazy val docs = project
sharedSettings,
moduleName := "metaconfig-docs",
libraryDependencies ++= List(
"com.lihaoyi" %% "scalatags" % scalatagsVersion.value
"com.lihaoyi" %% "scalatags" % "0.9.4"
),
mdocVariables := Map(
"VERSION" -> version.value.replaceFirst("\\+.*", ""),
Expand Down
27 changes: 13 additions & 14 deletions metaconfig-json/src/main/scala/metaconfig/JsonSchema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package metaconfig
import metaconfig.generic.Setting
import metaconfig.generic.Settings
import metaconfig.internal.JsonConverter
import ujson._

object JsonSchema {

Expand All @@ -12,7 +11,7 @@ object JsonSchema {
description: String,
url: Option[String],
default: T
)(implicit settings: Settings[T]): Js.Obj = {
)(implicit settings: Settings[T]): ujson.Value = {
ConfEncoder[T].write(default) match {
case obj: Conf.Obj =>
this.generate[T](title, description, url, obj)
Expand All @@ -26,16 +25,16 @@ object JsonSchema {
description: String,
url: Option[String],
default: Conf.Obj
)(implicit settings: Settings[T]): Js.Obj = {
)(implicit settings: Settings[T]): ujson.Value = {

val properties: List[(String, Js.Obj)] = settings.settings
val properties: List[(String, ujson.Value)] = settings.settings
.zip(default.values)
.map { case (s, (_, v)) => fromSetting(s, v) }

Js.Obj(
"$id" -> url.map(Js.Str).getOrElse(Js.Null),
"title" -> Js.Str(title),
"description" -> Js.Str(description),
ujson.Obj(
"$id" -> url.map(ujson.Str).getOrElse(ujson.Null),
"title" -> ujson.Str(title),
"description" -> ujson.Str(description),
"type" -> "object",
"properties" -> properties
)
Expand All @@ -44,13 +43,13 @@ object JsonSchema {
private def fromSetting(
setting: Setting,
defaultValue: Conf
): (String, Js.Obj) = {
): (String, ujson.Value) = {
val defaultJsonValue = JsonConverter.toJson(defaultValue)
val obj = Js.Obj(
"title" -> Js.Str(setting.name),
"description" -> setting.description.map(Js.Str).getOrElse(Js.Null),
val obj = ujson.Obj(
"title" -> ujson.Str(setting.name),
"description" -> setting.description.map(ujson.Str).getOrElse(ujson.Null),
"default" -> defaultJsonValue,
"required" -> Js.False, // TODO: How should we handle required
"required" -> ujson.False, // TODO: How should we handle required
"type" -> toSchemaType(defaultValue)
)
defaultValue match {
Expand All @@ -69,7 +68,7 @@ object JsonSchema {
setting.name -> obj
}

private def toSchemaType(conf: Conf): Js.Str = Js.Str(
private def toSchemaType(conf: Conf): ujson.Str = ujson.Str(
conf match {
// https://tools.ietf.org/html/draft-handrews-json-schema-01#section-4.2.1
case _: Conf.Bool => "boolean"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,45 @@ package metaconfig.internal

import metaconfig.Conf
import metaconfig.Input
import ujson._

object JsonConverter {

def fromInput(input: Input): Js = {
val readable = Readable.fromTransformer(input, JsonConfParser)
val js = readable.transform(Js)
def fromInput(input: Input): ujson.Value = {
val readable = ujson.Readable.fromTransformer(input, JsonConfParser)
val js = readable.transform(ujson.Value)
js
}

def toConf(js: Js): Conf = js match {
case Js.Obj(values) =>
def toConf(js: ujson.Value): Conf = js match {
case ujson.Obj(values) =>
Conf.Obj(values.iterator.map {
case (key, value) => key -> toConf(value)
}.toList)
case Js.Arr(values) =>
case ujson.Arr(values) =>
Conf.Lst(values.iterator.map(toConf).toList)
case Js.Bool(value) =>
case ujson.Bool(value) =>
Conf.Bool(value)
case Js.Num(value) =>
case ujson.Num(value) =>
Conf.Num(value)
case Js.Str(value) =>
case ujson.Str(value) =>
Conf.Str(value)
case Js.Null =>
case ujson.Null =>
Conf.Null()
}

import Js.Obj._
def toJson(conf: Conf): Js.Value = conf match {
import ujson.Obj._
def toJson(conf: Conf): ujson.Value = conf match {
case Conf.Obj(values) =>
values.map { case (k, v) => k -> toJson(v) }
case Conf.Lst(values) =>
Js.Arr(values.map(toJson): _*)
ujson.Arr(values.map(toJson): _*)
case Conf.Null() =>
Js.Null
ujson.Null
case Conf.Str(value) =>
Js.Str(value)
ujson.Str(value)
case Conf.Num(value) =>
Js.Num(value.toDouble)
ujson.Num(value.toDouble)
case Conf.Bool(value) =>
Js.Bool(value)
ujson.Bool(value)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package metaconfig.internal

import metaconfig.Input
import ujson._

class JsonConfErrorSuite extends munit.FunSuite {
def checkError(
Expand All @@ -12,11 +11,11 @@ class JsonConfErrorSuite extends munit.FunSuite {
test(path) {
val e = intercept[Exception] {
val readable =
Readable.fromTransformer[Input](
ujson.Readable.fromTransformer[Input](
Input.VirtualFile(path, original),
JsonConfParser
)
readable.transform(Js)
readable.transform(ujson.Value)
}
assertNoDiff(e.getMessage, expected)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package metaconfig.internal

import metaconfig.Input
import ujson._
import scala.util.Properties

class JsonConfParserSuite extends munit.FunSuite {

def check(original: String, expected: Js): Unit = {
def check(original: String, expected: ujson.Value): Unit = {
test(original) {
assume(
!Properties.isWin,
Expand All @@ -21,7 +20,7 @@ class JsonConfParserSuite extends munit.FunSuite {
"""{
| "a":1
|}""".stripMargin,
Js.Obj("a" -> Js.Num(1))
ujson.Obj("a" -> ujson.Num(1))
)

// comments
Expand All @@ -37,10 +36,10 @@ class JsonConfParserSuite extends munit.FunSuite {
| ] // close
|}
|""".stripMargin,
Js.Obj(
"a" -> Js.Num(1),
"b" -> Js.Num(2),
"c" -> Js.Arr(Js.Num(3))
ujson.Obj(
"a" -> ujson.Num(1),
"b" -> ujson.Num(2),
"c" -> ujson.Arr(ujson.Num(3))
)
)

Expand All @@ -58,17 +57,17 @@ class JsonConfParserSuite extends munit.FunSuite {
|
|}
""".stripMargin,
Js.Obj(
"b" -> Js.Arr(Js.Num(1), Js.Num(2)),
"a" -> Js.Num(2)
ujson.Obj(
"b" -> ujson.Arr(ujson.Num(1), ujson.Num(2)),
"a" -> ujson.Num(2)
)
)

check(
"""
|{ "a": [1,], }
""".stripMargin,
Js.Obj("a" -> Js.Arr(1))
ujson.Obj("a" -> ujson.Arr(1))
)

}
18 changes: 9 additions & 9 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.6.1")
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.4.31")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.2.1")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.7.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.14")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.32")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.1")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "0.6.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.9")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.8.1")
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.7")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.2.19")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.8.1")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.27")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.5.1")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.0.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.0")