Skip to content

Commit

Permalink
Merge pull request #91 from olafurpg/build-refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
olafurpg authored Apr 18, 2020
2 parents 62477af + 4711f71 commit aaab8fe
Show file tree
Hide file tree
Showing 66 changed files with 356 additions and 450 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@ jobs:
- uses: olafurpg/setup-scala@v2
- name: Test
run: sbt +test
checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: olafurpg/setup-scala@v7
- run: ./bin/scalafmt --check
- run: sbt scalafixCheckAll
6 changes: 6 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
rules = [
RemoveUnused,
ExplicitResultTypes,
]

ExplicitResultTypes.rewriteStructuralTypesToNamedSubclass = false
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "2.0.0"
version = "2.4.2"
assumeStandardLibraryStripMargin = true
align = none
project.git = true
Binary file added bin/scalafmt
Binary file not shown.
125 changes: 62 additions & 63 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import java.util.Date
import sbtcrossproject.CrossPlugin.autoImport.crossProject
lazy val V = new {
def munit = "0.7.2"
}
val scala211 = "2.11.12"
val scala212 = "2.12.10"
val scala212 = "2.12.11"
val scala213 = "2.13.1"
val ScalaVersions = List(scala212, scala211, scala213)
inThisBuild(
Expand All @@ -10,9 +13,7 @@ inThisBuild(
scalaVersion := scala212,
scalacOptions += "-Yrangepos",
organization := "com.geirsson",
version ~= { old =>
old.replace('+', '-')
},
version ~= { old => old.replace('+', '-') },
licenses := Seq(
"Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")
),
Expand All @@ -31,6 +32,15 @@ inThisBuild(
)
)

addCommandAlias(
"scalafixAll",
s"; ++$scala212 ; scalafixEnable ; all scalafix test:scalafix"
)
addCommandAlias(
"scalafixCheckAll",
s"; ++$scala212 ; scalafixEnable ; scalafix --check ; test:scalafix --check"
)

addCommandAlias(
"native-image",
"; tests/graalvm-native-image:packageBin ; taskready"
Expand All @@ -41,55 +51,24 @@ commands += Command.command("taskready") { s =>
s
}

lazy val testSettings = List(
testOptions.in(Test) +=
Tests.Argument(TestFrameworks.ScalaCheck, "-verbosity", "2"),
testFrameworks := List(
new TestFramework("munit.Framework"),
new TestFramework("org.scalacheck.ScalaCheckFramework")
),
libraryDependencies ++= {
if (SettingKey[Boolean]("nativeLinkStubs").?.value.contains(true))
List(
"org.scalameta" %%% "munit" % "0.4.5" % Test,
"com.github.lolgab" %%% "scalacheck" % "1.14.1" % Test
)
else
List(
"org.scalameta" %%% "munit" % "0.4.5" % Test,
"org.scalacheck" %%% "scalacheck" % "1.14.0" % Test,
"com.github.alexarchambault" %%% "scalacheck-shapeless_1.14" % "1.2.3" % Test
)
}
)
lazy val warnUnusedImport = Def.setting {
if (scalaVersion.value.startsWith("2.13")) "-Wunused:imports"
else "-Ywarn-unused-import"
}

lazy val nativeSettings = List(
nativeLinkStubs := true,
scalaVersion := scala211,
crossScalaVersions := List(scala211),
test.in(Test) := {}
lazy val sharedSettings = List[Setting[_]](
scalacOptions ++= List(
"-Yrangepos",
warnUnusedImport.value
)
)

skip.in(publish) := true

lazy val json = project
.in(file("metaconfig-json"))
.settings(
testSettings,
moduleName := "metaconfig-json",
libraryDependencies ++= List(
"org.scalameta" %% "testkit" % "4.1.12" % Test
) :+ (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 11 | 12)) => "com.lihaoyi" %%% "upickle" % "0.7.4"
case _ => "com.lihaoyi" %% "upickle" % "0.7.5"
})
)
.dependsOn(coreJVM)

