Commit 656d9a8a authored by Kunshan Wang's avatar Kunshan Wang

Generate zip package

parent f3f2ce01
......@@ -29,6 +29,9 @@ import uvm.refimpl.nat.NativeSupport
import uvm.refimpl.nat.PlatformConstants.Word
import uvm.types._
import uvm.utils.WithUtils.tryWithResource
import java.util.zip.ZipOutputStream
import uvm.utils.IOHelpers
import java.util.zip.ZipEntry
class BootImageBuilder(implicit microVM: MicroVM) {
def makeBootImage(whiteList: Seq[TopLevel], outputFile: String): Unit = {
......@@ -114,6 +117,10 @@ class BootImageWriter(tcb: TransitiveClosureBuilder, outputFile: String)(implici
val idNameMapPath = tempDir.resolve(IDNAMEMAP_FILE)
val uirBundlePath = tempDir.resolve(UIRBUNDLE_FILE)
val zipPath = Paths.get(outputFile)
val allZipContents = Seq(globalGroup.dataFile, heapGroup.dataFile, globalGroup.allocFile, heapGroup.allocFile,
globalGroup.relocFile, heapGroup.relocFile, idNameMapPath, uirBundlePath)
private val globalMemory: Space = microVM.memoryManager.globalMemory
private val smallObjectSpace: Space = microVM.memoryManager.heap.space
......@@ -149,6 +156,8 @@ class BootImageWriter(tcb: TransitiveClosureBuilder, outputFile: String)(implici
writeIDNameMap()
writeUIRBundle()
makeZipPackage()
}
private def writeAllocUnit(addr: Word, group: FileGroup, isGlobal: Boolean): Unit = {
......@@ -256,6 +265,18 @@ class BootImageWriter(tcb: TransitiveClosureBuilder, outputFile: String)(implici
bundleSerializer.writeUIR(writer)
}
}
private def makeZipPackage(): Unit = {
tryWithResource(new ZipOutputStream(Files.newOutputStream(zipPath))) { zos =>
for (path <- allZipContents) {
val entry = new ZipEntry(path.getFileName.toString)
zos.putNextEntry(entry)
tryWithResource(Files.newInputStream(path)) { fis =>
IOHelpers.copy(fis, zos)
}
}
}
}
}
class AlignedOutputStream(os: OutputStream) extends Closeable {
......
package uvm.utils
import java.io.Reader
import java.io.OutputStream
import java.io.InputStream
object IOHelpers {
def slurp(r: Reader): String = {
......@@ -19,4 +21,20 @@ object IOHelpers {
sb.toString()
}
private val BYTE_BUFFER_SIZE = 16384
def copy(in: InputStream, out: OutputStream): Unit = {
val buf = new Array[Byte](BYTE_BUFFER_SIZE)
var finished = false
while (!finished) {
val actualRead = in.read(buf, 0, BYTE_BUFFER_SIZE)
if (actualRead > 0) {
out.write(buf, 0, actualRead)
} else {
finished = true
}
}
}
}
\ No newline at end of file
......@@ -25,7 +25,7 @@ class BootImageWriterTest extends UvmBundleTesterBase with ExtraMatchers {
val tcb = new TransitiveClosureBuilder(everything)(microVM)
tcb.doTransitiveClosure()
val biw = new BootImageWriter(tcb, "just-test")(microVM)
val biw = new BootImageWriter(tcb, "target/boot-image-writer-test.muref")(microVM)
biw.writeFile()
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment