Skip to content

Commit

Permalink
[WIP] Port to Scala.js (#898)
Browse files Browse the repository at this point in the history
* Move core tests to tests module

* Remove unused sbt-pack

* Move cli/test to tests/test

* Tiny cleanup in build.sbt

* Move src to shared/src

* Abstract over config backend.

- Use metaconfig-hocon on JS
- Use metaconfig-typesafe-config on JVM

The first unit test passes on JS!

* Format :v

* Fix ci-slow command

* Add a few more JS unit tests.

Let's wait for scalameta/scalameta#812 to get
fixed so we can run the full test suite in Scala.js

* Skip CI_PUBLISH for ci-sbt-scalafmt

* Move all the files!

This commit reorganizes the top-level directories to follow a consistent
naming convention: scalafmt-MODULE. I'm doing this in this PR because
the files have already moved into `shared/` directories so URLs to
previous files will get lost anyways. I like the consistent naming
scheme because it feels easier to get an overview of the project.

* Move scalafmt-readme back to readme/

* Update .scalafmt.conf

* Fix ci-sbt-scalafmt command
  • Loading branch information
olafurpg authored Apr 23, 2017
1 parent c64dc59 commit d5c3b0a
Show file tree
Hide file tree
Showing 296 changed files with 171 additions and 79 deletions.
1 change: 0 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ matrix:
CI_PUBLISH: true
- CI_TEST: ci-sbt-scalafmt
CI_SCALA_VERSION: 2.12.2
CI_PUBLISH: true
- CI_TEST: ci-slow
CI_SCALA_VERSION: 2.11.11
- CI_TEST: ci-slow
Expand Down
2 changes: 1 addition & 1 deletion .drone.yml.sig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
eyJhbGciOiJIUzI1NiJ9.cGlwZWxpbmU6CiAgIyBGZXRjaCBmb2xkZXJzIGZyb20gZGlzdHJpYnV0ZWQgY2FjaGUKICBzZnRwX2NhY2hlX3Jlc3RvcmU6CiAgICBpbWFnZTogcGx1Z2lucy9zZnRwLWNhY2hlCiAgICByZXN0b3JlOiB0cnVlCiAgICBtb3VudDoKICAgICAgLSAvZHJvbmUvLml2eTIvY2FjaGUKICAgICAgLSAvZHJvbmUvLmNvdXJzaWVyLWNhY2hlCiAgIC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iBbY2hhbmdlZCwgZmFpbHVyZV0KCiAgIyBTYXZlIGZvbGRlcnMgaW4gZGlzdHJpYnV0ZWQgY2FjaGUKICBzZnRwX2NhY2hlX3JlYnVpbGQ6CiAgICBpbWFnZTogcGx1Z2lucy9zZnRwLWNhY2hlCiAgICByZWJ1aWxkOiB0cnVlCiAgICBtb3VudDoKICAgICAgLSAvZHJvbmUvLml2eTIvY2FjaGUKICAgICAgLSAvZHJvbmUvLmNvdXJzaWVyLWNhY2hlCiAgICAgIC0gL2Ryb25lLy5zYnQKICAgICAgLSAvZHJvbmUvLmdpdAoKbWF0cml4OgogIGluY2x1ZGU6CiAgICAtIENJX1RFU1Q6IGNpLWZhc3QKICAgICAgQ0lfU0NBTEFfVkVSU0lPTjogMi4xMS4xMQogICAgICBDSV9QVUJMSVNIOiB0cnVlCiAgICAtIENJX1RFU1Q6IGNpLWZhc3QKICAgICAgQ0lfU0NBTEFfVkVSU0lPTjogMi4xMi4yCiAgICAgIENJX1BVQkxJU0g6IHRydWUKICAgIC0gQ0lfVEVTVDogY2ktc2J0LXNjYWxhZm10CiAgICAgIENJX1NDQUxBX1ZFUlNJT046IDIuMTIuMgogICAgLSBDSV9URVNUOiBjaS1zbG93CiAgICAgIENJX1NDQUxBX1ZFUlNJT046IDIuMTEuMTEKICAgIC0gQ0lfVEVTVDogY2ktc2xvdwogICAgICBDSV9TQ0FMQV9WRVJTSU9OOiAyLjEyLjIKCg.PHp9BifCwMfM-7icmXekHjCFQ2ruZY4qBrn_GziMZIY
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ project/plugins/project/
.scala_dependencies
.worksheet
.idea
.idea.bak/
intellij/out


*~
3 changes: 1 addition & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
project.git = true
project.excludeFilters = [
benchmarks/src/resources,
scalafmt-benchmarks/src/resources,
sbt-test
bin/issue
metaconfig/src/main/scala
]
# These are disabled by default because vertical
# alignment still has some false positives/negatives.
Expand Down
134 changes: 74 additions & 60 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Dependencies._

addCommandAlias("downloadIdea", "intellij/updateIdea")
import org.scalajs.sbtplugin.cross.CrossProject

lazy val buildSettings = Seq(
organization := "com.geirsson",
Expand All @@ -9,78 +8,66 @@ lazy val buildSettings = Seq(
crossScalaVersions := Seq(scala211, scala212),
scalaCompilerBridgeSource :=
("org.scala-sbt" % "compiler-interface" % "0.13.15" % "component").sources,
updateOptions := updateOptions.value.withCachedResolution(true)
updateOptions := updateOptions.value.withCachedResolution(true),
resolvers += Resolver.sonatypeRepo("releases"),
libraryDependencies += scalatest.value % Test,
triggeredMessage in ThisBuild := Watched.clearWhenTriggered,
scalacOptions in (Compile, console) := compilerOptions :+ "-Yrepl-class-based",
assemblyJarName in assembly := "scalafmt.jar",
testOptions in Test += Tests.Argument("-oD")
)
lazy val allSettings = buildSettings ++ publishSettings

name := "scalafmtRoot"
allSettings
noPublish
commands += CiCommand("ci-fast")(
"test" ::
Nil
)
commands += CiCommand("ci-slow")(
"core/test:runMain org.scalafmt.ScalafmtProps" ::
Nil
)
commands += CiCommand("ci-sbt-scalafmt")(
"scalafmtSbt/it:test" ::
Nil
)
commands += CiCommand("ci-publish")(
if (sys.env.contains("CI_PUBLISH")) s"publish" :: Nil
else Nil
)
commands ++= ciCommands
addCommandAlias("downloadIdea", "intellij/updateIdea")

lazy val core = project
lazy val core = crossProject
.in(file("scalafmt-core"))
.settings(
moduleName := "scalafmt-core",
allSettings,
metaMacroSettings,
buildInfoSettings,
fork.in(run).in(Test) := true,
moduleName := "scalafmt-core",
libraryDependencies ++= Seq(
metaconfig,
scalameta,
"com.typesafe" % "config" % "1.2.1",
// Test dependencies
"com.googlecode.java-diff-utils" % "diffutils" % "1.3.0" % Test,
"com.lihaoyi" %% "scalatags" % "0.6.3" % Test,
scalametaTestkit % Test,
scalatest % Test
metaconfig.value,
scalameta.value
),
addCompilerPlugin(paradise)
)
.jsSettings(
libraryDependencies += metaconfigHocon.value
)
.jvmSettings(
libraryDependencies += metaconfigTypesafe.value
)
.enablePlugins(BuildInfoPlugin)

lazy val cliJvmOptions = Seq(
"-Xss4m"
)
lazy val coreJVM = core.jvm
lazy val coreJS = core.js

lazy val cli = project
.in(file("scalafmt-cli"))
.settings(
moduleName := "scalafmt-cli",
allSettings,
metaMacroSettings,
packSettings,
packMain := Map("scalafmt_pack" -> "org.scalafmt.cli.Cli"),
packJvmOpts := Map(
"scalafmt_pack" -> cliJvmOptions
),
moduleName := "scalafmt-cli",
mainClass in assembly := Some("org.scalafmt.cli.Cli"),
libraryDependencies ++= Seq(
"com.martiansoftware" % "nailgun-server" % "0.9.1",
"com.github.scopt" %% "scopt" % "3.5.0"
)
)
.dependsOn(core % "compile->compile;test->test")
.dependsOn(coreJVM)

def isOnly(scalaV: String) = Seq(
scalaVersion := scalaV,
crossScalaVersions := Seq(scalaV)
)

lazy val scalafmtSbt = project
lazy val `scalafmt-sbt` = project
.configs(IntegrationTest)
.settings(
allSettings,
Expand All @@ -91,18 +78,16 @@ lazy val scalafmtSbt = project
sbtVersion in Global := "1.0.0-M5",
test.in(IntegrationTest) := RunSbtCommand(
Seq(
s"wow $scala212",
"publishLocal",
s"plz $scala212 publishLocal",
"""set sbtVersion in Global := "0.13.15" """,
"such scalafmtSbtTest/scripted",
"""set sbtVersion in Global := "1.0.0-M5" """,
s"wow $scala211"
"such scalafmt-sbt-tests/scripted",
"""set sbtVersion in Global := "1.0.0-M5" """
).mkString("; ", "; ", "")
)(state.value)
)
.dependsOn(cli)

lazy val scalafmtSbtTest = project
lazy val `scalafmt-sbt-tests` = project
.settings(
allSettings,
noPublish,
Expand All @@ -125,7 +110,9 @@ lazy val scalafmtSbtTest = project
},
scriptedBufferLog := false
)

lazy val intellij = project
.in(file("scalafmt-intellij"))
.settings(
allSettings,
buildInfoSettings,
Expand All @@ -138,18 +125,35 @@ lazy val intellij = project
libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "1.0.6",
cleanFiles += ideaDownloadDirectory.value
)
.dependsOn(core, cli)
.dependsOn(coreJVM, cli)
.enablePlugins(SbtIdeaPlugin)

lazy val tests = project
.in(file("scalafmt-tests"))
.settings(
allSettings,
noPublish,
libraryDependencies ++= Seq(
// Test dependencies
"com.googlecode.java-diff-utils" % "diffutils" % "1.3.0",
"com.lihaoyi" %% "scalatags" % "0.6.3",
scalametaTestkit
)
)
.dependsOn(
cli
)

lazy val benchmarks = project
.in(file("scalafmt-benchmarks"))
.settings(
allSettings,
noPublish,
isOnly(scala212),
moduleName := "scalafmt-benchmarks",
libraryDependencies ++= Seq(
scalametaTestkit,
scalatest % Test
scalatest.value % Test
),
javaOptions in run ++= Seq(
"-Djava.net.preferIPv4Stack=true",
Expand All @@ -170,7 +174,7 @@ lazy val benchmarks = project
"-server"
)
)
.dependsOn(core)
.dependsOn(coreJVM)
.enablePlugins(JmhPlugin)

lazy val readme = scalatex
Expand All @@ -189,7 +193,7 @@ lazy val readme = scalatex
)
)
.dependsOn(
core,
coreJVM,
cli
)

