2014-05-01 18:50:07 +02:00
|
|
|
import sbt._
|
2019-11-28 19:05:49 +01:00
|
|
|
import sbt.Keys._
|
2011-06-26 18:27:07 +02:00
|
|
|
|
2014-05-01 18:50:07 +02:00
|
|
|
object Transform {
|
2019-11-28 19:05:49 +01:00
|
|
|
private val conscriptConfigs = taskKey[Unit]("")
|
2013-06-28 06:01:19 +02:00
|
|
|
|
2014-05-01 18:50:07 +02:00
|
|
|
def conscriptSettings(launch: Reference) = Seq(
|
2017-03-29 15:43:38 +02:00
|
|
|
conscriptConfigs := {
|
2019-11-28 19:05:49 +01:00
|
|
|
val sourceFile = (launch / Compile / managedResources).value
|
|
|
|
|
.find(_.getName == "sbt.boot.properties")
|
|
|
|
|
.getOrElse(sys.error("No managed boot.properties file."))
|
|
|
|
|
val source = IO.readLines(sourceFile)
|
|
|
|
|
val conscriptBase = (Compile / sourceDirectory).value / "conscript"
|
|
|
|
|
IO.delete(conscriptBase)
|
|
|
|
|
val pairs = Seq(
|
|
|
|
|
"sbt.xMain" -> "xsbt",
|
|
|
|
|
"sbt.ScriptMain" -> "scalas",
|
|
|
|
|
"sbt.ConsoleMain" -> "screpl",
|
|
|
|
|
)
|
|
|
|
|
for ((main, dir) <- pairs) {
|
|
|
|
|
val lines = source.map(l => if (l.trim.startsWith("class:")) s" class: $main" else l)
|
|
|
|
|
IO.writeLines(conscriptBase / dir / "launchconfig", lines)
|
|
|
|
|
}
|
2014-05-01 18:50:07 +02:00
|
|
|
},
|
|
|
|
|
)
|
2011-06-26 18:27:07 +02:00
|
|
|
|
2019-11-28 19:05:49 +01:00
|
|
|
def configSettings = Seq(
|
|
|
|
|
resourceGenerators += Def.task {
|
|
|
|
|
val rdirs = Seq(sourceDirectory.value / "input_resources")
|
|
|
|
|
val rm = resourceManaged.value
|
|
|
|
|
val paths = (rdirs ** (-DirectoryFilter)).get --- rdirs
|
|
|
|
|
val rs = paths.pair(Path.rebase(rdirs, rm) | Path.flat(rm))
|
|
|
|
|
val props = Map(
|
|
|
|
|
"org" -> organization.value,
|
|
|
|
|
"sbt.version" -> version.value,
|
|
|
|
|
"scala.version" -> scalaVersion.value,
|
|
|
|
|
)
|
|
|
|
|
def get(key: String) = props.getOrElse(key, sys.error(s"No value defined for key '$key'"))
|
|
|
|
|
val Property = """\$\{\{([\w.-]+)\}\}""".r
|
|
|
|
|
val catcher = scala.util.control.Exception.catching(classOf[java.io.IOException])
|
|
|
|
|
rs.map { case (in, out) =>
|
|
|
|
|
val newString = Property.replaceAllIn(IO.read(in), mtch => get(mtch.group(1)))
|
|
|
|
|
if (Some(newString) != catcher.opt(IO.read(out)))
|
|
|
|
|
IO.write(out, newString)
|
|
|
|
|
out
|
|
|
|
|
}
|
|
|
|
|
}.taskValue,
|
|
|
|
|
)
|
2011-11-10 11:11:16 +01:00
|
|
|
}
|