-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.sc
179 lines (151 loc) · 7.91 KB
/
build.sc
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// build.sc
import mill._
import mill.define.Sources
import scalalib._
import $ivy.`com.lihaoyi::mill-contrib-buildinfo:$MILL_VERSION`
import mill.contrib.buildinfo.BuildInfo
trait YuckBuild extends ScalaModule with BuildInfo {
val buildType: String
def git(args: String*) = os.proc("git" :: args.toList).call().out.lines.head
def gitCommitHash = T.input {git("rev-parse", "HEAD")}
def gitCommitDate = T {git("log", "-1", "--pretty=format:%cd", "--date=format:%Y%m%d")}
def gitBranch = T {git("rev-parse", "--abbrev-ref", "HEAD")}
def shortVersion = T {gitCommitDate()}
def longVersion = T {
"%s-%s-%s-%s".format(gitCommitDate(), gitBranch().replaceAll("/", "-"), gitCommitHash().take(8), buildType)}
def version = T {if (gitBranch() == "master") shortVersion() else longVersion()}
override def buildInfoPackageName = Some("yuck")
override def buildInfoMembers: T[Map[String, String]] = T {
Map(
"buildType" -> buildType,
"gitBranch" -> gitBranch(),
"gitCommitDate" -> gitCommitDate(),
"gitCommitHash" -> gitCommitHash(),
"version" -> version()
)
}
override def scalaVersion = "3.3.1"
override def millSourcePath = os.pwd
override def sources = T.sources {millSourcePath / "src" / "main"}
override def resources = T.sources()
override def javacOptions = Seq("-source", "1.8", "-target", "1.8")
override def scalacOptions = Seq("-deprecation", "-unchecked", "-feature")
override def ivyDeps = Agg(
ivy"com.conversantmedia:rtree:1.0.5",
ivy"com.github.scopt::scopt:4.1.0",
ivy"org.jgrapht:jgrapht-core:1.4.0",
ivy"org.scala-lang.modules::scala-parser-combinators:2.3.0"
)
val basicJvmConfiguration = Seq("-Djava.lang.Integer.IntegerCache.high=10000", "-XX:+UseParallelGC")
val jvmHeapSize = Option(System.getenv("YUCK_HEAP_SIZE")).getOrElse("2G")
val jvmConfiguration = Seq("-Xmx%s".format(jvmHeapSize)) ++ basicJvmConfiguration
override def forkArgs = jvmConfiguration
override def mainClass = Some("yuck.flatzinc.runner.FlatZincRunner")
def fullClasspath = T {(localClasspath() ++ upstreamAssemblyClasspath()).map(_.path)}
def fullClasspathAsString = T {fullClasspath().mkString(":")}
object test extends Tests {
override def millSourcePath = os.pwd
override def sources = T.sources {millSourcePath / "src" / "test"}
override def resources = T.sources()
override def ivyDeps = Agg(
ivy"junit:junit:4.13.2",
ivy"io.spray::spray-json:1.3.6".withDottyCompat(scalaVersion()),
ivy"org.jgrapht:jgrapht-io:1.4.0",
ivy"org.mockito:mockito-core:3.12.4"
)
override def testFramework = "com.novocode.junit.JUnitFramework"
val jvmHeapSize = Option(System.getenv("YUCK_TEST_HEAP_SIZE")).getOrElse("2G")
val jvmConfiguration = Seq("-Xmx%s".format(jvmHeapSize), "-XX:+AggressiveHeap") ++ basicJvmConfiguration
override def forkArgs = jvmConfiguration
override def mainClass = Some("yuck.test.util.YuckTestRunner")
def fullClasspath = T {(localClasspath() ++ upstreamAssemblyClasspath()).map(_.path)}
def fullClasspathAsString = T {fullClasspath().mkString(":")}
}
def documentation = T.source {millSourcePath / "doc"}
def miniZincBindings = T.source {millSourcePath / "resources" / "mzn" / "lib" / "yuck"}
def miniZincSolverConfigurationTemplate = T.source {millSourcePath / "resources" / "mzn" / "yuck.msc.in"}
def unixStartScriptTemplate = T.source {millSourcePath / "resources" / "bin" / "yuck.in"}
def winStartScriptTemplate = T.source {millSourcePath / "resources" / "bin" / "yuck.bat.in"}
def debianControlFileTemplate = T.source {millSourcePath / "resources" / "debian" / "control.in"}
def corePackage = T {
val packageName = "yuck-".concat(version())
val packageDir = T.dest / packageName
os.remove.all(packageDir)
for (dependency <- upstreamAssemblyClasspath().map(_.path)) {
os.copy.into(dependency, packageDir / "lib", createFolders = true, copyAttributes = true)
}
val yuckJarName = packageName.concat(".jar")
os.copy(jar().path, packageDir / "lib" / yuckJarName, createFolders = true, copyAttributes = true)
os.copy(documentation().path, packageDir / "doc", createFolders = true, copyAttributes = true)
os.copy(miniZincBindings().path, packageDir / "mzn" / "lib", createFolders = true, copyAttributes = true)
val classPathComponents = (upstreamAssemblyClasspath().iterator.map(_.path.last).toSeq :+ yuckJarName)
val unixClassPath = classPathComponents.map(jarName => "$LIB_DIR/".concat(jarName)).mkString(":")
val basicMapping = Map("#YUCK_JAVA_OPTS#" -> basicJvmConfiguration.mkString(" "), "#MAIN_CLASS#" -> mainClass().get)
fillTemplateIn(
unixStartScriptTemplate().path,
packageDir / "bin" / "yuck",
basicMapping + ("#CLASS_PATH#" -> unixClassPath))
makeExecutable(packageDir / "bin" / "yuck")
val winClassPath = classPathComponents.map(jarName => "%LIB_DIR%\\".concat(jarName)).mkString(";")
fillTemplateIn(
winStartScriptTemplate().path,
packageDir / "bin" / "yuck.bat",
basicMapping + ("#CLASS_PATH#" -> winClassPath))
PathRef(packageDir)
}
def universalPackage = T {
val packageName = "yuck-".concat(version())
val packageDir = T.dest / packageName
os.remove.all(packageDir)
os.copy(corePackage().path, packageDir, createFolders = true, copyAttributes = true)
fillTemplateIn(
miniZincSolverConfigurationTemplate().path,
packageDir / "mzn" / "yuck.msc",
Map("#VERSION#" -> version(), "#EXE_PATH#" -> "../bin/yuck", "#MZN_LIB_PATH#" -> "lib"))
val archiveName = packageName.concat(".zip")
os.proc("zip", "-r", archiveName, packageName).call(cwd = T.dest)
PathRef(T.dest / archiveName)
}
def debianPackage = T {
val packageName = "yuck-".concat(version())
val packageDir = T.dest / packageName
os.remove.all(packageDir)
os.copy(corePackage().path, packageDir / "usr" / "share" / "yuck", createFolders = true, copyAttributes = true)
fillTemplateIn(
miniZincSolverConfigurationTemplate().path,
packageDir / "usr" / "share" / "minizinc" / "solvers" / "yuck.msc",
Map("#VERSION#" -> version(), "#EXE_PATH#" -> "/usr/bin/yuck", "#MZN_LIB_PATH#" -> "/usr/share/yuck/mzn/lib"))
fillTemplateIn(
debianControlFileTemplate().path,
packageDir / "DEBIAN" / "control",
Map("#VERSION#" -> version()))
os.makeDir.all(packageDir / "usr" / "bin")
os.symlink(packageDir / "usr" / "bin" / "yuck", os.Path("/usr/share/yuck/bin/yuck"))
os.proc("dpkg-deb", "--build", packageName).call(cwd = T.dest)
PathRef(T.dest / (packageName.concat(".deb")))
}
private def fillTemplateIn(template: os.Path, target: os.Path, mapping: Map[String, String]): Unit = {
os.write.append(
target,
mapping.foldLeft(os.read(template))({case (s, (k, v)) => s.replace(k, v)}),
createFolders = true)
}
private def makeExecutable(path: os.Path): Unit = {
import java.nio.file.Files
import java.nio.file.attribute.PosixFilePermission
val perms = Files.getPosixFilePermissions(path.toNIO)
perms.add(PosixFilePermission.GROUP_EXECUTE)
perms.add(PosixFilePermission.OWNER_EXECUTE)
perms.add(PosixFilePermission.OTHERS_EXECUTE)
Files.setPosixFilePermissions(path.toNIO, perms)
}
}
object yuck extends Module {
object dev extends YuckBuild {
override val buildType = "dev"
}
object prod extends YuckBuild {
override val buildType = "prod"
override val skipIdea = true
}
}