-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgenerate.sbt
36 lines (31 loc) · 1.07 KB
/
generate.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
import sbtrelease.ReleasePlugin.runtimeVersion
sourceGenerators in Compile += genCodeTask.taskValue
def generateAppInfoSourceFile(sourceManaged: java.io.File, version: String) = {
val file = sourceManaged / "com" / "ccm" / "me" / "playground" / "bindingscala" / "AppInfo.scala"
IO.write(file,
s"""
|package com.ccm.me.playground.bindingscala
|
|object AppInfo {
| val version = "$version"
|}""".stripMargin)
Set(file)
}
def genCodeTask = Def.task {
streams.value.log.info("Generating sources")
val cachedCompile = FileFunction.cached(
streams.value.cacheDirectory / "code-gen",
inStyle = FilesInfo.lastModified,
outStyle = FilesInfo.exists) {
(in: Set[java.io.File]) =>
streams.value.log.info("Generating AppInfo")
generateAppInfoSourceFile((sourceManaged in Compile).value, runtimeVersion.value)
}
cachedCompile(Set(file("build.sbt"))).toSeq
}
val generateSources = taskKey[List[File]]("generate sources")
generateSources := {
(sourceGenerators in Compile) {
_.join.map(_.flatten.toList)
}
}.value