Skip to content

Commit

Permalink
Merge pull request #485 from kennethshackleton/gradle-layout-idiom
Browse files Browse the repository at this point in the history
Idiomatic use of layout.buildDirectory.
  • Loading branch information
kennethshackleton authored Nov 17, 2023
2 parents 86a9e9b + 48c2c2f commit 522ba78
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
43 changes: 22 additions & 21 deletions OpenSSL/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@ plugins {
id("de.undercouch.download") version Versions.GRADLE_DOWNLOAD_TASK_PLUGIN.version
}

fun Project.openSslVersion() = arrayOf(
"${property("openssl.version")}",
"${property("openssl.version.suffix")}"
).joinToString("")
fun Project.openSslVersion() = property("openssl.version").toString()

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 +60,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 +75,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/${get().asFile.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 +97,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/${get().asFile.name.substringBefore(".tar.gz")}")
}.get().asFile.path,
it,
21
)
Expand All @@ -130,12 +128,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 All @@ -144,24 +142,26 @@ tasks.register<Exec>("configureHost") {
dependsOn("unpackOpenSslHost")
inputs.property("target", targetIdentifier())
inputs.property("version", openSslVersion())
workingDir(openSslWorkingDir)
val openSslWorkingDir = openSslWorkingDir.get().asFile
outputs.files("$openSslWorkingDir/Makefile", "$openSslWorkingDir/configdata.pm")
.withPropertyName("configure")
outputs.cacheIf { false } // TODO Restore me.
workingDir(openSslWorkingDir)
commandLine("./config")
}

tasks.register<Exec>("makeHost") {
dependsOn("configureHost")
inputs.property("target", targetIdentifier())
inputs.property("version", openSslVersion())
workingDir(openSslWorkingDir)
val openSslWorkingDir = openSslWorkingDir.get().asFile
arrayOf(".a").forEach {
outputs.files("$openSslWorkingDir/libcrypto$it")
.withPropertyName("libcrypto$it")
}
outputs.files(fileTree("$openSslWorkingDir/include") { include("**/*.h") })
.withPropertyName("headers")
workingDir(openSslWorkingDir)
outputs.cacheIf { false } // TODO Restore me.
commandLine("make")
args("build_libs")
Expand All @@ -172,9 +172,10 @@ 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.
val openSslWorkingDir = openSslWorkingDir.get().asFile
from(fileTree(openSslWorkingDir) {
arrayOf(".a").forEach { e ->
include("**/libcrypto$e")
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
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ selekt.versionName=0.21.0
selekt.nextVersionName=0.22.0

openssl.version=3.1.2
openssl.version.suffix=
openssl.sha256=a0ce69b8b97ea6a35b96875235aa453b966ba3cba8af2de23657d8b6767d6539
openssl.pgp.sha256=0c14b85a86966752f1cdc2a3306497010d5fb9d405070b64cbb201d7ad1eb61a

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 522ba78

Please sign in to comment.