-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbuild.sbt
299 lines (250 loc) · 13.7 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
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
lazy val commonSettings = Seq(
// --------- Project information
organization := "ch.epfl.data",
version := "2.3",
// --------- Compilation options
scalaVersion := "2.11.12", // LMS requires 2.11.2 --> root uses the same
javacOptions ++= Seq("-Xlint:unchecked", "-Xlint:-options", "-source", "1.6", "-_target", "1.6"),
scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature", "-optimise", "-_target:jvm-1.6" /* , "-Yinline-warnings" */),
// --------- Dependencies
resolvers += Resolver.sonatypeRepo("snapshots")
)
lazy val storelib = Project(id = "storelib", base = file("storelib"), settings = commonSettings)
lazy val core = Project(id = "core", base = file("ddbtoaster/core"), settings = commonSettings) dependsOn (storelib)
lazy val sparklib = Project(id = "sparklib", base = file("ddbtoaster/spark"), settings = commonSettings) dependsOn (storelib)
lazy val lms = Project(id = "lms", base = file("ddbtoaster/lms"), settings = commonSettings) dependsOn (storelib, core, sparklib)
lazy val pardis = Project(id = "pardis", base = file("ddbtoaster/pardis"), settings = commonSettings) dependsOn (storelib, core)
lazy val root = Project(id = "DBToaster", base = file("."), settings = commonSettings) dependsOn(core, lms, pardis) aggregate(core, sparklib, lms, pardis, storelib)
lazy val runtime = Project(id = "Runtime", base = file("runtime"), settings = commonSettings) dependsOn(storelib, pardis)
Seq(
// --------- Project information
name := "dbtoaster",
// --------- Paths
scalaSource in Compile <<= baseDirectory / "ddbtoaster/src",
javaSource in Compile <<= baseDirectory / "ddbtoaster/src",
sourceDirectory in Compile <<= baseDirectory / "ddbtoaster/src",
resourceDirectory in Compile <<= baseDirectory / "ddbtoaster/conf",
// scalaSource in Test <<= baseDirectory / "ddbtoaster/test",
// javaSource in Test <<= baseDirectory / "ddbtoaster/test",
// sourceDirectory in Test <<= baseDirectory / "ddbtoaster/test",
// --------- Execution options
fork := true, // required to enable javaOptions
javaOptions ++= Seq("-Xss128m", "-XX:-DontCompileHugeMethods", "-XX:+CMSClassUnloadingEnabled"), // ,"-Xss512m"
javaOptions ++= Seq("-Xmx4G", "-Xms1G"/*,"-verbose:gc"*/), parallelExecution in Test := false, // for large benchmarks
javaOptions <+= (fullClasspath in Runtime) map (cp => "-Dsbt.classpath=" + cp.files.absString) // propagate paths
)
// --------- LMS codegen, enabled with ddbt.lms = 1 in conf/ddbt.properties
{
val prop = new java.util.Properties()
try { prop.load(new java.io.FileInputStream("ddbtoaster/conf/ddbt.properties")) }
catch { case _: Throwable => }
if (prop.getProperty("ddbt.lms", "0") == "0") Seq()
else Seq(
scalaVersion := "2.11.2",
scalaOrganization := "org.scala-lang.virtualized",
scalacOptions ++= List("-Yvirtualize")
)
}
mainClass in run in Compile := Some("ddbt.Compiler")
packSettings
packMain := Map("compiler" -> "ddbt.Compiler")
addCommandAlias("toast", ";runMain ddbt.Compiler ") ++
addCommandAlias("unit", ";runMain ddbt.UnitTest ")
// // --------- Custom tasks
val LANG_SCALA = "vscala"
val LANG_SCALA_SC = "scala"
addCommandAlias("queries", "unit -dd -v -x -r 0 -l " + LANG_SCALA_SC + " ")
commands += Command.command("release")((state: State) => {
def copyFile(file: File, _targetDir: File) = {
if (!_targetDir.exists) _targetDir.mkdirs
IO.copyFile(file, _targetDir/file.getName)
}
def copyFiles(files: Iterable[File], _targetDir: File) = {
if (!_targetDir.exists) _targetDir.mkdirs
files.foreach { f => IO.copyFile(f, _targetDir/f.getName) }
}
def copyDir(sourceDir: File, _targetDir: File) = {
if (!_targetDir.exists) _targetDir.mkdirs
IO.copyDirectory(sourceDir, _targetDir, true)
}
def read(file: String): String = {
val f = new File(file)
val cs = new Array[Char](f.length.toInt)
val r = new java.io.FileReader(f)
r.read(cs)
r.close
new String(cs)
}
def write(file: String, data: String) = {
val f = new File(file)
val dir = f.getParentFile
if (dir != null && !dir.exists) dir.mkdirs
val o = new java.io.PrintWriter(f)
o.write(data)
o.close()
}
def fixSqlFiles(files: Iterable[File], _targetDir: File) = {
if (!_targetDir.exists) _targetDir.mkdirs
def fixSQL(input:String) = {
var output_next_self = false
(new scala.collection.immutable.StringOps(input)).lines.map { l =>
l.replace("../../experiments", "examples")
.replace("test/queries", "examples/queries")
.replace("standard/", "")
.replace("tiny/", "")
.replace("big/", "")
.replace("data/finance/finance.csv", "data/finance.csv")
.replace("../alpha5/", "")
.replaceAll("--.*", "") + IO.Newline
}.filter { l =>
if(!l.trim.isEmpty) { output_next_self = true; true }
else if(output_next_self) { output_next_self = false; true }
else false
}.mkString
}
files.foreach { f =>
write((_targetDir/f.getName).getAbsolutePath(), fixSQL(read(f.getAbsolutePath())))
}
}
// load all the properties
val prop = new java.util.Properties()
try { prop.load(new java.io.FileInputStream("ddbtoaster/conf/ddbt.properties")) }
catch { case _: Throwable => }
println("defining base and release paths")
val baseDir = baseDirectory.value/"ddbtoaster"
val releaseDir = baseDir/"release"
println("cleaning")
IO.delete(releaseDir/"bin"/"dbtoaster_frontend")
// IO.delete(releaseDir/"CHANGELOG")
IO.delete(releaseDir/"LICENSE")
// IO.delete(releaseDir/"README")
IO.delete(releaseDir/"doc")
IO.delete(releaseDir/"examples")
IO.delete(releaseDir/"lib")
println("compiling sources")
val compilerFilePath = (baseDir/"src"/"Compiler.scala").getAbsolutePath
val compilerClassContent = read(compilerFilePath).trim
write(compilerFilePath, compilerClassContent.replace("= DEPLOYMENT_STATUS_DEVELOPMENT", "= DEPLOYMENT_STATUS_RELEASE"))
Project.runTask(compile, state)
val propertiesFilePath = (baseDir/"conf"/"ddbt.properties").getAbsolutePath
val propertiesFileContent = read(propertiesFilePath)
write(propertiesFilePath, "ddbt.base_repo=.")
println("execute pack task")
Project.runTask(pack, state)
write(propertiesFilePath, propertiesFileContent)
println("copy all the Scala dependency libraries")
val sourceDir = baseDirectory.value/"_target"/"pack"/"lib";
if (sourceDir.exists) {
val _targetDir = releaseDir/"lib"/"dbt_scala"
_targetDir.mkdirs
copyFiles(IO.listFiles(sourceDir).filter { _.getName.matches(
"(akka-actor|config|scala-library|scala-reflect|scala-parser-combinators|scala-xml" +
"|sc-shared|sc-pardis-compiler|sc-pardis-core-compiler|sc-pardis-library|sc-pardis-quasi|scala-yinyang|squid-sc-backend" +
"|dbtoaster|lms|scalariform).*") }, _targetDir)
val ddbtJar = _targetDir/s"dbtoaster_${scalaBinaryVersion.value}-${version.value}.jar"
if (prop.getProperty("ddbt.lms","0") != "1") { // vanilla scala
println(s"using vanilla Scala + PARDIS version using dbtoaster_${scalaBinaryVersion.value}-${version.value}.jar")
IO.copyFile(ddbtJar, _targetDir/s"dbtoaster-${version.value}.jar")
}
else { // lms
println(s"using Scala + LMS version using dbtoaster_${scalaBinaryVersion.value}-${version.value}.jar")
IO.copyFile(ddbtJar, _targetDir/s"dbtoaster-${version.value}-lms.jar")
}
IO.delete(ddbtJar)
} else {
println("Libraries (in " + sourceDir + ") are not created via pack command.")
}
println("copy dbtoaster_release")
val frontendRepo = file(prop.getProperty("ddbt.base_repo", ""))
if (frontendRepo != "") {
println("make dbt_release")
("make -C " + frontendRepo.getAbsolutePath)!;
println("copy dbt_release")
val dbtBinPath = frontendRepo/"bin"/"dbtoaster_release"
copyFile(dbtBinPath, releaseDir/"bin")
("mv " + (releaseDir/"bin"/dbtBinPath.getName).getAbsolutePath + " " + (releaseDir/"bin"/"dbtoaster_frontend").getAbsolutePath)!;
("chmod +x " + (releaseDir/"bin"/"dbtoaster_frontend").getAbsolutePath)!;
println("copy LICENSE")
copyFile(baseDir/".."/"LICENSE", releaseDir)
// val websitePath = frontendRepo/".."/".."/"website"
// println("copy README, LICENSE and CHANGELOG")
// copyFile(websitePath/"README", releaseDir)
// copyFile(websitePath/"CHANGELOG", releaseDir)
// copyFile(frontendRepo/"LICENSE", releaseDir)
// println("copy docs to doc dir")
// val releaseDocDir = releaseDir/"doc"
// releaseDocDir.mkdirs
// copyFiles(
// List("9.jpg", "bakeoff.png", "bluetab.gif", "bluetabactive.gif", "dbtoaster-logo.gif",
// "favicon.ico", "internal_arch.png", "perf.png", "schematic.png")
// .map(f => websitePath/"site_html"/f),
// releaseDocDir)
// copyFiles(IO.listFiles(websitePath/"site_html").filter(f => f.getName.endsWith(".html") && !f.getName.startsWith("samples_")), releaseDocDir)
// copyFiles(IO.listFiles(websitePath/"site_html"/"css").filter(_.getName.endsWith(".css")), releaseDocDir/"css")
// copyFiles(IO.listFiles(websitePath/"site_html"/"js").filter(_.getName.endsWith(".js")), releaseDocDir/"js")
val cppOldLibDir = baseDir/"srccpp"/"old_lib"
// sanity check old c++ lib compiles
println("make old C++ libs")
("make -C " + cppOldLibDir.getAbsolutePath)!;
println("copy old C++ libs")
val releaseCppOldLibDir = releaseDir/"lib"/"dbt_c++"/"old_lib"
releaseCppOldLibDir.mkdirs
(releaseCppOldLibDir/"hpds").mkdirs
(releaseCppOldLibDir/"mmap").mkdirs
(releaseCppOldLibDir/"smhasher").mkdirs
(releaseCppOldLibDir/"sc").mkdirs
copyFiles(IO.listFiles(cppOldLibDir).filter { f => f.getName.endsWith(".cpp") || f.getName.endsWith(".hpp") || f.getName.endsWith(".h") || "makefile" == f.getName }, releaseCppOldLibDir)
copyFiles(IO.listFiles(cppOldLibDir/"hpds").filter { f => f.getName.endsWith(".cpp") || f.getName.endsWith(".hpp") || "makefile" == f.getName }, releaseCppOldLibDir/"hpds")
copyFiles(IO.listFiles(cppOldLibDir/"mmap").filter { f => f.getName.endsWith(".cpp") || f.getName.endsWith(".hpp") || "makefile" == f.getName }, releaseCppOldLibDir/"mmap")
copyFiles(IO.listFiles(cppOldLibDir/"smhasher").filter { f => f.getName.startsWith("MurmurHash2") }, releaseCppOldLibDir/"smhasher")
copyFiles(IO.listFiles(cppOldLibDir/"sc").filter { f => f.getName.endsWith(".cpp") || f.getName.endsWith(".hpp") || f.getName.endsWith(".h") || "makefile" == f.getName }, releaseCppOldLibDir/"sc")
val cppOldDriverDir = baseDir/"srccpp"/"old_driver"
// sanity check old c++ driver compiles
println("make old C++ driver")
("make -C " + cppOldDriverDir.getAbsolutePath)!;
println("copy old C++ driver")
val releaseCppOldDriverDir = releaseDir/"lib"/"dbt_c++"/"old_driver"
releaseCppOldDriverDir.mkdirs
copyFiles(IO.listFiles(cppOldDriverDir).filter { f => f.getName.endsWith(".cpp") || f.getName.endsWith(".hpp") || f.getName.endsWith(".h") || "makefile" == f.getName }, releaseCppOldDriverDir)
println("copy C++ libs")
val cppLibDir = baseDir/"srccpp"/"lib"
val releaseCppLibDir = releaseDir/"lib"/"dbt_c++"/"lib"
releaseCppLibDir.mkdirs
(releaseCppLibDir/"pardis").mkdirs
copyFiles(IO.listFiles(cppLibDir).filter { f => f.getName.endsWith(".hpp") }, releaseCppLibDir)
copyFiles(IO.listFiles(cppLibDir/"pardis").filter { f => f.getName.endsWith(".hpp") }, releaseCppLibDir/"pardis")
println("copy C++ driver")
val cppDriverDir = baseDir/"srccpp"/"driver"
val releaseCppDriverDir = releaseDir/"lib"/"dbt_c++"/"driver"
releaseCppDriverDir.mkdirs
copyFiles(IO.listFiles(cppDriverDir).filter { f => f.getName.endsWith(".cpp") || f.getName.endsWith(".hpp") }, releaseCppDriverDir)
// println("copy main.cpp")
// copyFile(frontendRepo/"lib"/"dbt_c++"/"main.cpp", releaseDir/"examples"/"code")
// println("make scala libs")
// val scalaLibDir = frontendRepo/"lib"/"dbt_scala"
// ("make -C "+scalaLibDir.getAbsolutePath)!;
// copyFile(frontendRepo/"lib"/"dbt_scala"/"dbtlib.jar", releaseDir/"lib"/"dbt_scala")
// copyFile(frontendRepo/"lib"/"dbt_scala"/"tuplegen.jar", releaseDir/"lib"/"dbt_scala")
val dataRepo = file(prop.getProperty("ddbt.data_repo", ""))
if (dataRepo != "") {
println("copy data files to data")
copyFiles(IO.listFiles(dataRepo/"simple"/"tiny").filter(_.getName.endsWith(".dat")), releaseDir/"examples"/"data"/"simple")
copyFiles(IO.listFiles(dataRepo/"tpch"/"tiny").filter(_.getName.endsWith(".csv")), releaseDir/"examples"/"data"/"tpch")
copyFiles(IO.listFiles(dataRepo/"mddb"/"tiny").filter(_.getName.endsWith(".csv")), releaseDir/"examples"/"data"/"mddb")
copyFile(dataRepo/"finance"/"tiny"/"finance.csv", releaseDir/"examples"/"data")
}
println("copy query files to queries")
fixSqlFiles((frontendRepo/"test"/"queries"/"simple") * "r*.sql" get, releaseDir/"examples"/"queries"/"simple")
fixSqlFiles(IO.listFiles(frontendRepo/"test"/"queries"/"tpch").filter(f => !"""((query[0-9]+a?)|(schemas)).sql""".r.findFirstIn(f.getName).isEmpty), releaseDir/"examples"/"queries"/"tpch")
fixSqlFiles(((frontendRepo/"test"/"queries"/"finance") * "*.sql" get).filter(_.getName != "chrissedtrades.sql"), releaseDir/"examples"/"queries"/"finance")
fixSqlFiles(IO.listFiles(frontendRepo/"test"/"queries"/"mddb").filter(f => !"""((query[1-2]+.sql)|(schemas.sql)|(README))""".r.findFirstIn(f.getName).isEmpty), releaseDir/"examples"/"queries"/"mddb")
val distDir = baseDir/"dist";
if (!distDir.exists) distDir.mkdirs;
val tmpDir = baseDir/"dbtoaster"
(s"mv ${releaseDir.getAbsolutePath} ${tmpDir.getAbsolutePath}")!;
(s"tar -cvzf ${distDir.getAbsolutePath}/dbtoaster.tgz -C ${baseDir} ./dbtoaster")!;
(s"mv ${tmpDir.getAbsolutePath} ${releaseDir.getAbsolutePath}")!;
}
write(compilerFilePath, compilerClassContent)
state
})