move checkDexer out of build.gradle to an own script file

This commit is contained in:
Robert Stoll
2020-05-25 23:28:48 +02:00
parent 72e8d38260
commit 371c19d71f
2 changed files with 86 additions and 84 deletions

View File

@@ -335,6 +335,7 @@ configure(subprojects - sampleProjects - toolProjects) {
}
apply from: 'gradle/scripts/check-dexer.gradle'
apply from: 'gradle/scripts/gh-pages.gradle'
apply from: 'gradle/scripts/jacoco-multi-project.gradle'
@@ -528,90 +529,6 @@ configure(subprojects - getJsProjects()) { subproject ->
}
}
def preCheck_ATRIUM_ANDROID_JAR = task('preCheck_ATRIUM_ANDROID_JAR') {
doFirst {
if (System.getenv('ATRIUM_ANDROID_JAR') == null) {
throw new InvalidUserDataException("env variable ATRIUM_ANDROID_JAR not set. Point it to the android SDK android.jar path (e.g. /android-sdk-linux/platforms/android-26/android.jar")
}
println("Using android.jar defined at: ${System.getenv('ATRIUM_ANDROID_JAR')}")
}
}
def dexerProjects = jvmProjects.findAll {
!it.name.contains("-specs-")
}
configure(dexerProjects) { subproject ->
configurations {
r8
d8
}
repositories {
google()
}
dependencies {
r8 "com.android.tools:r8:$d8_version"
d8 subproject
}
afterEvaluate {
task('checkDexer', type: JavaExec, description: 'compiles android class files into dex bytecode') {
inputs.property 'ATRIUM_ANDROID_JAR', System.getenv('ATRIUM_ANDROID_JAR')
def outputPath = "${subproject.buildDir}/d8"
outputs.dir(outputPath)
dependsOn jar
dependsOn preCheck_ATRIUM_ANDROID_JAR
jar.mustRunAfter(preCheck_ATRIUM_ANDROID_JAR)
classpath subproject.configurations.r8.asPath
main = "com.android.tools.r8.D8"
def d8Classpath = subproject.configurations.d8.files.collect {
["--classpath", it.getAbsolutePath()]
}.flatten()
def androidJarPath = System.getenv('ATRIUM_ANDROID_JAR')
// ATRIUM_ANDROID_JAR has to point to something like /android-sdk-linux/platforms/android-XY/android.jar
// where Xy is the version we want to support
def androidJar = androidJarPath != null ? ['--lib', androidJarPath] : []
args = d8Classpath + androidJar + ['--output', outputPath, jar.archiveFile.get().asFile]
def oldStream = errorOutput
def outputWritten = false
errorOutput = new OutputStream() {
@Override
void write(int b) {
outputWritten = true
oldStream.write(b)
}
}
doLast {
if (outputWritten) {
throw new GradleException("checkDexer failed due to output, see above.")
}
}
}
}
}
def preCheckDexerProjects = task('preCheckDexerProjects', dependsOn: preCheck_ATRIUM_ANDROID_JAR) {
doFirst {
if (dexerProjects.size() == 0) {
throw new InvalidUserDataException("env variable CI not set and hence no android projects included. Use e.g. `CI=true gradlew checkDexer`")
}
}
}
task('checkDexer', description: 'executes all checkDexer tasks', dependsOn: 'preCheckDexerProjects') {
dexerProjects.forEach { subproject ->
subproject.afterEvaluate {
Task subprojectCheckDexer = subproject.tasks.getByName("checkDexer")
dependsOn subprojectCheckDexer
subprojectCheckDexer.mustRunAfter(preCheckDexerProjects)
}
}
}
/*
Release & deploy a commit

View File

@@ -0,0 +1,85 @@
def preCheck_ATRIUM_ANDROID_JAR = task('preCheck_ATRIUM_ANDROID_JAR') {
doFirst {
if (System.getenv('ATRIUM_ANDROID_JAR') == null) {
throw new InvalidUserDataException("env variable ATRIUM_ANDROID_JAR not set. Point it to the android SDK android.jar path (e.g. /android-sdk-linux/platforms/android-26/android.jar")
}
println("Using android.jar defined at: ${System.getenv('ATRIUM_ANDROID_JAR')}")
}
}
def dexerProjects = getJvmProjects().findAll {
!it.name.contains("-specs-")
}
configure(dexerProjects) { subproject ->
configurations {
r8
d8
}
repositories {
google()
}
dependencies {
r8 "com.android.tools:r8:$d8_version"
d8 subproject
}
afterEvaluate {
task('checkDexer', type: JavaExec, description: 'compiles android class files into dex bytecode') {
inputs.property 'ATRIUM_ANDROID_JAR', System.getenv('ATRIUM_ANDROID_JAR')
def outputPath = "${subproject.buildDir}/d8"
outputs.dir(outputPath)
dependsOn jar
dependsOn preCheck_ATRIUM_ANDROID_JAR
jar.mustRunAfter(preCheck_ATRIUM_ANDROID_JAR)
classpath subproject.configurations.r8.asPath
main = "com.android.tools.r8.D8"
def d8Classpath = subproject.configurations.d8.files.collect {
["--classpath", it.getAbsolutePath()]
}.flatten()
def androidJarPath = System.getenv('ATRIUM_ANDROID_JAR')
// ATRIUM_ANDROID_JAR has to point to something like /android-sdk-linux/platforms/android-XY/android.jar
// where Xy is the version we want to support
def androidJar = androidJarPath != null ? ['--lib', androidJarPath] : []
args = d8Classpath + androidJar + ['--output', outputPath, jar.archiveFile.get().asFile]
def oldStream = errorOutput
def outputWritten = false
errorOutput = new OutputStream() {
@Override
void write(int b) {
outputWritten = true
oldStream.write(b)
}
}
doLast {
if (outputWritten) {
throw new GradleException("checkDexer failed due to output, see above.")
}
}
}
}
}
def preCheckDexerProjects = task('preCheckDexerProjects', dependsOn: preCheck_ATRIUM_ANDROID_JAR) {
doFirst {
if (dexerProjects.size() == 0) {
throw new InvalidUserDataException("env variable CI not set and hence no android projects included. Use e.g. `CI=true gradlew checkDexer`")
}
}
}
task('checkDexer', description: 'executes all checkDexer tasks', dependsOn: 'preCheckDexerProjects') {
dexerProjects.forEach { subproject ->
subproject.afterEvaluate {
Task subprojectCheckDexer = subproject.tasks.getByName("checkDexer")
dependsOn subprojectCheckDexer
subprojectCheckDexer.mustRunAfter(preCheckDexerProjects)
}
}
}