diff --git a/README.md b/README.md index d974690..57931e3 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,16 @@ cp vbmeta.img +
+ clean workspace +When you finished current work and need to clean the workspace for next image, it's a good idea to call the `clear` command: + +```bash +./gradlew clear +``` + +
+
working with boot.img and vbmeta.img diff --git a/bbootimg/src/main/kotlin/packable/BootImgParser.kt b/bbootimg/src/main/kotlin/packable/BootImgParser.kt index e7e7279..35af43e 100644 --- a/bbootimg/src/main/kotlin/packable/BootImgParser.kt +++ b/bbootimg/src/main/kotlin/packable/BootImgParser.kt @@ -35,7 +35,7 @@ class BootImgParser : IPackable { } override fun unpack(fileName: String) { - cleanUp() + clear() val hv = probeHeaderVersion(fileName) log.info("header version $hv") when (hv) { @@ -126,12 +126,12 @@ class BootImgParser : IPackable { super.pull(fileName, deviceName) } - fun clean(fileName: String) { - super.cleanUp() + fun clear(fileName: String) { + super.clear() listOf("", ".clear", ".google", ".clear", ".signed", ".signed2").forEach { "$fileName$it".deleteIfExists() } - VBMetaParser().clean("vbmeta.img") + VBMetaParser().clear("vbmeta.img") } companion object { diff --git a/bbootimg/src/main/kotlin/packable/DtboParser.kt b/bbootimg/src/main/kotlin/packable/DtboParser.kt index 32cc954..51594ec 100644 --- a/bbootimg/src/main/kotlin/packable/DtboParser.kt +++ b/bbootimg/src/main/kotlin/packable/DtboParser.kt @@ -42,7 +42,7 @@ class DtboParser(val workDir: File) : IPackable { } override fun unpack(fileName: String) { - cleanUp() + clear() Dtbo.parse(fileName) .unpack(outDir) .extractVBMeta() @@ -61,12 +61,12 @@ class DtboParser(val workDir: File) : IPackable { super.`@verify`(fileName) } - fun clean(fileName: String) { - super.cleanUp() + fun clear(fileName: String) { + super.clear() listOf("", ".clear", ".google", ".clear", ".signed", ".signed2").forEach { "$fileName$it".deleteIfExists() } - VBMetaParser().clean("vbmeta.img") + VBMetaParser().clear("vbmeta.img") } private fun execInDirectory(cmd: CommandLine, inWorkDir: File) { @@ -108,7 +108,7 @@ class DtboParser(val workDir: File) : IPackable { @Deprecated("for debugging purpose only") fun unpackLegacy(fileName: String) { - cleanUp() + clear() val dtbPath = File("$outDir/dtb").path val headerPath = File("$outDir/dtbo.header").path val cmdPrefix = if (EnvironmentVerifier().isWindows) "python " else "" diff --git a/bbootimg/src/main/kotlin/packable/IPackable.kt b/bbootimg/src/main/kotlin/packable/IPackable.kt index b03976b..41704cb 100644 --- a/bbootimg/src/main/kotlin/packable/IPackable.kt +++ b/bbootimg/src/main/kotlin/packable/IPackable.kt @@ -19,6 +19,7 @@ import cfig.Avb import cfig.helper.Helper import cfig.helper.Helper.Companion.check_call import cfig.helper.Helper.Companion.check_output +import cfig.helper.Helper.Companion.deleteIfExists import org.slf4j.Logger import org.slf4j.LoggerFactory import java.io.File @@ -70,10 +71,14 @@ interface IPackable { Avb().verify(ai, fileName) } - fun cleanUp() { + fun clear() { val workDir = Helper.prop("workDir") - if (File(workDir).exists()) File(workDir).deleteRecursively() + if (File(workDir).exists()) { + log.info("deleting $workDir ...") + File(workDir).deleteRecursively() + } File(workDir).mkdirs() + "uiderrors".deleteIfExists() } companion object { diff --git a/bbootimg/src/main/kotlin/packable/MiscImgParser.kt b/bbootimg/src/main/kotlin/packable/MiscImgParser.kt index 9c38208..cf8a1e4 100644 --- a/bbootimg/src/main/kotlin/packable/MiscImgParser.kt +++ b/bbootimg/src/main/kotlin/packable/MiscImgParser.kt @@ -14,13 +14,12 @@ package cfig.packable -import cc.cfig.io.Struct +import cfig.helper.Helper import miscimg.MiscImage import cfig.helper.Helper.Companion.deleteIfExists import com.fasterxml.jackson.databind.ObjectMapper import org.slf4j.LoggerFactory import java.io.File -import java.io.FileOutputStream import java.io.RandomAccessFile class MiscImgParser : IPackable { @@ -31,23 +30,22 @@ class MiscImgParser : IPackable { return listOf("^misc\\.img$") } + private fun getOutputFile(fileName: String): File { + return File(workDir + "/" + File(fileName).name.removeSuffix(".img") + ".json") + } + override fun unpack(fileName: String) { - cleanUp() + clear() val misc = MiscImage.parse(fileName) log.info(misc.toString()) + ObjectMapper().writerWithDefaultPrettyPrinter().writeValue(getOutputFile(fileName), misc) ObjectMapper().writerWithDefaultPrettyPrinter() - .writeValue(File(File(fileName).name.removeSuffix(".img") + ".json"), misc) - ObjectMapper().writerWithDefaultPrettyPrinter().writeValue( - File("sample.json"), - MiscImage.BootloaderMessage.generateSamples() - ) + .writeValue(getOutputFile("sample.img"), MiscImage.BootloaderMessage.generateSamples()) + log.info(getOutputFile(fileName).path + " is ready") } override fun pack(fileName: String) { - val misc = ObjectMapper().readValue( - File(File(fileName).name.removeSuffix(".img") + ".json"), - MiscImage::class.java - ) + val misc = ObjectMapper().readValue(getOutputFile(fileName), MiscImage::class.java) val out = File("$fileName.new") File(fileName).copyTo(out, true) RandomAccessFile(out.name, "rw").use { raf -> @@ -73,15 +71,15 @@ class MiscImgParser : IPackable { super.pull(fileName, deviceName) } - fun clean(fileName: String) { - super.cleanUp() - listOf("", ".clear", ".google", ".clear", ".signed", ".signed2").forEach { + fun clear(fileName: String) { + super.clear() + listOf("", ".new").forEach { "$fileName$it".deleteIfExists() } - VBMetaParser().clean("vbmeta.img") } companion object { private val log = LoggerFactory.getLogger(MiscImgParser::class.java) + private val workDir = Helper.prop("workDir") } } diff --git a/bbootimg/src/main/kotlin/packable/PayloadBinParser.kt b/bbootimg/src/main/kotlin/packable/PayloadBinParser.kt index 7495610..e9107c2 100644 --- a/bbootimg/src/main/kotlin/packable/PayloadBinParser.kt +++ b/bbootimg/src/main/kotlin/packable/PayloadBinParser.kt @@ -25,7 +25,7 @@ class PayloadBinParser : IPackable { } override fun unpack(fileName: String) { - cleanUp() + clear() Payload.parse(fileName).let { pl -> pl.setUp() pl.printInfo() @@ -44,7 +44,7 @@ class PayloadBinParser : IPackable { super.pull(fileName, deviceName) } - fun clean(fileName: String) { + fun clear(fileName: String) { } override fun flash(fileName: String, deviceName: String) { diff --git a/bbootimg/src/main/kotlin/packable/VBMetaParser.kt b/bbootimg/src/main/kotlin/packable/VBMetaParser.kt index 5c08e7c..e014180 100644 --- a/bbootimg/src/main/kotlin/packable/VBMetaParser.kt +++ b/bbootimg/src/main/kotlin/packable/VBMetaParser.kt @@ -16,6 +16,7 @@ package cfig.packable import avb.AVBInfo import cfig.Avb +import cfig.helper.Helper import cfig.helper.Helper.Companion.deleteIfExists import com.fasterxml.jackson.databind.ObjectMapper import org.slf4j.LoggerFactory @@ -24,7 +25,7 @@ import java.nio.file.Files import java.nio.file.Paths import java.nio.file.StandardOpenOption -class VBMetaParser: IPackable { +class VBMetaParser : IPackable { override val loopNo: Int get() = 1 @@ -32,12 +33,12 @@ class VBMetaParser: IPackable { return listOf("^vbmeta\\.img$", "^vbmeta\\_[a-z]+.img$") } - override fun cleanUp() { - File(outDir).mkdirs() - } - override fun unpack(fileName: String) { - cleanUp() + File(Helper.prop("workDir")).let { + if (!it.exists()) { + it.mkdirs() + } + } AVBInfo.parseFrom(fileName).dumpDefault(fileName) } @@ -60,8 +61,8 @@ class VBMetaParser: IPackable { super.pull(fileName, deviceName) } - fun clean(fileName: String) { - super.cleanUp() + fun clear(fileName: String) { + super.clear() listOf("", ".signed").forEach { "$fileName$it".deleteIfExists() } diff --git a/bbootimg/src/main/kotlin/packable/VendorBootParser.kt b/bbootimg/src/main/kotlin/packable/VendorBootParser.kt index 94ea8fc..07d8a90 100644 --- a/bbootimg/src/main/kotlin/packable/VendorBootParser.kt +++ b/bbootimg/src/main/kotlin/packable/VendorBootParser.kt @@ -28,7 +28,7 @@ class VendorBootParser : IPackable { } override fun unpack(fileName: String) { - cleanUp() + clear() val vb = VendorBoot .parse(fileName) .extractImages() @@ -55,12 +55,12 @@ class VendorBootParser : IPackable { super.pull(fileName, deviceName) } - fun clean(fileName: String) { - super.cleanUp() + fun clear(fileName: String) { + super.clear() listOf("", ".clear", ".google", ".clear", ".signed", ".signed2").forEach { "$fileName$it".deleteIfExists() } - VBMetaParser().clean("vbmeta.img") + VBMetaParser().clear("vbmeta.img") } override fun flash(fileName: String, deviceName: String) { diff --git a/bbootimg/src/main/kotlin/utils/SparseImgParser.kt b/bbootimg/src/main/kotlin/utils/SparseImgParser.kt index acd2800..4c125cf 100644 --- a/bbootimg/src/main/kotlin/utils/SparseImgParser.kt +++ b/bbootimg/src/main/kotlin/utils/SparseImgParser.kt @@ -40,7 +40,7 @@ class SparseImgParser : IPackable { } override fun unpack(fileName: String) { - cleanUp() + clear() simg2img(fileName, "$fileName.unsparse") } diff --git a/build.gradle.kts b/build.gradle.kts index 67b6112..e133f36 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -73,15 +73,15 @@ tasks { } pullTask.dependsOn("bbootimg:jar") - val cleanTask by register("clean", JavaExec::class) { + val clearTask by register("clear", JavaExec::class) { group = GROUP_ANDROID main = "cfig.packable.PackableLauncherKt" classpath = files("bbootimg/build/libs/bbootimg.jar") this.maxHeapSize = "512m" enableAssertions = true - args("clean") + args("clear") } - cleanTask.dependsOn("bbootimg:jar") + clearTask.dependsOn("bbootimg:jar") //sparse image dependencies if (bHackingMode) { diff --git a/integrationTest.py b/integrationTest.py index e2f1ecb..c682633 100755 --- a/integrationTest.py +++ b/integrationTest.py @@ -25,15 +25,19 @@ def hashFile(fileName): return hasher.hexdigest() def deleteIfExists(inFile): - for i in range(3): - try: - if os.path.isfile(inFile): - log.info("rm %s" % inFile) - os.remove(inFile) - return - except Exception as e: - log.warning("Exception in cleaning up %s" % inFile) - time.sleep(3) + if os.path.isfile(inFile): + log.info("rm %s" % inFile) + raise + ## do not delete + #for i in range(3): + # try: + # if os.path.isfile(inFile): + # log.info("rm %s" % inFile) + # os.remove(inFile) + # return + # except Exception as e: + # log.warning("Exception in cleaning up %s" % inFile) + # time.sleep(3) def cleanUp(): log.info("clean up ...") @@ -51,7 +55,7 @@ def cleanUp(): "vendor_boot-debug.img", "vendor_boot-debug.img.clear", "vendor_boot-debug.img.google" ]] def verifySingleJson(jsonFile, func = None): - log.info(jsonFile) + log.info("executing %s ..." % jsonFile) imgDir = os.path.dirname(jsonFile) verifyItems = json.load(open(jsonFile)) for k, v in verifyItems["copy"].items(): @@ -76,7 +80,7 @@ def verifySingleJson(jsonFile, func = None): log.info("%s : %s" % (k, v)) unittest.TestCase().assertEqual(v, hashFile(k)) try: - subprocess.check_call(gradleWrapper + " clean", shell = True) + subprocess.check_call(gradleWrapper + " clear", shell = True) except Exception as e: pass diff --git a/src/integrationTest/resources b/src/integrationTest/resources index 3714e20..e228732 160000 --- a/src/integrationTest/resources +++ b/src/integrationTest/resources @@ -1 +1 @@ -Subproject commit 3714e200116ea12cf4d1d462d443177ecc21222a +Subproject commit e22873286ef13ebaf60d39dd51405cb6825cef97