build.sc
author Tomas Zeman <tomas@functionals.cz>
Wed, 27 May 2020 17:22:31 +0200
changeset 23 2015beb50730
parent 22 445c6ed80d1c
child 24 f93465523457
permissions -rw-r--r--
Added tag purecss-0.2 for changeset 445c6ed80d1c

import mill._
import mill.api.Loose
import mill.define.{Command, Input, Sources, Target}
import mill.scalajslib._
import mill.scalalib._
import mill.scalalib.publish._

object V {
  val app = "0.2"
  val scalaJs = "0.6.28"
  val scala211 = "2.11.12"
  val scala212 = "2.12.9"
}

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

trait Common extends CrossSbtModule with PublishModule {

  def pomSettings = PomSettings(
    description = "Scalatags DSL for purecss.io framework",
    organization = "cz.functionals",
    url = "https://hg.functionals.cz/purecss",
    licenses = Seq(License.`Apache-2.0`),
    versionControl = VersionControl(developerConnection = Some(
      "https://hg.functionals.cz/purecss")),
    developers = Seq(
      Developer("tzeman", "Tomas Zeman", "https://functionals.cz")
    )
  )

  override def artifactName = "purecss" 

  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.text.trim
  }

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

  private val maskedTags = Set("tip", "qtip", "qbase")
  def hgTag: Input[Option[String]] = T.input {
    os.proc("hg", "id", "-t").call().out.text.trim.split(' ').filterNot(v =>
      maskedTags contains v).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)
  }

  override def publishVersion: Input[String] = T.input{
    val tv = hgTag() map(v => "-" + v.replace(".patch", "")) getOrElse ""
    V.app.replace("SNAPSHOT", s"${hgNum()}-${hgId()}$tv")
  }
}

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(): Command[Unit] = T.command{
  jvm(V.scala212).publishLocal()()
  js(V.scala212).publishLocal()()
  jvm(V.scala211).publishLocal()()
  js(V.scala211).publishLocal()()
  ()
}

def publishM2Local(p: os.Path): Command[Unit] = T.command{
  jvm(V.scala212).publishM2Local(p.toString)()
  js(V.scala212).publishM2Local(p.toString)()
  jvm(V.scala211).publishM2Local(p.toString)()
  js(V.scala211).publishM2Local(p.toString)()
  ()
}

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