-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.sbt
108 lines (80 loc) · 2.79 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
import java.util.concurrent.locks.ReentrantLock
val ProjectName = "gluon"
lazy val gluon = (project in file("."))
.settings(settings: _*)
lazy val settings = Seq(
name := ProjectName,
Compile / mainClass / run := Some("gluon.Main"),
autoScalaLibrary := false,
crossPaths := false,
libraryDependencies ++= Seq(
"ca.mcgill.sable" % "soot" % "4.1.0",
"gnu.getopt" % "java-getopt" % "1.0.13",
"org.slf4j" % "slf4j-simple" % "1.6.1"
),
Compile / resourceGenerators += Def.task {
val javaSourceDir = (Compile / javaSource).value
val resourceDir = (Compile / resourceManaged).value
generateSableCC.value
Seq(
file("gluon") / "contract" / "parsing" / "lexer" / "lexer.dat",
file("gluon") / "contract" / "parsing" / "parser" / "parser.dat"
).map { file =>
val src = javaSourceDir.toPath.resolve(file.toPath).toFile
val dest = resourceDir.toPath.resolve(file.toPath).toFile
IO.copyFile(src, dest)
dest
}
},
Compile / sourceGenerators += Def.task {
val javaSourceDir: File = (Compile / javaSource).value
val grammarDir = javaSourceDir / "gluon" / "contract" / "parsing"
generateSableCC.value
(grammarDir ** "*.java").get
},
assembly / assemblyMergeStrategy := {
case PathList("META-INF", _*) => MergeStrategy.discard
case "module-info.class" => MergeStrategy.first
case path => (assembly / assemblyMergeStrategy).value(path)
},
cleanFiles ++= {
val javaSourceDir = (Compile / javaSource).value
val grammarDir = javaSourceDir / "gluon" / "contract" / "parsing"
(baseDirectory.value ** "target").get ++
Seq(
grammarDir / "analysis",
grammarDir / "lexer",
grammarDir / "node",
grammarDir / "parser"
)
},
Universal / mappings += file("README.md") -> "README.md",
run / fork := true
)
lazy val gluonTests =
(project in file("test"))
.settings(
name := "test",
autoScalaLibrary := false,
crossPaths := false,
javacOptions += "-g",
Compile / javaSource := baseDirectory.value
)
val generateSableCCLock: ReentrantLock = new ReentrantLock
def generateSableCC: Def.Initialize[Task[Unit]] = Def.task {
import org.sablecc.sablecc.SableCC
val javaSourceDir: File = (Compile / javaSource).value
val grammarDir = javaSourceDir / "gluon" / "contract" / "parsing"
val grammarFile = grammarDir / "grammar.sablecc"
generateSableCCLock.lock()
try {
if (!(grammarDir / "parser" / "Parser.java").exists()) {
SableCC.processGrammar(grammarFile.getAbsolutePath, javaSourceDir.getAbsolutePath)
}
} finally {
generateSableCCLock.unlock()
}
}
enablePlugins(JavaAppPackaging)
addCommandAlias("dist", "universal:packageXzTarball")
addCommandAlias("compileTests", "gluonTests/compile")