Issue #87: refine "clear" task

Please use "gradle clear" instead of "gradle clean".
pull/94/head
cfig 3 years ago
parent 2d8c39b797
commit 3df4ec6fc1
No known key found for this signature in database
GPG Key ID: B104C307F0FDABB7

@ -129,6 +129,16 @@ cp <your_vbmeta_image> vbmeta.img
</details> </details>
<details>
<summary>clean workspace</summary>
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
```
</details>
<details> <details>
<summary>working with boot.img and vbmeta.img</summary> <summary>working with boot.img and vbmeta.img</summary>

@ -35,7 +35,7 @@ class BootImgParser : IPackable {
} }
override fun unpack(fileName: String) { override fun unpack(fileName: String) {
cleanUp() clear()
val hv = probeHeaderVersion(fileName) val hv = probeHeaderVersion(fileName)
log.info("header version $hv") log.info("header version $hv")
when (hv) { when (hv) {
@ -126,12 +126,12 @@ class BootImgParser : IPackable {
super.pull(fileName, deviceName) super.pull(fileName, deviceName)
} }
fun clean(fileName: String) { fun clear(fileName: String) {
super.cleanUp() super.clear()
listOf("", ".clear", ".google", ".clear", ".signed", ".signed2").forEach { listOf("", ".clear", ".google", ".clear", ".signed", ".signed2").forEach {
"$fileName$it".deleteIfExists() "$fileName$it".deleteIfExists()
} }
VBMetaParser().clean("vbmeta.img") VBMetaParser().clear("vbmeta.img")
} }
companion object { companion object {

@ -42,7 +42,7 @@ class DtboParser(val workDir: File) : IPackable {
} }
override fun unpack(fileName: String) { override fun unpack(fileName: String) {
cleanUp() clear()
Dtbo.parse(fileName) Dtbo.parse(fileName)
.unpack(outDir) .unpack(outDir)
.extractVBMeta() .extractVBMeta()
@ -61,12 +61,12 @@ class DtboParser(val workDir: File) : IPackable {
super.`@verify`(fileName) super.`@verify`(fileName)
} }
fun clean(fileName: String) { fun clear(fileName: String) {
super.cleanUp() super.clear()
listOf("", ".clear", ".google", ".clear", ".signed", ".signed2").forEach { listOf("", ".clear", ".google", ".clear", ".signed", ".signed2").forEach {
"$fileName$it".deleteIfExists() "$fileName$it".deleteIfExists()
} }
VBMetaParser().clean("vbmeta.img") VBMetaParser().clear("vbmeta.img")
} }
private fun execInDirectory(cmd: CommandLine, inWorkDir: File) { private fun execInDirectory(cmd: CommandLine, inWorkDir: File) {
@ -108,7 +108,7 @@ class DtboParser(val workDir: File) : IPackable {
@Deprecated("for debugging purpose only") @Deprecated("for debugging purpose only")
fun unpackLegacy(fileName: String) { fun unpackLegacy(fileName: String) {
cleanUp() clear()
val dtbPath = File("$outDir/dtb").path val dtbPath = File("$outDir/dtb").path
val headerPath = File("$outDir/dtbo.header").path val headerPath = File("$outDir/dtbo.header").path
val cmdPrefix = if (EnvironmentVerifier().isWindows) "python " else "" val cmdPrefix = if (EnvironmentVerifier().isWindows) "python " else ""

@ -19,6 +19,7 @@ import cfig.Avb
import cfig.helper.Helper import cfig.helper.Helper
import cfig.helper.Helper.Companion.check_call import cfig.helper.Helper.Companion.check_call
import cfig.helper.Helper.Companion.check_output import cfig.helper.Helper.Companion.check_output
import cfig.helper.Helper.Companion.deleteIfExists
import org.slf4j.Logger import org.slf4j.Logger
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import java.io.File import java.io.File
@ -70,10 +71,14 @@ interface IPackable {
Avb().verify(ai, fileName) Avb().verify(ai, fileName)
} }
fun cleanUp() { fun clear() {
val workDir = Helper.prop("workDir") 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() File(workDir).mkdirs()
"uiderrors".deleteIfExists()
} }
companion object { companion object {

@ -14,13 +14,12 @@
package cfig.packable package cfig.packable
import cc.cfig.io.Struct import cfig.helper.Helper
import miscimg.MiscImage import miscimg.MiscImage
import cfig.helper.Helper.Companion.deleteIfExists import cfig.helper.Helper.Companion.deleteIfExists
import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.ObjectMapper
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import java.io.File import java.io.File
import java.io.FileOutputStream
import java.io.RandomAccessFile import java.io.RandomAccessFile
class MiscImgParser : IPackable { class MiscImgParser : IPackable {
@ -31,23 +30,22 @@ class MiscImgParser : IPackable {
return listOf("^misc\\.img$") return listOf("^misc\\.img$")
} }
private fun getOutputFile(fileName: String): File {
return File(workDir + "/" + File(fileName).name.removeSuffix(".img") + ".json")
}
override fun unpack(fileName: String) { override fun unpack(fileName: String) {
cleanUp() clear()
val misc = MiscImage.parse(fileName) val misc = MiscImage.parse(fileName)
log.info(misc.toString()) log.info(misc.toString())
ObjectMapper().writerWithDefaultPrettyPrinter().writeValue(getOutputFile(fileName), misc)
ObjectMapper().writerWithDefaultPrettyPrinter() ObjectMapper().writerWithDefaultPrettyPrinter()
.writeValue(File(File(fileName).name.removeSuffix(".img") + ".json"), misc) .writeValue(getOutputFile("sample.img"), MiscImage.BootloaderMessage.generateSamples())
ObjectMapper().writerWithDefaultPrettyPrinter().writeValue( log.info(getOutputFile(fileName).path + " is ready")
File("sample.json"),
MiscImage.BootloaderMessage.generateSamples()
)
} }
override fun pack(fileName: String) { override fun pack(fileName: String) {
val misc = ObjectMapper().readValue( val misc = ObjectMapper().readValue(getOutputFile(fileName), MiscImage::class.java)
File(File(fileName).name.removeSuffix(".img") + ".json"),
MiscImage::class.java
)
val out = File("$fileName.new") val out = File("$fileName.new")
File(fileName).copyTo(out, true) File(fileName).copyTo(out, true)
RandomAccessFile(out.name, "rw").use { raf -> RandomAccessFile(out.name, "rw").use { raf ->
@ -73,15 +71,15 @@ class MiscImgParser : IPackable {
super.pull(fileName, deviceName) super.pull(fileName, deviceName)
} }
fun clean(fileName: String) { fun clear(fileName: String) {
super.cleanUp() super.clear()
listOf("", ".clear", ".google", ".clear", ".signed", ".signed2").forEach { listOf("", ".new").forEach {
"$fileName$it".deleteIfExists() "$fileName$it".deleteIfExists()
} }
VBMetaParser().clean("vbmeta.img")
} }
companion object { companion object {
private val log = LoggerFactory.getLogger(MiscImgParser::class.java) private val log = LoggerFactory.getLogger(MiscImgParser::class.java)
private val workDir = Helper.prop("workDir")
} }
} }

@ -25,7 +25,7 @@ class PayloadBinParser : IPackable {
} }
override fun unpack(fileName: String) { override fun unpack(fileName: String) {
cleanUp() clear()
Payload.parse(fileName).let { pl -> Payload.parse(fileName).let { pl ->
pl.setUp() pl.setUp()
pl.printInfo() pl.printInfo()
@ -44,7 +44,7 @@ class PayloadBinParser : IPackable {
super.pull(fileName, deviceName) super.pull(fileName, deviceName)
} }
fun clean(fileName: String) { fun clear(fileName: String) {
} }
override fun flash(fileName: String, deviceName: String) { override fun flash(fileName: String, deviceName: String) {

@ -16,6 +16,7 @@ package cfig.packable
import avb.AVBInfo import avb.AVBInfo
import cfig.Avb import cfig.Avb
import cfig.helper.Helper
import cfig.helper.Helper.Companion.deleteIfExists import cfig.helper.Helper.Companion.deleteIfExists
import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.ObjectMapper
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
@ -24,7 +25,7 @@ import java.nio.file.Files
import java.nio.file.Paths import java.nio.file.Paths
import java.nio.file.StandardOpenOption import java.nio.file.StandardOpenOption
class VBMetaParser: IPackable { class VBMetaParser : IPackable {
override val loopNo: Int override val loopNo: Int
get() = 1 get() = 1
@ -32,12 +33,12 @@ class VBMetaParser: IPackable {
return listOf("^vbmeta\\.img$", "^vbmeta\\_[a-z]+.img$") return listOf("^vbmeta\\.img$", "^vbmeta\\_[a-z]+.img$")
} }
override fun cleanUp() {
File(outDir).mkdirs()
}
override fun unpack(fileName: String) { override fun unpack(fileName: String) {
cleanUp() File(Helper.prop("workDir")).let {
if (!it.exists()) {
it.mkdirs()
}
}
AVBInfo.parseFrom(fileName).dumpDefault(fileName) AVBInfo.parseFrom(fileName).dumpDefault(fileName)
} }
@ -60,8 +61,8 @@ class VBMetaParser: IPackable {
super.pull(fileName, deviceName) super.pull(fileName, deviceName)
} }
fun clean(fileName: String) { fun clear(fileName: String) {
super.cleanUp() super.clear()
listOf("", ".signed").forEach { listOf("", ".signed").forEach {
"$fileName$it".deleteIfExists() "$fileName$it".deleteIfExists()
} }

@ -28,7 +28,7 @@ class VendorBootParser : IPackable {
} }
override fun unpack(fileName: String) { override fun unpack(fileName: String) {
cleanUp() clear()
val vb = VendorBoot val vb = VendorBoot
.parse(fileName) .parse(fileName)
.extractImages() .extractImages()
@ -55,12 +55,12 @@ class VendorBootParser : IPackable {
super.pull(fileName, deviceName) super.pull(fileName, deviceName)
} }
fun clean(fileName: String) { fun clear(fileName: String) {
super.cleanUp() super.clear()
listOf("", ".clear", ".google", ".clear", ".signed", ".signed2").forEach { listOf("", ".clear", ".google", ".clear", ".signed", ".signed2").forEach {
"$fileName$it".deleteIfExists() "$fileName$it".deleteIfExists()
} }
VBMetaParser().clean("vbmeta.img") VBMetaParser().clear("vbmeta.img")
} }
override fun flash(fileName: String, deviceName: String) { override fun flash(fileName: String, deviceName: String) {

@ -40,7 +40,7 @@ class SparseImgParser : IPackable {
} }
override fun unpack(fileName: String) { override fun unpack(fileName: String) {
cleanUp() clear()
simg2img(fileName, "$fileName.unsparse") simg2img(fileName, "$fileName.unsparse")
} }

@ -73,15 +73,15 @@ tasks {
} }
pullTask.dependsOn("bbootimg:jar") pullTask.dependsOn("bbootimg:jar")
val cleanTask by register("clean", JavaExec::class) { val clearTask by register("clear", JavaExec::class) {
group = GROUP_ANDROID group = GROUP_ANDROID
main = "cfig.packable.PackableLauncherKt" main = "cfig.packable.PackableLauncherKt"
classpath = files("bbootimg/build/libs/bbootimg.jar") classpath = files("bbootimg/build/libs/bbootimg.jar")
this.maxHeapSize = "512m" this.maxHeapSize = "512m"
enableAssertions = true enableAssertions = true
args("clean") args("clear")
} }
cleanTask.dependsOn("bbootimg:jar") clearTask.dependsOn("bbootimg:jar")
//sparse image dependencies //sparse image dependencies
if (bHackingMode) { if (bHackingMode) {

@ -25,15 +25,19 @@ def hashFile(fileName):
return hasher.hexdigest() return hasher.hexdigest()
def deleteIfExists(inFile): def deleteIfExists(inFile):
for i in range(3): if os.path.isfile(inFile):
try: log.info("rm %s" % inFile)
if os.path.isfile(inFile): raise
log.info("rm %s" % inFile) ## do not delete
os.remove(inFile) #for i in range(3):
return # try:
except Exception as e: # if os.path.isfile(inFile):
log.warning("Exception in cleaning up %s" % inFile) # log.info("rm %s" % inFile)
time.sleep(3) # os.remove(inFile)
# return
# except Exception as e:
# log.warning("Exception in cleaning up %s" % inFile)
# time.sleep(3)
def cleanUp(): def cleanUp():
log.info("clean up ...") log.info("clean up ...")
@ -51,7 +55,7 @@ def cleanUp():
"vendor_boot-debug.img", "vendor_boot-debug.img.clear", "vendor_boot-debug.img.google" ]] "vendor_boot-debug.img", "vendor_boot-debug.img.clear", "vendor_boot-debug.img.google" ]]
def verifySingleJson(jsonFile, func = None): def verifySingleJson(jsonFile, func = None):
log.info(jsonFile) log.info("executing %s ..." % jsonFile)
imgDir = os.path.dirname(jsonFile) imgDir = os.path.dirname(jsonFile)
verifyItems = json.load(open(jsonFile)) verifyItems = json.load(open(jsonFile))
for k, v in verifyItems["copy"].items(): for k, v in verifyItems["copy"].items():
@ -76,7 +80,7 @@ def verifySingleJson(jsonFile, func = None):
log.info("%s : %s" % (k, v)) log.info("%s : %s" % (k, v))
unittest.TestCase().assertEqual(v, hashFile(k)) unittest.TestCase().assertEqual(v, hashFile(k))
try: try:
subprocess.check_call(gradleWrapper + " clean", shell = True) subprocess.check_call(gradleWrapper + " clear", shell = True)
except Exception as e: except Exception as e:
pass pass

@ -1 +1 @@
Subproject commit 3714e200116ea12cf4d1d462d443177ecc21222a Subproject commit e22873286ef13ebaf60d39dd51405cb6825cef97
Loading…
Cancel
Save