Skip to content

Commit

Permalink
Idiomatic use of layout.buildDirectory.
Browse files Browse the repository at this point in the history
Signed-off-by: Kenneth J. Shackleton <[email protected]>
  • Loading branch information
kennethshackleton committed Nov 16, 2023
1 parent 86a9e9b commit 1bf75be
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
31 changes: 16 additions & 15 deletions OpenSSL/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ val openSslBaseUrl = "https://www.openssl.org/source"
fun Project.openSslUrl() = "$openSslBaseUrl/openssl-${openSslVersion()}.tar.gz"
fun Project.openSslPgpUrl() = "$openSslBaseUrl/openssl-${openSslVersion()}.tar.gz.asc"

val archive = File("${layout.buildDirectory.get()}/tmp/openssl-${openSslVersion()}.tar.gz")
val archivePgp = File("${archive.path}.asc")
val archive: Provider<RegularFile> = layout.buildDirectory.file("tmp/openssl-${openSslVersion()}.tar.gz")
val archivePgp: Provider<RegularFile> = layout.buildDirectory.file("tmp/openssl-${openSslVersion()}.tar.gz.asc")

tasks.register<Download>("downloadOpenSslPgp") {
val url = openSslPgpUrl()
Expand All @@ -63,13 +63,13 @@ tasks.register<Download>("downloadOpenSsl") {
}

tasks.register<Verify>("verifyOpenSslPgpChecksum") {
src(archivePgp)
src(archivePgp.get().asFile)
algorithm("SHA-256")
checksum("${project.property("openssl.pgp.sha256")}")
}

tasks.register<Verify>("verifyOpenSslChecksum") {
src(archive)
src(archive.get().asFile)
algorithm("SHA-256")
checksum("${project.property("openssl.sha256")}")
}
Expand All @@ -78,19 +78,19 @@ tasks.register<Exec>("verifyOpenSslSignature") {
inputs.files(archivePgp, archive)
commandLine(
"gpg", "--no-default-keyring", "--keyring", "$projectDir/openssl.gpg", "--verify",
archivePgp, archive
archivePgp.get().asFile, archive.get().asFile
)
}

fun openSslWorkingDir(target: String) = archive.run {
File("${layout.buildDirectory.get()}/generated/$target/${name.substringBefore(".tar.gz")}")
}.path
fun openSslWorkingDir(target: String): Provider<Directory> = archive.run {
layout.buildDirectory.dir("generated/$target/${name.substringBefore(".tar.gz")}")
}

arrayOf("armeabi-v7a", "arm64-v8a", "x86", "x86_64").forEach {
val titleCaseName = it.replaceFirstChar { c -> c.uppercaseChar() }
tasks.register<Copy>("unpackOpenSsl$titleCaseName") {
from(tarTree(archive))
into("${layout.buildDirectory.get()}/generated/$it")
into(layout.buildDirectory.dir("generated/$it"))
dependsOn("downloadOpenSsl")
}

Expand All @@ -100,13 +100,14 @@ arrayOf("armeabi-v7a", "arm64-v8a", "x86", "x86_64").forEach {
inputs.property("version", openSslVersion())
outputs.files(fileTree("${openSslWorkingDir(it)}/include") { include("**/*.h") })
.withPropertyName("headers")
outputs.dir("${layout.buildDirectory.get()}/libs/$it").withPropertyName("lib")
outputs.dir(layout.buildDirectory.dir("libs/$it")).withPropertyName("lib")
outputs.cacheIf { false } // TODO Restore me.
workingDir(projectDir)
commandLine("./build_libraries.sh")
args(
archive.run { File("${layout.buildDirectory.get()}/generated" +
"/$it/${name.substringBefore(".tar.gz")}") }.path,
archive.run { layout.buildDirectory.file("generated" +
"/$it/${name.substringBefore(".tar.gz")}")
}.get().asFile.path,
it,
21
)
Expand All @@ -130,12 +131,12 @@ fun osName() = System.getProperty("os.name").lowercase(Locale.US).run {

fun targetIdentifier() = "${osName()}-${System.getProperty("os.arch")}"

val openSslWorkingDir: String = openSslWorkingDir(targetIdentifier())
val openSslWorkingDir: Provider<Directory> = openSslWorkingDir(targetIdentifier())

// FIXME Some of the host building logic parallels Android's above. Re-purpose?
tasks.register<Copy>("unpackOpenSslHost") {
from(tarTree(archive))
into("${layout.buildDirectory.get()}/generated/${targetIdentifier()}")
into(layout.buildDirectory.dir("generated/${targetIdentifier()}"))
dependsOn("downloadOpenSsl")
mustRunAfter("clean")
}
Expand Down Expand Up @@ -172,7 +173,7 @@ tasks.register<Copy>("assembleHost") {
dependsOn("makeHost")
inputs.property("target", targetIdentifier())
inputs.property("version", openSslVersion())
val outputDir = "${layout.buildDirectory.get()}/libs/${targetIdentifier()}"
val outputDir = layout.buildDirectory.dir("libs/${targetIdentifier()}")
outputs.dir(outputDir).withPropertyName("libs")
outputs.cacheIf { false } // TODO Restore me.
from(fileTree(openSslWorkingDir) {
Expand Down
2 changes: 1 addition & 1 deletion Selektric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ tasks.register<Copy>("copyLibraries") {
from(fileTree(".cxx-host") {
include("**/*.dll", "**/*.dylib", "**/*.so")
})
into("${layout.buildDirectory.get()}/intermediates/libs/${platformIdentifier()}")
into(layout.buildDirectory.dir("intermediates/libs/${platformIdentifier()}"))
}

tasks.register<Delete>("deleteCxxHost") {
Expand Down
8 changes: 4 additions & 4 deletions selekt-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ android {
arrayOf("debug", "main", "release", "test").forEach {
sourceSets[it].java.srcDir("src/$it/kotlin")
}
sourceSets["test"].resources.srcDir("${layout.buildDirectory.get()}/intermediates/libs")
sourceSets["test"].resources.srcDir(layout.buildDirectory.dir("intermediates/libs"))
publishing {
singleVariant("release") {
withJavadocJar()
Expand Down Expand Up @@ -92,10 +92,10 @@ koverReport {

tasks.register<Copy>("copyJniLibs") {
from(
fileTree("${project(":selekt-sqlite3").layout.buildDirectory.get()}/intermediates/libs"),
fileTree("${project(":Selektric").layout.buildDirectory.get()}/intermediates/libs")
fileTree(project(":selekt-sqlite3").layout.buildDirectory.dir("intermediates/libs")),
fileTree(project(":Selektric").layout.buildDirectory.dir("intermediates/libs"))
)
into("${layout.buildDirectory.get()}/intermediates/libs/jni")
into(layout.buildDirectory.dir("intermediates/libs/jni"))
}

tasks.register<Task>("buildNativeHost") {
Expand Down
6 changes: 3 additions & 3 deletions selekt-java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ sourceSets {
create("integrationTest") {
compileClasspath += sourceSets.main.get().output
runtimeClasspath += sourceSets.main.get().output
resources.srcDir("${layout.buildDirectory.get()}/intermediates/libs")
resources.srcDir(layout.buildDirectory.dir("intermediates/libs"))
}
}

Expand Down Expand Up @@ -88,8 +88,8 @@ tasks.register<Task>("buildHostSQLite") {
}

tasks.register<Copy>("copyJniLibs") {
from(fileTree("${project(":selekt-sqlite3").layout.buildDirectory.get()}/intermediates/libs"))
into("${layout.buildDirectory.get()}/intermediates/libs/jni")
from(fileTree(project(":selekt-sqlite3").layout.buildDirectory.dir("intermediates/libs")))
into(layout.buildDirectory.dir("intermediates/libs/jni"))
}

tasks.withType<ProcessResources>().configureEach {
Expand Down
2 changes: 1 addition & 1 deletion selekt-sqlite3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ fun platformIdentifier() = "${osName()}-${System.getProperty("os.arch")}"
tasks.register<Copy>("buildHost") {
dependsOn("makeSQLite")
from(".cxx-host/sqlite3")
into("${layout.buildDirectory.get()}/intermediates/libs/${platformIdentifier()}")
into(layout.buildDirectory.dir("intermediates/libs/${platformIdentifier()}"))
include("*.dll", "*.dylib", "*.so")
}

Expand Down

0 comments on commit 1bf75be

Please sign in to comment.