Expand All @@ -214,7 +218,7 @@ lazy val noDocs = Seq(
)

lazy val metaMacroSettings: Seq[Def.Setting[_]] = Seq(
libraryDependencies += scalameta,
libraryDependencies += scalameta.value,
addCompilerPlugin(paradise),
scalacOptions += "-Xplugin-require:macroparadise"
) ++ noDocs
Expand All @@ -235,13 +239,6 @@ lazy val compilerOptions = Seq(
"-Xlint"
)

lazy val commonSettings = Seq(
triggeredMessage in ThisBuild := Watched.clearWhenTriggered,
scalacOptions in (Compile, console) := compilerOptions :+ "-Yrepl-class-based",
assemblyJarName in assembly := "scalafmt.jar",
testOptions in Test += Tests.Argument("-oD")
)

lazy val publishSettings = Seq(
publishMavenStyle := true,
publishArtifact := true,
Expand Down Expand Up @@ -309,4 +306,21 @@ def extraSbtBootOptions: Seq[String] = {
sys.props.get(bootProps).map(x => s"-D$bootProps=$x").toList
}

lazy val allSettings = commonSettings ++ buildSettings ++ publishSettings
def ciCommands = Seq(
CiCommand("ci-fast")(
"test" ::
Nil
),
CiCommand("ci-slow")(
"tests/test:runMain org.scalafmt.ScalafmtProps" ::
Nil
),
Command.command("ci-sbt-scalafmt") { s =>
"scalafmt-sbt/it:test" ::
s
},
CiCommand("ci-publish")(
if (sys.env.contains("CI_PUBLISH")) s"publish" :: Nil
else Nil
)
)
18 changes: 11 additions & 7 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import sbt._
import sbt.Keys._
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
// scalafmt: { maxColumn = 120, style = defaultWithAlign }

object Dependencies {
val metaconfigV = "0.3.0"
val metaconfigV = "0.3.2"
val scalametaV = "1.7.0"
val paradiseV = "3.0.0-M8"
val scalatestV = "3.0.1"
val coursier = "1.0.0-M15-5"

val paradise = "org.scalameta" % "paradise" % paradiseV cross CrossVersion.full
val scalameta = "org.scalameta" %% "scalameta" % scalametaV
val scalametaTestkit = "org.scalameta" %% "testkit" % scalametaV
val scalatest = "org.scalatest" %% "scalatest" % scalatestV
val metaconfig = "com.geirsson" %% "metaconfig-typesafe-config" % metaconfigV
val scalariform = "org.scalariform" %% "scalariform" % "0.1.8"
val paradise = "org.scalameta" % "paradise" % paradiseV cross CrossVersion.full
val scalametaTestkit = "org.scalameta" %% "testkit" % scalametaV
val scalariform = "org.scalariform" %% "scalariform" % "0.1.8"

val scalatest = Def.setting("org.scalatest" %%% "scalatest" % scalatestV)
val scalameta = Def.setting("org.scalameta" %%% "scalameta" % scalametaV)
val metaconfig = Def.setting("com.geirsson" %%% "metaconfig-core" % metaconfigV)
val metaconfigTypesafe = Def.setting("com.geirsson" %%% "metaconfig-typesafe-config" % metaconfigV)
val metaconfigHocon = Def.setting("com.geirsson" %%% "metaconfig-hocon" % metaconfigV)
}
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-M15-5")
addSbtPlugin("com.eed3si9n" % "sbt-doge" % "0.1.5")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.3")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.2.15")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.15")
addSbtPlugin("com.lihaoyi" % "scalatex-sbt-plugin" % "0.3.7")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
addSbtPlugin("org.xerial.sbt" % "sbt-pack" % "0.8.0")
addSbtPlugin("com.dancingrobot84" % "sbt-idea-plugin" % "0.4.2")
libraryDependencies += "org.scala-sbt" % "scripted-plugin" % sbtVersion.value
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ abstract class MicroBenchmark(path: String*) extends FormatBenchmark {
// jmh runs from benchmarks directory while tests run from from root.
// Can't bother to find more generic solution
if (filename.isFile) filename
else FileOps.getFile(Seq("benchmarks", "src", "resources") ++ path: _*)
else
FileOps.getFile(
Seq("scalafmt-benchmarks", "src", "resources") ++ path: _*)
}

