summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-03-03 11:14:22 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-03-03 11:33:53 -0800
commit8c360c652902b9ccf13060ea1fd050bf473bf2d8 (patch)
treecd7d72f9fb785d193163ae768b46eea234f10b6d /core
parent4edb1740397f6328177042a55a1404e42c1d6439 (diff)
downloadmill-8c360c652902b9ccf13060ea1fd050bf473bf2d8.tar.gz
mill-8c360c652902b9ccf13060ea1fd050bf473bf2d8.tar.bz2
mill-8c360c652902b9ccf13060ea1fd050bf473bf2d8.zip
Split out `upstreamAssembly` from `assembly`
Also re-write `Jvm.createAssembly` to allow incremental assembly construction. This should allow much faster assembly creation in the common case where upstream dependencies do not change
Diffstat (limited to 'core')
-rw-r--r--core/src/mill/eval/PathRef.scala19
-rw-r--r--core/src/mill/util/DummyInputStream.scala5
-rw-r--r--core/src/mill/util/IO.scala32
3 files changed, 37 insertions, 19 deletions
diff --git a/core/src/mill/eval/PathRef.scala b/core/src/mill/eval/PathRef.scala
index 168eaa9a..0fbc18f8 100644
--- a/core/src/mill/eval/PathRef.scala
+++ b/core/src/mill/eval/PathRef.scala
@@ -4,10 +4,11 @@ import java.io.IOException
import java.nio.file.attribute.BasicFileAttributes
import java.nio.file.{FileVisitResult, FileVisitor}
import java.nio.{file => jnio}
-import java.security.MessageDigest
+import java.security.{DigestOutputStream, MessageDigest}
+
import upickle.default.{ReadWriter => RW}
import ammonite.ops.Path
-import mill.util.JsonFormatters
+import mill.util.{DummyOutputStream, IO, JsonFormatters}
/**
@@ -23,8 +24,7 @@ object PathRef{
def apply(path: ammonite.ops.Path, quick: Boolean = false) = {
val sig = {
val digest = MessageDigest.getInstance("MD5")
-
- val buffer = new Array[Byte](16 * 1024)
+ val digestOut = new DigestOutputStream(DummyOutputStream, digest)
jnio.Files.walkFileTree(
path.toNIO,
new FileVisitor[jnio.Path] {
@@ -43,16 +43,7 @@ object PathRef{
digest.update(value.toByte)
}else {
val is = jnio.Files.newInputStream(file)
-
- def rec(): Unit = {
- val length = is.read(buffer)
- if (length != -1) {
- digest.update(buffer, 0, length)
- rec()
- }
- }
- rec()
-
+ IO.stream(is, digestOut)
is.close()
}
FileVisitResult.CONTINUE
diff --git a/core/src/mill/util/DummyInputStream.scala b/core/src/mill/util/DummyInputStream.scala
deleted file mode 100644
index 310b358b..00000000
--- a/core/src/mill/util/DummyInputStream.scala
+++ /dev/null
@@ -1,5 +0,0 @@
-package mill.util
-
-import java.io.ByteArrayInputStream
-
-object DummyInputStream extends ByteArrayInputStream(Array()) \ No newline at end of file
diff --git a/core/src/mill/util/IO.scala b/core/src/mill/util/IO.scala
new file mode 100644
index 00000000..833e52c7
--- /dev/null
+++ b/core/src/mill/util/IO.scala
@@ -0,0 +1,32 @@
+package mill.util
+
+import java.io.{InputStream, OutputStream}
+
+import scala.tools.nsc.interpreter.OutputStream
+
+/**
+ * Misc IO utilities, eventually probably should be pushed upstream into
+ * ammonite-ops
+ */
+object IO {
+ def stream(src: InputStream, dest: OutputStream) = {
+ val buffer = new Array[Byte](4096)
+ while ( {
+ src.read(buffer) match {
+ case -1 => false
+ case n =>
+ dest.write(buffer, 0, n)
+ true
+ }
+ }) ()
+ }
+}
+
+import java.io.{ByteArrayInputStream, OutputStream}
+
+object DummyInputStream extends ByteArrayInputStream(Array())
+object DummyOutputStream extends OutputStream{
+ override def write(b: Int) = ()
+ override def write(b: Array[Byte]) = ()
+ override def write(b: Array[Byte], off: Int, len: Int) = ()
+}