build.sc
author Tomas Zeman <tomas@functionals.cz>
Thu, 24 Oct 2019 13:10:50 +0200
changeset 7 d101f632cc8d
parent 6 7146cc2c4b81
child 8 7d705a7b1867
permissions -rw-r--r--
Using PublishM2Module, depending on spss-reader-1.3-SNAPSHOT

// mill 0.5.1

import ammonite.ops._
import coursier.Repository
import coursier.maven.MavenRepository
import mill._
import mill.define.{Input, Sources, Target}
import mill.scalajslib._
import mill.scalalib._
import mill.scalalib.publish._
import $ivy.`de.tototec::de.tobiasroeser.mill.publishM2:0.1.0`
import de.tobiasroeser.mill.publishM2._

import scala.language.postfixOps

object V {
  val spss4s = "0.1-SNAPSHOT"
  val scalaJs = "0.6.26"
  val scala211 = "2.11.12"
  val scala212 = "2.12.8"
}

object D {
  val spssReader = ivy"com.bedatadriven.spss:spss-reader:1.3-SNAPSHOT"
}

trait Common extends CrossScalaModule with PublishM2Module {

  override def artifactName: T[String] = "spss4s"

  override def repositories: Seq[Repository] = super.repositories ++ Seq(
    MavenRepository("https://maven.functionals.cz/m2/")
  )

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

  def pomSettings = PomSettings(
    description = "SPSS reader for Scala",
    organization = "net.tz",
    url = "https://hg.functionals.cz/spss4s",
    licenses = Seq(License.`Apache-2.0`),
    versionControl = VersionControl(developerConnection = Some(
      "https://hg.functionals.cz/spss4s")),
    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 sources: Sources = T.sources(
    millSourcePath / 'src, millSourcePath / 'shared
  )

}

class JvmModule(val crossScalaVersion: String) extends Common {

  override def ivyDeps = Agg(D.spssReader)

}

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()()
}

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

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