Skip to content

Commit

Permalink
Lift libsRoot into extension
Browse files Browse the repository at this point in the history
  • Loading branch information
eoger committed Apr 23, 2019
1 parent 06e59a1 commit 7ad46c9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
30 changes: 16 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -229,20 +229,22 @@ subprojects {

apply plugin: NativeLibsPlugin
nativeLibs {
nss {
libRoot = "${libsRootDir}/libs"
lib "libplc4.*"
lib "libplds4.*"
lib "libnspr4.*"
lib "*freebl3.*"
lib "*nss3.*"
lib "*nssckbi.*"
lib "*nssutil3.*"
lib "*softokn3.*"
lib "*smime3.*"
lib "*sqlite3.*"
// We don't need SSL so we might as well save space.
// lib "libssl3.*"
libsRoot = "${libsRootDir}/libs"
libs {
nss {
lib "libplc4.*"
lib "libplds4.*"
lib "libnspr4.*"
lib "*freebl3.*"
lib "*nss3.*"
lib "*nssckbi.*"
lib "*nssutil3.*"
lib "*softokn3.*"
lib "*smime3.*"
lib "*sqlite3.*"
// We don't need SSL so we might as well save space.
// lib "libssl3.*"
}
}
}
}
Expand Down
30 changes: 21 additions & 9 deletions buildSrc/src/main/java/NativeLibsPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
* <pre>
* apply plugin: NativeLibsPlugin
* nativeLibs {
* nss {
* lib "libnss3.*" // Wildcards are supported, just like the Copy task `include` method.
* libsRoot = "${rootProject.rootDir}/libs"
* libs {
* nss {
* lib "libnss3.*" // Wildcards are supported, just like the Copy task `include` method.
* }
* }
* }
* android {
Expand All @@ -27,14 +30,15 @@
* </pre>
*/

import groovy.lang.Closure
import org.gradle.api.tasks.Copy
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
import org.gradle.api.Plugin
import org.gradle.kotlin.dsl.delegateClosureOf
// Needed to be able to call `DomainObjectCollection.all` instead of Kotlin's built-in `all` method.
import kotlin.collections.all as ktAll // ktlint-disable no-unused-imports

const val EXTENSION_NAME = "nativeLibs"
val ARCHS_FOLDERS = arrayOf(
"android/armeabi-v7a",
"android/arm64-v8a",
Expand All @@ -47,32 +51,40 @@ val ARCHS_FOLDERS = arrayOf(

data class NativeLib(
val name: String,
var libs: List<String>,
var libRoot: String?
var libs: List<String>
) {
constructor(name: String) : this(name, listOf<String>(), null)
constructor(name: String) : this(name, listOf<String>())

public fun lib(libName: String): NativeLib {
this.libs += libName
return this
}
}

const val EXTENSION_NAME = "nativeLibs"
open class NativeLibsExtension(nativeLibs: NamedDomainObjectContainer<NativeLib>) {
lateinit var libsRoot: String
val libs: NamedDomainObjectContainer<NativeLib> = nativeLibs

fun libs(config: Closure<*>) {
this.libs.configure(config)
}
}

open class NativeLibsPlugin : Plugin<Project> {
override fun apply(project: Project) {
with(project) {
val nativeLibs = container(NativeLib::class.java)
extensions.add(EXTENSION_NAME, nativeLibs)
val extension = extensions.create(EXTENSION_NAME, NativeLibsExtension::class.java, nativeLibs)

nativeLibs.all(delegateClosureOf<NativeLib>({
val nativeLib = this
val libRoot = this.libRoot ?: "${rootProject.rootDir}/build/libs"
afterEvaluate {
var copyNativeLibsTask = tasks.maybeCreate("copyNativeLibs")
ARCHS_FOLDERS.forEach { archFolder ->
val taskName = archFolder.replace("/", "-")
val copyLibsTask = tasks.maybeCreate("copyNativeLibs-$taskName", Copy::class.java).apply {
from("$libRoot/$archFolder/${nativeLib.name}/lib/")
from("${extension.libsRoot}/$archFolder/${nativeLib.name}/lib/")
into("$buildDir/nativeLibs/$archFolder")
nativeLib.libs.forEach {
include(it)
Expand Down

0 comments on commit 7ad46c9

Please sign in to comment.