Skip to content

Commit

Permalink
Add aggregate projects for each ScalaJS project to keep things simple (
Browse files Browse the repository at this point in the history
…#95)

This allows us to delete the hacky script for performing cross-build-like
tasks and gets us back in the fold with SBT.
  • Loading branch information
lloydmeta authored Jan 1, 2017
1 parent 3bd6220 commit c9d2c39
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 54 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Integrations are available for:
8. [Argonaut integration](#argonaut)
9. [Slick integration](#slick-integration)
10. [Benchmarking](#benchmarking)
11. [Publishing](#publishing)


## Quick start
Expand Down Expand Up @@ -831,3 +832,13 @@ is acceptable for almost all use-cases. PRs that promise to increase performance
Also, Enumeratum's `withName` is faster than the standard library's `Enumeration`, by around 4x in the case where an entry exists with the given name.
My guess is this is because Enumeratum doesn't use any `synchronized` calls or `volatile` annotations. It is also faster in the case where there is no
corresponding name, but not by a significant amount, perhaps because the high cost of throwing an exception masks any benefits.

## Publishing

Projects are published independently of each other.

JVM + ScalaJS projects should have an aggregate project to make it easy to publish them, e.g. for `enumeratum-circe`:

`$ sbt "project circe-aggregate" +clean +publish-signed`

Should publish all needed artefacts. Note that `sbt circe-aggregate/publish-signed` will not work (ScalaJS gets skipped).
Empty file added aggregates/circe/.gitkeep
Empty file.
Empty file added aggregates/core/.gitkeep
Empty file.
Empty file added aggregates/macros/.gitkeep
Empty file.
5 changes: 5 additions & 0 deletions aggregates/note
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This and the directories under it are all for the sole purpose of
giving SBT homes for the aggregate projects.

This is required so that ScalaJS and JVM libs can be published side
by side with the proper platform suffices in their artefact names.
Empty file added aggregates/upickle/.gitkeep
Empty file.
64 changes: 44 additions & 20 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def thePlayVersion(scalaVersion: String) =
}

lazy val baseProjectRefs =
Seq(macrosJs, macrosJvm, coreJs, coreJvm, coreJVMTests).map(Project.projectToRef)
Seq(macrosJS, macrosJVM, coreJS, coreJVM, coreJVMTests).map(Project.projectToRef)

lazy val integrationProjectRefs = Seq(
enumeratumPlay,
Expand Down Expand Up @@ -64,7 +64,7 @@ lazy val scala_2_12 = Project(id = "scala_2_12",
// Do not publish this project (it just serves as an aggregate)
publishArtifact := false,
publishLocal := {},
doctestWithDependencies := false,
doctestWithDependencies := false, // sbt-doctest is not yet compatible with this 2.12
aggregate in publish := false,
aggregate in PgpKeys.publishSigned := false
)
Expand All @@ -79,21 +79,21 @@ lazy val scala_2_12 = Project(id = "scala_2_12",
enumeratumReactiveMongoBson
).map(Project.projectToRef): _*) // base plus known 2.12 friendly libs

// Aggregates core and macro
lazy val coreAggregate = aggregateProject("core", coreJS, coreJVM)
lazy val core = crossProject
.crossType(CrossType.Pure)
.in(file("enumeratum-core"))
.settings(testSettings: _*)
.settings(commonWithPublishSettings: _*)
.settings(
name := "enumeratum",
version := Versions.Core.head,
crossScalaVersions := scalaVersionsAll,
crossVersion := CrossVersion.binary,
version := Versions.Core.head
libraryDependencies += "com.beachape" %% "enumeratum-macros" % Versions.Macros.stable
)
.settings(testSettings: _*)
.settings(commonWithPublishSettings: _*)
.dependsOn(macros)
lazy val coreJs = core.js
lazy val coreJvm = core.jvm
lazy val coreJS = core.js
lazy val coreJVM = core.jvm

// Project models used in test for some subprojects
lazy val enumeratumTest = crossProject
Expand Down Expand Up @@ -133,8 +133,9 @@ lazy val coreJVMTests = Project(id = "coreJVMTests",
),
publishArtifact := false
)
.dependsOn(coreJvm)
.dependsOn(coreJVM)

lazy val macrosAggregate = aggregateProject("macros", macrosJS, macrosJVM)
lazy val macros = crossProject
.crossType(CrossType.Pure)
.in(file("macros"))
Expand All @@ -145,16 +146,14 @@ lazy val macros = crossProject
includeTestSrcs = false): _*)
.settings(
name := "enumeratum-macros",
version := Versions.Core.head,
crossScalaVersions := scalaVersionsAll,
crossVersion := CrossVersion.binary,
version := Versions.Macros.head,
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value
)
)
.settings(testSettings: _*)
lazy val macrosJs = macros.js
lazy val macrosJvm = macros.jvm
lazy val macrosJS = macros.js
lazy val macrosJVM = macros.jvm

