diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2024-09-25 21:12:24 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2024-09-25 21:12:24 +0200 |
| commit | 28a55fdc69e31490a4086ecae8cc687f40ba0b94 (patch) | |
| tree | 9bde6e49eb091f912e8a9f8b2853d87f6a932d27 /libs/sftp/build.gradle.kts | |
| parent | 07d35782b377a8b98cf8dbbb5734d3f2514bccd5 (diff) | |
Add libs:sftp
sftp implementation using libssh2 and openssl
Diffstat (limited to 'libs/sftp/build.gradle.kts')
| -rw-r--r-- | libs/sftp/build.gradle.kts | 205 |
1 files changed, 205 insertions, 0 deletions
diff --git a/libs/sftp/build.gradle.kts b/libs/sftp/build.gradle.kts new file mode 100644 index 0000000..4ccac9c --- /dev/null +++ b/libs/sftp/build.gradle.kts @@ -0,0 +1,205 @@ +plugins { + alias(libs.plugins.android.library) +} + +val shareDir = layout.buildDirectory.dir("test-share") +val dockerDir = layout.projectDirectory.dir("src/test/docker") + +val openssl = layout.projectDirectory.dir("openssl") +val opensslBaseBuildDir = layout.buildDirectory.dir("openssl") + +android { + namespace = "org.the_jk.cleversync.sftp" + + externalNativeBuild { + cmake { + path("CMakeLists.txt") + } + } + + defaultConfig { + externalNativeBuild { + cmake { + // Need both source and build include, CMakeLists.txt sets up build + // so add source here. + cFlags += listOf("-I${openssl.dir("include")}") + targets("sftpjni") + arguments("-DOPENSSL_BUILD_DIR=${opensslBaseBuildDir.get()}") + } + } + } + + buildTypes { + debug { + externalNativeBuild { + cmake { + cFlags += listOf("-g") + } + } + } + release { + externalNativeBuild { + cmake { + cFlags += listOf("-O3") + } + } + } + } + + testOptions { + unitTests { + all { test -> + test.doFirst { + shareDir.get().asFile.mkdirs() + } + + test.systemProperty("dockerDir", dockerDir.toString()) + test.systemProperty("shareDir", shareDir.get().toString()) + } + } + } +} + +dependencies { + implementation(project(":libs:io")) + testImplementation(project(":libs:utils")) + testImplementation(project(":libs:test-utils")) +} + +listOf("armeabi-v7a", "arm64-v8a", "x86", "x86_64").forEach { arch -> + val buildDir = opensslBaseBuildDir.map { it.dir(arch) } + + val configure by tasks.register<Exec>( + "configureOpenssl[${arch}]" + ) { + doFirst { + buildDir.get().asFile.mkdirs() + } + + onlyIf { + !buildDir.get().file("configdata.pm").asFile.exists() + } + + environment( + "ANDROID_NDK_ROOT" to android.ndkDirectory.toString(), + "PATH" to "${android.ndkDirectory}/toolchains/llvm/prebuilt/linux-x86_64/bin:${System.getenv("PATH")}", + ) + workingDir = buildDir.get().asFile + executable = openssl.file("Configure").asFile.toString() + args( + when (arch) { + "armeabi-v7a" -> "android-arm" + "arm64-v8a" -> "android-arm64" + "x86" -> "android-x86" + "x86_64" -> "android-x86_64" + else -> "" + }, + ) + } + + val build by tasks.register<Exec>( + "buildOpenssl[${arch}]" + ) { + dependsOn(configure) + environment( + "ANDROID_NDK_ROOT" to android.ndkDirectory.toString(), + "PATH" to "${android.ndkDirectory}/toolchains/llvm/prebuilt/linux-x86_64/bin:${System.getenv("PATH")}", + ) + workingDir = buildDir.get().asFile + executable = "make" + args( + listOf( + "-j", + Runtime.getRuntime().availableProcessors() - 1, + "--quiet", + ) + ) + } + + tasks.named { + it == "configureCMakeDebug[$arch]" || + it == "configureCMakeWithDebInfo[$arch]" + }.configureEach { + dependsOn(build) + } +} + +val buildDirHostSsl = opensslBaseBuildDir.map { it.dir("host") } + +val configureHostSsl by tasks.register<Exec>( + "configureOpenssl[host]" +) { + doFirst { + buildDirHostSsl.get().asFile.mkdirs() + } + + onlyIf { + !buildDirHostSsl.get().file("configdata.pm").asFile.exists() + } + + workingDir = buildDirHostSsl.get().asFile + executable = openssl.file("Configure").asFile.toString() +} + +val buildHostSsl by tasks.register<Exec>( + "buildOpenssl[host]" +) { + dependsOn(configureHostSsl) + workingDir = buildDirHostSsl.get().asFile + executable = "make" + args( + listOf( + "-j", + Runtime.getRuntime().availableProcessors() - 1, + "--quiet", + ) + ) +} + +listOf("Debug", "Release").forEach { buildType -> + val buildDir = project.layout.buildDirectory.dir("test-cpp/$buildType/build") + + val configure by tasks.register( + "configureLibsFor${buildType}UnitTest", + Exec::class + ) { + dependsOn(buildHostSsl) + + environment( + "CFLAGS" to "-I${openssl.dir("include")}", + ) + args( + "-S", + project.layout.projectDirectory.dir("."), + "-B", + buildDir.get(), + "-DOPENSSL_BUILD_DIR=${opensslBaseBuildDir.get()}", + ) + executable = "cmake" + } + + val compile by tasks.register( + "compileLibsFor${buildType}UnitTest", + Exec::class + ) { + dependsOn(configure) + args( + "--build", buildDir.get(), + "--target", "sftpjni", + ) + executable = "cmake" + } + + val copy by tasks.register( + "copyLibsFor${buildType}UnitTest", + Copy::class + ) { + dependsOn(compile) + from(buildDir.map { it.file("libsftpjni.so") }) + into(project.layout.projectDirectory.dir("src/test${buildType}/jniLibs")) + } + + tasks.matching { it.name == "test${buildType}UnitTest" }.all { + dependsOn(copy) + } +} |
