You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
168 lines
5.2 KiB
Groovy
168 lines
5.2 KiB
Groovy
apply plugin: "java"
|
|
|
|
buildscript {
|
|
repositories {
|
|
jcenter()
|
|
}
|
|
dependencies {
|
|
classpath "org.apache.commons:commons-exec:1.3"
|
|
}
|
|
}
|
|
|
|
subprojects {
|
|
tasks.withType(JavaCompile) {
|
|
//options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
|
|
}
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// global
|
|
// ----------------------------------------------------------------------------
|
|
import java.util.regex.Matcher
|
|
import java.util.regex.Pattern
|
|
import org.apache.commons.exec.CommandLine
|
|
import org.apache.commons.exec.DefaultExecutor
|
|
import org.apache.commons.exec.PumpStreamHandler
|
|
|
|
if (parseGradleVersion(gradle.gradleVersion) < 5) {
|
|
logger.error("ERROR: Gradle Version MUST >= 5.0, current is {}", gradle.gradleVersion)
|
|
throw new RuntimeException("ERROR: Gradle Version")
|
|
} else {
|
|
logger.info("Gradle Version {}", gradle.gradleVersion)
|
|
}
|
|
|
|
def GROUP_ANDROID = "Android"
|
|
project.ext.bootSigner = new File("boot_signer/build/libs/boot_signer.jar").getAbsolutePath()
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// tasks
|
|
// ----------------------------------------------------------------------------
|
|
task _setup(type: Copy) {
|
|
group GROUP_ANDROID
|
|
from 'src/test/resources/boot.img'
|
|
into '.'
|
|
}
|
|
|
|
task pull() {
|
|
group GROUP_ANDROID
|
|
doFirst {
|
|
println("Pulling ...")
|
|
}
|
|
|
|
doLast {
|
|
String avb_version = adbCmd("getprop ro.boot.avb_version2")
|
|
Boolean isAvbEnabled = false
|
|
if (avb_version.isEmpty()) {
|
|
isAvbEnabled = true
|
|
}
|
|
println("AVB: $isAvbEnabled")
|
|
if (project.findProperty("group")) {
|
|
println("Pull: $group")
|
|
} else {
|
|
println("Pull /boot, /recovery, /vbmeta")
|
|
pullDefault(isAvbEnabled)
|
|
}
|
|
}
|
|
}
|
|
|
|
void pullDefault(Boolean avb = true) {
|
|
Run(["adb", "shell", "dd if=/dev/block/by-name/boot of=/cache/boot.img"])
|
|
Run(["adb", "shell", "dd if=/dev/block/by-name/recovery of=/cache/recovery.img"])
|
|
if (avb) Run(["adb", "shell", "dd if=/dev/block/by-name/vbmeta of=/cache/vbmeta.img"])
|
|
|
|
Run(["adb", "pull", "/cache/boot.img"])
|
|
Run(["adb", "pull", "/cache/recovery.img"])
|
|
if (avb) Run(["adb", "pull", "/cache/vbmeta.img"])
|
|
|
|
Run(["adb", "shell", "rm /cache/boot.img"])
|
|
Run(["adb", "shell", "rm /cache/recovery.img"])
|
|
if (avb) Run(["adb", "shell", "rm /cache/vbmeta.img"])
|
|
}
|
|
|
|
void Run(List<String> inCmd, String inWorkdir = null) {
|
|
println("CMD:" + inCmd)
|
|
if (inWorkdir == null) {
|
|
inWorkdir = ".";
|
|
}
|
|
ProcessBuilder pb = new ProcessBuilder(inCmd)
|
|
.directory(new File(inWorkdir))
|
|
.redirectErrorStream(true);
|
|
Process p = pb.start()
|
|
p.inputStream.eachLine { println it }
|
|
p.waitFor();
|
|
assert 0 == p.exitValue()
|
|
}
|
|
|
|
void Run(String inCmd, String inWorkdir = null) {
|
|
Run(Arrays.asList(inCmd.split()), inWorkdir);
|
|
}
|
|
|
|
void rebootRecovery() {
|
|
Run("adb reboot recovery")
|
|
}
|
|
|
|
task rr {
|
|
group GROUP_ANDROID
|
|
doLast {
|
|
rebootRecovery()
|
|
}
|
|
}
|
|
|
|
task unpack(type: JavaExec, dependsOn: ["bbootimg:jar"]) {
|
|
group GROUP_ANDROID
|
|
main = "cfig.packable.PackableLauncherKt"
|
|
classpath = files("bbootimg/build/libs/bbootimg.jar")
|
|
maxHeapSize '512m'
|
|
args "unpack"
|
|
}
|
|
|
|
task pack(type: JavaExec, dependsOn: ["bbootimg:jar", "aosp:boot_signer:build"]) {
|
|
group GROUP_ANDROID
|
|
main = "cfig.packable.PackableLauncherKt"
|
|
classpath = files("bbootimg/build/libs/bbootimg.jar")
|
|
maxHeapSize '512m'
|
|
args "pack"
|
|
}
|
|
|
|
task flash(type: JavaExec, dependsOn: ["bbootimg:jar"]) {
|
|
group GROUP_ANDROID
|
|
main = "cfig.packable.PackableLauncherKt"
|
|
classpath = files("bbootimg/build/libs/bbootimg.jar")
|
|
maxHeapSize '512m'
|
|
args "flash"
|
|
}
|
|
|
|
//sparse image dependencies
|
|
if (System.getProperty("os.name").contains("Mac")) {
|
|
unpack.dependsOn("aosp:libsparse:simg2img:installReleaseMacos")
|
|
pack.dependsOn("aosp:libsparse:img2simg:installReleaseMacos")
|
|
pack.dependsOn("aosp:mkbootfs:installReleaseMacos")
|
|
} else {
|
|
unpack.dependsOn("aosp:libsparse:simg2img:installReleaseLinux")
|
|
pack.dependsOn("aosp:libsparse:img2simg:installReleaseLinux")
|
|
pack.dependsOn("aosp:mkbootfs:installReleaseLinux")
|
|
}
|
|
|
|
int parseGradleVersion(String version) {
|
|
Pattern VERSION_PATTERN = Pattern.compile("((\\d+)(\\.\\d+)+)(-(\\p{Alpha}+)-(\\w+))?(-(SNAPSHOT|\\d{14}([-+]\\d{4})?))?")
|
|
Matcher matcher = VERSION_PATTERN.matcher(version)
|
|
if (!matcher.matches()) {
|
|
throw new IllegalArgumentException(format("'%s' is not a valid Gradle version string (examples: '1.0', '1.0-rc-1')", version))
|
|
}
|
|
String versionPart = matcher.group(1)
|
|
int majorPart = Integer.parseInt(matcher.group(2), 10)
|
|
logger.info("Gradle: versionPart {}, majorPart {}", versionPart, majorPart)
|
|
return majorPart
|
|
}
|
|
|
|
String adbCmd(String cmd) {
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()
|
|
def exec = new DefaultExecutor()
|
|
exec.streamHandler = new PumpStreamHandler(outputStream)
|
|
def cmdline = "adb shell $cmd"
|
|
//println(cmdline)
|
|
exec.execute(CommandLine.parse(cmdline))
|
|
//println(outputStream)
|
|
return outputStream.toString().trim()
|
|
}
|