forked from miguel-negrao/ScalaColliderUGens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sbt
196 lines (171 loc) · 7.08 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
lazy val baseName = "ScalaColliderUGens"
lazy val baseNameL = baseName.toLowerCase
lazy val projectVersion = "1.16.6-SNAPSHOT"
lazy val mimaVersion = "1.16.4"
name := baseName
lazy val commonSettings = Seq(
version := projectVersion,
organization := "de.sciss",
description := "UGens for ScalaCollider",
homepage := Some(url(s"https://github.com/Sciss/$baseName")),
scalaVersion := "2.12.3",
crossScalaVersions := Seq("2.12.3", "2.11.11", "2.10.6"),
scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature", "-encoding", "utf8", "-Xfuture", "-Xlint"),
initialCommands in console := """import de.sciss.synth._"""
) ++ publishSettings
// --- main dependencies ---
lazy val numbersVersion = "0.1.3"
lazy val scalaXMLVersion = "1.0.6"
// --- test-only dependencies ---
lazy val scalaTestVersion = "3.0.4"
// --- gen project (not published, thus not subject to major version concerns) ---
lazy val fileUtilVersion = "1.1.3"
lazy val scoptVersion = "3.7.0"
// ---
lazy val root = Project(id = baseNameL, base = file(".")).
aggregate(spec, api, gen, core, plugins).
settings(commonSettings).
settings(
packagedArtifacts := Map.empty // don't send this to Sonatype
)
// taking inspiration from http://stackoverflow.com/questions/11509843/sbt-generate-code-using-project-defined-generator
lazy val ugenGenerator = TaskKey[Seq[File]]("ugen-generate", "Generate UGen class files")
def licenseURL(licName: String, sub: String) =
licenses := Seq(licName -> url(s"https://raw.github.com/Sciss/$baseName/master/$sub/LICENSE"))
lazy val lgpl = Seq("LGPL v2.1+" -> url("http://www.gnu.org/licenses/lgpl-2.1.txt"))
lazy val spec = Project(id = s"$baseNameL-spec", base = file("spec")).
settings(commonSettings).
settings(
description := "UGens XML specification files for ScalaCollider",
autoScalaLibrary := false, // this is a pure xml containing jar
crossPaths := false,
licenseURL("BSD", "spec"),
publishArtifact in (Compile, packageDoc) := false, // there are no javadocs
publishArtifact in (Compile, packageSrc) := false, // there are no sources (only re-sources)
mimaPreviousArtifacts := Set("de.sciss" % s"$baseNameL-spec" % mimaVersion)
)
lazy val api = Project(id = s"$baseNameL-api", base = file("api")).
enablePlugins(BuildInfoPlugin).
settings(commonSettings).
settings(
description := "Basic UGens API for ScalaCollider",
licenses := lgpl,
libraryDependencies += "de.sciss" %% "numbers" % numbersVersion,
libraryDependencies ++= {
val sv = scalaVersion.value
if (!(sv startsWith "2.10")) {
("org.scala-lang.modules" %% "scala-xml" % scalaXMLVersion) :: Nil
} else Nil
},
buildInfoKeys := Seq(name, organization, version, scalaVersion, description,
BuildInfoKey.map(homepage) {
case (k, opt) => k -> opt.get
},
BuildInfoKey.map(licenses) {
case (_, Seq((lic, _))) => "license" -> lic
}
),
buildInfoPackage := "de.sciss.synth.ugen",
mimaPreviousArtifacts := Set("de.sciss" %% s"$baseNameL-api" % mimaVersion)
)
lazy val gen = Project(id = s"$baseNameL-gen", base = file("gen")).
dependsOn(spec, api).
settings(commonSettings).
settings(
description := "Source code generator for ScalaCollider UGens",
licenses := lgpl,
libraryDependencies ++= Seq(
"com.github.scopt" %% "scopt" % scoptVersion,
"de.sciss" %% "fileutil" % fileUtilVersion,
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
"org.scalatest" %% "scalatest" % scalaTestVersion % "test"
),
mimaPreviousArtifacts := Set.empty,
publishLocal := {},
publish := {},
publishArtifact := false, // cf. http://stackoverflow.com/questions/8786708/
publishTo := Some(Resolver.file("Unused transient repository", file("target/unusedrepo")))
)
lazy val core = Project(id = s"$baseNameL-core", base = file("core")).
dependsOn(api).
settings(commonSettings).
settings(
description := "UGen classes for ScalaCollider",
licenses := lgpl,
sourceGenerators in Compile <+= ugenGenerator in Compile,
ugenGenerator in Compile := {
val spc = (resourceDirectory in Compile in spec).value
val src = (sourceManaged in Compile ).value
val cp = (dependencyClasspath in Runtime in gen ).value
val st = streams.value
runUGenGenerator("--standard", spc, src, cp.files, st.log)
},
mappings in (Compile, packageSrc) ++= {
val base = (sourceManaged in Compile).value
val files = (managedSources in Compile).value
files.map { f => (f, f.relativeTo(base).get.getPath) }
},
mimaPreviousArtifacts := Set("de.sciss" %% s"$baseNameL-core" % mimaVersion)
)
lazy val plugins = Project(id = s"$baseNameL-plugins", base = file("plugins")).
dependsOn(core).
settings(commonSettings).
settings(
description := "Additional third-party UGens for ScalaCollider",
licenses := lgpl,
sourceGenerators in Compile <+= ugenGenerator in Compile,
ugenGenerator in Compile := {
val spc = (resourceDirectory in Compile in spec).value
val src = (sourceManaged in Compile ).value
val cp = (dependencyClasspath in Runtime in gen ).value
val st = streams.value
runUGenGenerator("--plugins", spc, src, cp.files, st.log)
},
mimaPreviousArtifacts := Set("de.sciss" %% s"$baseNameL-plugins" % mimaVersion)
)
def runUGenGenerator(switch: String, specDir: File, outputDir: File, cp: Seq[File], log: Logger): Seq[File] = {
val mainClass = "de.sciss.synth.ugen.Gen"
val tmp = java.io.File.createTempFile("sources", ".txt")
val os = new java.io.FileOutputStream(tmp)
log.info("Generating UGen source code in " + outputDir + " for specs in " + specDir)
try {
val outs = CustomOutput(os)
val fOpt = ForkOptions(javaHome = None, outputStrategy = Some(outs), /* runJVMOptions = Nil, */ bootJars = cp,
workingDirectory = None, connectInput = false)
val res: Int = Fork.scala(config = fOpt, arguments = mainClass :: switch :: "-d" :: outputDir.getAbsolutePath :: Nil)
if (res != 0) {
sys.error(s"UGen class file generator failed with exit code $res")
}
} finally {
os.close()
}
val sources = scala.io.Source.fromFile(tmp).getLines().map(file).toList
tmp.delete()
sources
}
// ---- publishing ----
lazy val publishSettings = Seq(
publishMavenStyle := true,
publishTo := {
Some(if (isSnapshot.value)
"Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
else
"Sonatype Releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2"
)
},
publishArtifact in Test := false,
pomIncludeRepository := { _ => false },
pomExtra := { val n = baseName
<scm>
<url>[email protected]:Sciss/{n}.git</url>
<connection>scm:git:[email protected]:Sciss/{n}.git</connection>
</scm>
<developers>
<developer>
<id>sciss</id>
<name>Hanns Holger Rutz</name>
<url>http://www.sciss.de</url>
</developer>
</developers>
}
)