Skip to content

Commit

Permalink
Merge pull request #1064 from mozilla/fix-native-libs-plugin
Browse files Browse the repository at this point in the history
NativeLibsPlugin should use the downloaded libs (/build/libs), not the libs from /libs [ci full]
  • Loading branch information
thomcc authored Apr 24, 2019
2 parents 8f0cb16 + 7ad46c9 commit 8d28d68
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 42 deletions.
77 changes: 40 additions & 37 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,43 +58,6 @@ allprojects {
}
}

subprojects {
apply plugin: 'digital.wup.android-maven-publish'

// This allows to invoke Gradle like `./gradlew publishToRootProjectBuildDir` (equivalent to
// `./gradlew publish`) and also `./gradlew publishToProjectBuildDir`.
publishing {
repositories {
maven {
name = "rootProjectBuildDir"
url "file://${project.rootProject.buildDir}/maven"
}
maven {
name = "projectBuildDir"
url "file://${project.buildDir}/maven"
}
}
}

apply plugin: NativeLibsPlugin
nativeLibs {
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.*"
}
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
Expand Down Expand Up @@ -246,6 +209,46 @@ switch (DefaultPlatform.RESOURCE_PREFIX) {
// downloaded libs.
def libsRootDir = (System.getenv('CI') || ext.libsGitSha == null) ? rootProject.rootDir : rootProject.buildDir

subprojects {
apply plugin: 'digital.wup.android-maven-publish'

// This allows to invoke Gradle like `./gradlew publishToRootProjectBuildDir` (equivalent to
// `./gradlew publish`) and also `./gradlew publishToProjectBuildDir`.
publishing {
repositories {
maven {
name = "rootProjectBuildDir"
url "file://${project.rootProject.buildDir}/maven"
}
maven {
name = "projectBuildDir"
url "file://${project.buildDir}/maven"
}
}
}

apply plugin: NativeLibsPlugin
nativeLibs {
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.*"
}
}
}
}

// Configure some environment variables, per toolchain, that will apply during
// the Cargo build. We assume that the `libs/` directory has been populated
// before invoking Gradle (or Cargo).
Expand Down
24 changes: 19 additions & 5 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 @@ -57,11 +61,21 @@ data class NativeLib(
}
}

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
Expand All @@ -70,7 +84,7 @@ open class NativeLibsPlugin : Plugin<Project> {
ARCHS_FOLDERS.forEach { archFolder ->
val taskName = archFolder.replace("/", "-")
val copyLibsTask = tasks.maybeCreate("copyNativeLibs-$taskName", Copy::class.java).apply {
from("${rootProject.rootDir}/libs/$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 8d28d68

Please sign in to comment.