/
Build.scala
259 lines (214 loc) · 8.65 KB
/
Build.scala
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
// https://github.com/harrah/xsbt/wiki/Full-Configuration-Example
import java.text.SimpleDateFormat
import java.util.Date
import sbt.Keys._
import sbt._
object BuildSettings {
import Dependencies._
val buildOrganization = "de.fosd.typechef"
val buildVersion = "0.4.0"
val buildScalaVersion = "2.11.4"
val buildSettings = Defaults.coreDefaultSettings ++ Seq(
organization := buildOrganization,
version := buildVersion,
scalaVersion := buildScalaVersion,
shellPrompt := ShellPrompt.buildShellPrompt,
javacOptions ++= Seq("-Xlint:unchecked", "-target", "1.7"),
scalacOptions ++= Seq("-deprecation", "-unchecked", "-optimise"),
testOptions += Tests.Argument(TestFrameworks.JUnit, "-q", "-v"),
// suppress feature warnings in Scala 2.10.x
// (we do not actually change the code to allow cross builds with prior scala versions)
scalacOptions <++= scalaVersion map {
sv =>
if (sv startsWith "2.1") List(
"-Yinline-warnings",
"-feature",
"-language:postfixOps",
"-language:implicitConversions",
"-Xfatal-warnings" // make sure we take warnings seriously
)
else Nil
},
crossScalaVersions := Seq("2.10.4", "2.11.4"),
conflictWarning := ConflictWarning.disable,
libraryDependencies := {
CrossVersion.partialVersion(scalaVersion.value) match {
// if scala 2.11+ is used, add dependency on scala-xml module
case Some((2, scalaMajor)) if scalaMajor >= 11 =>
libraryDependencies.value ++ testEnvironment ++ scala211Libraries
case _ => libraryDependencies.value ++ testEnvironment
}
},
parallelExecution := false, //run into memory problems on hudson otherwise
homepage := Some(url("https://github.com/ckaestne/TypeChef")),
licenses := Seq("GNU Lesser General Public License v3.0" -> url("http://www.gnu.org/licenses/lgpl.txt")),
//maven
publishTo <<= version {
(v: String) =>
val nexus = "https://oss.sonatype.org/"
if (v.trim.endsWith("SNAPSHOT"))
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
},
publishMavenStyle := true,
publishArtifact in Test := false,
pomIncludeRepository := {
_ => false
},
pomExtra :=
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent> ++
<scm>
<connection>scm:git:git@github.com:ckaestne/TypeChef.git</connection>
<url>git@github.com:ckaestne/TypeChef.git</url>
</scm> ++
<developers>
<developer>
<id>ckaestne</id> <name>Christian Kaestner</name> <url>http://www.cs.cmu.edu/~ckaestne/</url>
</developer>
</developers>,
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
)
}
object ShellPrompt {
object devnull extends ProcessLogger {
def info(s: => String) {}
def error(s: => String) {}
def buffer[T](f: => T): T = f
}
val current = """\*\s+(\w+)""".r
def gitBranches = ("git branch --no-color" lines_! devnull mkString)
val buildShellPrompt = {
(state: State) => {
val currBranch =
current findFirstMatchIn gitBranches map (_ group (1)) getOrElse "-"
val currProject = Project.extract(state).currentProject.id
"%s:%s:%s> ".format(
currProject, currBranch, BuildSettings.buildVersion
)
}
}
}
object Dependencies {
val junit = "junit" % "junit" % "4.11" % "test"
val junitInterface = "com.novocode" % "junit-interface" % "0.11" % "test"
val scalacheck = "org.scalacheck" %% "scalacheck" % "1.12.0" % "test"
val scalatest = "org.scalatest" %% "scalatest" % "2.2.1" % "test"
val scalaparsercombinators = "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.2"
val scalaxml = "org.scala-lang.modules" %% "scala-xml" % "1.0.2"
val testEnvironment = Seq(junit, junitInterface, scalatest, scalacheck)
val scala211Libraries = Seq(scalaparsercombinators, scalaxml)
}
object VersionGen {
object VersionGenKeys {
val versionGen = TaskKey[Seq[File]]("version-gen")
val versionGenPackage = SettingKey[String]("version-gen-package")
val versionGenClass = SettingKey[String]("version-gen-class")
}
import VersionGen.VersionGenKeys._
lazy val settings = Seq(
versionGenPackage <<= Keys.organization {
(org) => org
},
versionGenClass := "Version",
versionGen <<= (sourceManaged in Compile, name, version, versionGenPackage, versionGenClass) map {
(sourceManaged: File, name: String, version: String, vgp: String, vgc: String) =>
val file = sourceManaged / vgp.replace(".", "/") / ("%s.scala" format vgc)
val code =
(
if (vgp != null && vgp.nonEmpty) "package " + vgp + "\n"
else ""
) +
"class " + vgc + " extends VersionInfo {\n" +
" def getVersion:String = \"" + version + "_" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + "\"\n" +
"}\n"
IO write(file, code)
Seq(file)
},
sourceGenerators in Compile <+= versionGen map identity
)
}
object TypeChef extends Build {
import BuildSettings._
lazy val typechef = Project(
"TypeChef",
file("."),
settings = buildSettings
) aggregate(
featureexpr,
conditionallib,
parserexp,
jcpp,
cparser,
errorlib,
ctypechecker,
javaparser,
crewrite,
frontend
)
lazy val featureexpr = Project(
"FeatureExprLib",
file("FeatureExprLib"),
settings = buildSettings
)
lazy val conditionallib = Project(
"ConditionalLib",
file("ConditionalLib"),
settings = buildSettings
) dependsOn (featureexpr)
lazy val errorlib = Project(
"ErrorLib",
file("ErrorLib"),
settings = buildSettings
) dependsOn (featureexpr)
lazy val parserexp = Project(
"ParserFramework",
file("ParserFramework"),
settings = buildSettings
) dependsOn(featureexpr, conditionallib, errorlib)
lazy val jcpp = Project(
"PartialPreprocessor",
file("PartialPreprocessor"),
settings = buildSettings
) dependsOn(featureexpr, conditionallib, errorlib)
lazy val cparser = Project(
"CParser",
file("CParser"),
settings = buildSettings ++
Seq(parallelExecution in Test := false,
libraryDependencies <+= scalaVersion(kiamaDependency(_)))
) dependsOn(featureexpr, jcpp, parserexp, conditionallib, errorlib)
lazy val frontend = Project(
"Frontend",
file("Frontend"),
settings = buildSettings ++ VersionGen.settings
) dependsOn(featureexpr, jcpp, cparser % "test->test;compile->compile", ctypechecker, conditionallib, crewrite, javaparser, errorlib)
lazy val ctypechecker = Project(
"CTypeChecker",
file("CTypeChecker"),
settings = buildSettings ++
Seq(libraryDependencies <+= scalaVersion(kiamaDependency(_)))
) dependsOn(cparser % "test->test;compile->compile", conditionallib, errorlib)
lazy val javaparser = Project(
"JavaParser",
file("JavaParser"),
settings = buildSettings
) dependsOn(featureexpr, parserexp, conditionallib, errorlib)
lazy val crewrite = Project(
"CRewrite",
file("CRewrite"),
settings = buildSettings ++
Seq(libraryDependencies <+= scalaVersion(kiamaDependency(_)))
) dependsOn(cparser % "test->test;compile->compile", ctypechecker, conditionallib, errorlib)
def kiamaDependency(scalaVersion: String, testOnly: Boolean = false) = {
val x = scalaVersion match {
case "2.9.1" => "com.googlecode.kiama" %% "kiama" % "1.2.0"
case _ => "com.googlecode.kiama" %% "kiama" % "1.8.0"
}
if (testOnly) x % "test" else x
}
}