lazy val enumeratumReactiveMongoBson =
Project(id = "enumeratum-reactivemongo-bson",
Expand Down Expand Up @@ -200,6 +199,7 @@ lazy val enumeratumPlay = Project(id = "enumeratum-play",
)
.dependsOn(enumeratumPlayJson % "test->test;compile->compile")

lazy val uPickleAggregate = aggregateProject("upickle", enumeratumUPickleJs, enumeratumUPickleJvm)
lazy val enumeratumUPickle = crossProject
.crossType(CrossType.Pure)
.in(file("enumeratum-upickle"))
Expand All @@ -208,8 +208,6 @@ lazy val enumeratumUPickle = crossProject
.settings(
name := "enumeratum-upickle",
version := "1.5.5-SNAPSHOT",
crossScalaVersions := scalaVersionsAll,
crossVersion := CrossVersion.binary,
libraryDependencies ++= {
import org.scalajs.sbtplugin._
val cross = {
Expand Down Expand Up @@ -238,6 +236,7 @@ lazy val enumeratumUPickle = crossProject
lazy val enumeratumUPickleJs = enumeratumUPickle.js
lazy val enumeratumUPickleJvm = enumeratumUPickle.jvm

lazy val circeAggregate = aggregateProject("circe", enumeratumCirceJs, enumeratumCirceJvm)
lazy val enumeratumCirce = crossProject
.crossType(CrossType.Pure)
.in(file("enumeratum-circe"))
Expand All @@ -246,8 +245,6 @@ lazy val enumeratumCirce = crossProject
.settings(
name := "enumeratum-circe",
version := "1.5.5-SNAPSHOT",
crossScalaVersions := scalaVersionsAll,
crossVersion := CrossVersion.binary,
libraryDependencies ++= {
import org.scalajs.sbtplugin._
val cross = {
Expand All @@ -258,7 +255,8 @@ lazy val enumeratumCirce = crossProject
}
Seq(
impl.ScalaJSGroupID.withCross("io.circe", "circe-core", cross) % circeVersion,
impl.ScalaJSGroupID.withCross("com.beachape", "enumeratum", cross) % Versions.Core.stable)
impl.ScalaJSGroupID.withCross("com.beachape", "enumeratum", cross) % Versions.Core.stable
)
}
)
lazy val enumeratumCirceJs = enumeratumCirce.js
Expand Down Expand Up @@ -440,6 +438,7 @@ def withCompatUnmanagedSources(jsJvmCrossProject: Boolean,
case _ => Nil
}
}

val unmanagedMainDirsSetting = Seq(
unmanagedSourceDirectories in Compile ++= {
compatDirs(projectbase = baseDirectory.value,
Expand All @@ -460,4 +459,29 @@ def withCompatUnmanagedSources(jsJvmCrossProject: Boolean,
}
}

/**
* Assumes that
*
* - a corresponding directory exists under ./aggregates.
* - publishing 2.10.x, 2.11.x, 2.12.x
*/
def aggregateProject(id: String, projects: ProjectReference*): Project =
Project(id = s"$id-aggregate",
base = file(s"./aggregates/$id"),
settings = commonWithPublishSettings)
.settings(
crossScalaVersions := scalaVersionsAll,
crossVersion := CrossVersion.binary,
// Do not publish the aggregate project (it just serves as an aggregate)
publishArtifact := false,
doctestWithDependencies := {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 12)) => false
case _ => true
}
},
publishLocal := {}
)
.aggregate(projects: _*)

scalafmtConfig := Some(file(".scalafmt.conf"))
32 changes: 0 additions & 32 deletions cross-task

This file was deleted.

9 changes: 7 additions & 2 deletions project/Versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ object Versions {

object Core {
val stable = "1.5.4"
val head = "1.5.5-SNAPSHOT"
val head = "1.5.5-SNAPSHOT"
}

}
object Macros {
val stable = "1.5.4"
val head = "1.5.5-SNAPSHOT"
}

}

0 comments on commit c9d2c39

Please sign in to comment.