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>
<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>
<summary>working with boot.img and vbmeta.img</summary>

@ -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 {

@ -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 ""

@ -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 {

@ -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")
}
}

@ -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) {

@ -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()
}

@ -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) {

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

@ -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) {

@ -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

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