-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We need a nightly containing sbt/sbt#5344 if we want children projects to be insensitive to repackaging.
- Loading branch information
1 parent
48e398a
commit ea6a105
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,46 @@ | ||
package sbtmemoize | ||
|
||
import sbt.Keys._ | ||
import sbt._ | ||
import sjsonnew.support.murmurhash.Hasher | ||
import sjsonnew.{Builder, HashWriter} | ||
|
||
object MemoizePlugin extends AutoPlugin { | ||
|
||
override def trigger = noTrigger | ||
|
||
object autoImport { | ||
val memoizeCacheKey = | ||
taskKey[Int]("Compute the cache key for the current state of the project") | ||
} | ||
|
||
import autoImport._ | ||
|
||
override def projectSettings: Seq[Def.Setting[_]] = | ||
Seq(Compile, Test).flatMap(inConfig(_)(memoizeConfigSettings)) | ||
|
||
lazy val memoizeConfigSettings: Seq[Def.Setting[_]] = | ||
Seq( | ||
memoizeCacheKey := { | ||
// like FileInfo.hash but without the path (which is environment-specific) | ||
val hashWriter: HashWriter[Seq[File]] = new HashWriter[Seq[File]] { | ||
override def write[J](obj: Seq[File], builder: Builder[J]): Unit = { | ||
import sjsonnew.BasicJsonProtocol._ | ||
builder.beginArray() | ||
obj.foreach { file => | ||
builder.beginObject() | ||
builder.addField("hash", file.hash) | ||
builder.endObject() | ||
} | ||
builder.endArray() | ||
} | ||
} | ||
|
||
val srcs = sources.value | ||
val deps = dependencyClasspathAsJars.value.map(_.data) | ||
|
||
Hasher.hash(srcs ++ deps)(hashWriter).get | ||
} | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
> compile | ||
> compile | ||
> show memoizeCacheKey |