def scalametaParser(): Unit = {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.scalafmt.config

object PlatformConfig {
implicit val parser = metaconfig.hocon.hoconMetaconfigParser
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.scalafmt.config

object PlatformConfig {
implicit val parser =
metaconfig.typesafeconfig.typesafeConfigMetaconfigParser
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package org.scalafmt.config

import scala.language.reflectiveCalls

import metaconfig._
import scala.meta.inputs.Input
import scala.meta.internal.parsers.ScalametaParser

import java.io.File
Expand All @@ -12,8 +14,7 @@ import metaconfig.Configured
import metaconfig.Configured.Ok
import metaconfig.HasFields
import metaconfig.String2AnyMap
import metaconfig.typesafeconfig.TypesafeConfig2Class
import org.scalameta.logger
import org.scalafmt.config.PlatformConfig._

object Config {

Expand All @@ -40,16 +41,23 @@ object Config {
Seq(s" = $output")
}

/** Read ScalafmtConfig from String contents from an optional HOCON path. */
def fromInput(input: Input, path: Option[String]): Configured[Conf] = {
val configured = implicitly[MetaconfigParser].fromInput(input)
path match {
case Some(x) => ConfDynamic(configured).selectDynamic(x).asConf
case None => configured
}
}

def fromHoconString(
string: String,
path: Option[String] = None): Configured[ScalafmtConfig] =
fromConf(TypesafeConfig2Class.gimmeConfFromString(string), path)
fromConf(fromInput(Input.String(string), path))

/** Read ScalafmtConfig from String contents from an optional HOCON path. */
def fromHoconFile(file: File,
path: Option[String] = None): Configured[ScalafmtConfig] =
fromConf(TypesafeConfig2Class.gimmeConfFromFile(file), path)
fromConf(fromInput(Input.File(file), path))

def fromConf(conf: Configured[Conf],
path: Option[String] = None): Configured[ScalafmtConfig] =
Expand Down
Loading

0 comments on commit d5c3b0a

Please sign in to comment.