lazy val core = crossProject(JVMPlatform, JSPlatform)
.in(file("metaconfig-core"))
.settings(
testSettings,
sharedSettings,
moduleName := "metaconfig-core",
libraryDependencies ++= List(
"org.typelevel" %%% "paiges-core" % "0.3.0",
Expand All @@ -100,54 +79,67 @@ lazy val core = crossProject(JVMPlatform, JSPlatform)
case _ => "com.lihaoyi" %%% "pprint" % "0.5.9"
})
)
.jsSettings(scalaJSModuleKind := ModuleKind.CommonJSModule)
// .nativeSettings(nativeSettings)
.jvmSettings(
libraryDependencies += "org.scalameta" %% "testkit" % "4.1.12" % Test
)
lazy val coreJVM = core.jvm
lazy val coreJS = core.js
// lazy val coreNative = core.native

lazy val typesafeConfig = "com.typesafe" % "config" % "1.2.1"
lazy val json = project
.in(file("metaconfig-json"))
.settings(
sharedSettings,
moduleName := "metaconfig-json",
libraryDependencies ++= List(
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 11 | 12)) => "com.lihaoyi" %%% "upickle" % "0.7.4"
case _ => "com.lihaoyi" %% "upickle" % "0.7.5"
})
)
)
.dependsOn(coreJVM)

lazy val typesafe = project
.in(file("metaconfig-typesafe-config"))
.settings(
testSettings,
sharedSettings,
moduleName := "metaconfig-typesafe-config",
description := "Integration for HOCON using typesafehub/config.",
libraryDependencies += typesafeConfig
libraryDependencies += "com.typesafe" % "config" % "1.2.1"
)
.dependsOn(coreJVM % "test->test;compile->compile")
.dependsOn(coreJVM)

lazy val sconfig = crossProject(JVMPlatform)
.in(file("metaconfig-sconfig"))
.settings(
testSettings,
sharedSettings,
moduleName := "metaconfig-sconfig",
description := "Integration for HOCON using ekrich/sconfig.",
libraryDependencies ++= List(
"org.ekrich" %%% "sconfig" % "1.0.0"
)
)
// .nativeSettings(nativeSettings)
.dependsOn(core % "test->test;compile->compile")
.dependsOn(core)
lazy val sconfigJVM = sconfig.jvm
// lazy val sconfigNative = sconfig.native

val scalatagsVersion = Def.setting {
if (scalaVersion.value.startsWith("2.11")) "0.6.7"
else "0.7.0"
}

lazy val tests = project
lazy val tests = crossProject(JVMPlatform, JSPlatform)
.in(file("metaconfig-tests"))
.settings(
sharedSettings,
skip in publish := true,
publishArtifact.in(Compile, packageDoc) := false,
testFrameworks := List(new TestFramework("munit.Framework")),
libraryDependencies ++= List(
"org.scalameta" %%% "munit-scalacheck" % V.munit,
"com.github.alexarchambault" %%% "scalacheck-shapeless_1.14" % "1.2.3"
)
)
.jsSettings(scalaJSModuleKind := ModuleKind.CommonJSModule)
.jvmSettings(
mainClass in GraalVMNativeImage := Some("metaconfig.tests.ExampleMain"),
sources.in(Compile, doc) := Seq.empty,
publishArtifact.in(Compile, packageDoc) := false,
graalVMNativeImageOptions ++= {
val reflectionFile =
Keys.sourceDirectory.in(Compile).value./("graal")./("reflection.json")
Expand All @@ -168,10 +160,17 @@ lazy val tests = project
)
}
)
.enablePlugins(GraalVMNativeImagePlugin)
.dependsOn(coreJVM)
.jvmConfigure(
_.enablePlugins(GraalVMNativeImagePlugin)
.dependsOn(json, typesafe, sconfigJVM)
)
.dependsOn(core)
lazy val testsJVM = tests.jvm
lazy val testsJS = tests.js

