build.sc
author Tomas Zeman <tzeman@volny.cz>
Thu, 17 Jan 2019 14:51:59 +0100
changeset 20 529418651908
child 21 175e7d7ce5b3
permissions -rw-r--r--
Build refactoring: sbt -> mill

import ammonite.ops._
import mill._
import mill.define.{Input, Sources, Target}
import mill.scalajslib._
import mill.scalalib._
import mill.scalalib.publish._
import mill.util.Loose

object V {
  val fatags = "0.4-SNAPSHOT"
  val scalaJs = "0.6.26"
  val scala211 = "2.11.12"
  val scala212 = "2.12.8"
}

object D {
  val scalatags = ivy"com.lihaoyi::scalatags::0.6.7"
}

trait Common extends CrossSbtModule with PublishModule {

  def publishVersion: Target[String] = V.fatags

  def pomSettings = PomSettings(
    description = "FontAwesome Scala DSL (tags)",
    organization = "net.tz",
    url = "https://bitbucket.org/tzeman/fatags",
    licenses = Seq(License.`Apache-2.0`),
    versionControl = VersionControl(developerConnection = Some(
      "ssh://hg@bitbucket.org/tzeman/fatags")),
    developers = Seq(
      Developer("tzeman", "Tomas Zeman", "")
    )
  )

  override def scalacOptions = T{Seq(
    "-deprecation",                      // Emit warning and location for usages of deprecated APIs.
    "-encoding", "utf-8",                // Specify character encoding used by source files.
    "-explaintypes",                     // Explain type errors in more detail.
    "-feature",                          // Emit warning and location for usages of features that should be imported explicitly.
    "-language:higherKinds",             // Allow higher-kinded types
    "-language:implicitConversions",     // Allow definition of implicit functions called views
    "-language:reflectiveCalls",
    "-language:postfixOps",
    "-unchecked",                        // Enable additional warnings where generated code depends on assumptions.
    "-Xcheckinit",                       // Wrap field accessors to throw an exception on uninitialized access.
    "-Xfuture",                          // Turn on future language features.
    "-target:jvm-1.8",
  )}

  def hgId: Input[String] = T.input {
    os.proc("hg", "id", "-i").call().out.string.trim
  }

  def hgNum: Input[String] = T.input {
    os.proc("hg", "id", "-n").call().out.string.trim
  }

  def hgTag: Input[Option[String]] = T.input {
    os.proc("hg", "id", "-t").call().out.string.trim.split(' ').headOption
  }

  override def ivyDeps: Target[Loose.Agg[Dep]] = Agg(D.scalatags)

  override def sources: Sources = T.sources{
    super.sources() :+ PathRef(millSourcePath / 'shared / 'src / 'main / 'scala)
  }

}

class JvmModule(val crossScalaVersion: String) extends Common
class JsModule(val crossScalaVersion: String) extends ScalaJSModule
  with Common {
  override def scalaJSVersion: Target[String] = V.scalaJs
}

object jvm extends Cross[JvmModule](V.scala211, V.scala212)
object js extends Cross[JsModule](V.scala211, V.scala212)

def publishLocal(): define.Command[Unit] = T.command{
  jvm(V.scala212).publishLocal()()
  js(V.scala212).publishLocal()()
  jvm(V.scala211).publishLocal()()
  js(V.scala211).publishLocal()()
}

object example extends ScalaModule with ScalaJSModule {
  override def moduleDeps: Seq[PublishModule] = Seq(js(V.scala212))
  override def scalaVersion: Target[String] = T{V.scala212}
  override def scalaJSVersion: Target[String] = V.scalaJs
}

// vim: et ts=2 sw=2 syn=scala