-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.sbt
67 lines (61 loc) · 2.67 KB
/
build.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import Path.FileMap
import java.nio.file.{ Files, Paths }
import java.nio.file.attribute.PosixFilePermissions
lazy val commonSettings = Seq(
organization := "org.sellmerfud",
version := "2.16",
scalaVersion := "2.13.14"
)
lazy val stage = taskKey[Unit]("Create distribution zip file")
lazy val sourceOther = settingKey[File]("Other source file included in the package")
lazy val coltwi = (project in file("."))
.settings(
commonSettings,
name := "coltwi",
description := "A scala implementation of the solo AI for Colonial Twilight",
scalacOptions ++= Seq( "-deprecation", "-unchecked", "-feature" ),
libraryDependencies ++= Seq(
"org.scala-lang.modules" %% "scala-parser-combinators" % "2.1.1"
),
sourceOther := sourceDirectory.value / "other",
Compile / resourceGenerators += Def.task {
val versFile = (Compile / resourceManaged).value / "version"
IO.write(versFile, version.value)
Seq(versFile)
}.taskValue,
// Task to create the distribution zip file
Compile / stage := {
val log = streams.value.log
(loader / Compile / packageBin).value // Depends on the loader package being built
(Compile / packageBin).value // Depends on the package being built
def rebaseTo(directory: File)(origfile: File): Option[File] = {
val mapper: FileMap = Path.flat(directory)
mapper(origfile)
}
val pkgDir = target.value / s"coltwi-${version.value}"
val lib = pkgDir / "lib"
val loader_jar = (loader / Compile / packageBin / artifactPath).value
val zipfile = file(s"${pkgDir.getAbsolutePath}.zip")
val jars = (Compile / fullClasspathAsJars).value.files
val others = (sourceOther.value * "*").get
val assets = (others pair rebaseTo(pkgDir)) ++ (jars pair rebaseTo(lib))
log.info(s"Staging to $pkgDir ...")
IO.delete(pkgDir)
IO.createDirectory(lib)
IO.copyFile(loader_jar, lib / loader_jar.getName)
IO.copy(assets, CopyOptions().withOverwrite(true))
IO.setPermissions(pkgDir / "coltwi", "rwxr-xr-x") // Make bash script executable
// Create zip file
(pkgDir ** ".DS_Store").get foreach IO.delete
val zipEntries = (pkgDir ** "*").get map (f => (f, IO.relativize(target.value, f).get) )
IO.zip(zipEntries, zipfile, None)
}
)
lazy val loader = (project in file("loader"))
.settings(
commonSettings,
name := "Loader",
description := "Bootstrap loader",
// Make loader.jar generic without version number so the fitl scripts can find it.
(Compile / packageBin / artifactPath) := (Compile / target).value / "loader.jar"
)