lazy val docs = project
.settings(
sharedSettings,
moduleName := "metaconfig-docs",
libraryDependencies ++= List(
"com.lihaoyi" %% "scalatags" % scalatagsVersion.value
Expand Down
36 changes: 0 additions & 36 deletions metaconfig-core/jvm/src/test/scala/metaconfig/CodecProps.scala

This file was deleted.

16 changes: 0 additions & 16 deletions metaconfig-core/jvm/src/test/scala/metaconfig/cli/Site.scala

This file was deleted.

8 changes: 2 additions & 6 deletions metaconfig-core/shared/src/main/scala/metaconfig/Conf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import metaconfig.internal.CliParser
import metaconfig.internal.ConfGet
import metaconfig.internal.ConfPatch
import metaconfig.internal.HoconPrinter
import org.typelevel.paiges.Doc
import metaconfig.generic.Surface

sealed abstract class Conf extends Product with Serializable {
def dynamic: ConfDynamic = ConfDynamic(Configured.Ok(this))
Expand Down Expand Up @@ -109,13 +107,11 @@ object Conf {
): Configured[Option[T]] =
ConfGet
.getKey(this, path +: extraNames)
.map(
value => ev.read(value).map(Some(_))
)
.map(value => ev.read(value).map(Some(_)))
.getOrElse(Configured.Ok(None))
}
object Obj {
val empty = Obj()
val empty: Obj = Obj()
def apply(values: (String, Conf)*): Obj = Obj(values.toList)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package metaconfig

import scala.language.higherKinds

trait ConfCodec[A] extends ConfDecoder[A] with ConfEncoder[A] { self =>
def bimap[B](in: B => A, out: A => B): ConfCodec[B] = new ConfCodec[B] {
override def write(value: B): Conf = self.write(in(value))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package metaconfig

import scala.language.experimental.macros
import scala.language.higherKinds
import scala.collection.compat._
import scala.reflect.ClassTag
Expand Down
11 changes: 7 additions & 4 deletions metaconfig-core/shared/src/main/scala/metaconfig/Input.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ sealed abstract class Input(val path: String, val text: String)
buf += (i + 1)
i += 1
}
if (buf.last != chars.length) buf += chars.length // sentinel value used for binary search
if (buf.last != chars.length)
buf += chars.length // sentinel value used for binary search
buf.toArray
}

Expand Down Expand Up @@ -66,19 +67,21 @@ sealed abstract class Input(val path: String, val text: String)
object Input {

case object None extends Input("<none>", "") {
override def toString = "Input.None"
override def toString: Predef.String = "Input.None"
}

final case class String(override val text: Predef.String)
extends Input("<input>", text) {
override def toString = s"""Input.String("$text")"""
override def toString: Predef.String =
s"""Input.String("$text")"""
}

final case class VirtualFile(
override val path: Predef.String,
override val text: Predef.String
) extends Input(path, text) {
override def toString = s"""Input.VirtualFile("$path", "...")"""
override def toString: Predef.String =
s"""Input.VirtualFile("$path", "...")"""
}

final case class File(file: Path, charset: Charset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ object Position {
def endLine: Int = input.offsetToLine(end)
def endColumn: Int = end - input.lineToOffset(endLine)
override def text = new String(input.chars, start, end - start)
override def toString = s"[$start..$end) in $input"
override def toString: String = s"[$start..$end) in $input"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package metaconfig.cli

import java.io.PrintStream
import java.io.InputStream
import metaconfig.generic
import metaconfig.ConfEncoder
import metaconfig.generic.Surface
import java.nio.file.Path
import fansi.Str
import fansi.Color
Expand Down Expand Up @@ -50,9 +47,7 @@ case class CliApp(
case Ok(value) =>
command.run(value, app)
case NotOk(error) =>
error.all.foreach { message =>
app.error(message)
}
error.all.foreach { message => app.error(message) }
1
}
case None =>
Expand Down
Loading

0 comments on commit aaab8fe

Please sign in to comment.