Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 21 additions & 91 deletions ReactAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ plugins {
id("de.undercouch.download")
}

import com.facebook.react.tasks.internal.*

import java.nio.file.Paths

import de.undercouch.gradle.tasks.download.Download
Expand Down Expand Up @@ -54,15 +56,11 @@ task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) {
dest(new File(downloadsDir, "boost_${BOOST_VERSION}.tar.gz"))
}

task prepareBoost(dependsOn: boostPath ? [] : [downloadBoost], type: Copy) {
from(boostPath ?: tarTree(resources.gzip(downloadBoost.dest)))
from("src/main/jni/third-party/boost")
include("Android.mk", "boost_${BOOST_VERSION}/boost/**/*.hpp", "boost/boost/**/*.hpp", "asm/**/*.S")
includeEmptyDirs = false
into("$thirdPartyNdkDir/boost")
doLast {
file("$thirdPartyNdkDir/boost/boost").renameTo("$thirdPartyNdkDir/boost/boost_${BOOST_VERSION}")
}
final def prepareBoost = tasks.register("prepareBoost", PrepareBoostTask) {
it.dependsOn(boostPath ? [] : [downloadBoost])
it.boostPath.setFrom(boostPath ?: tarTree(resources.gzip(downloadBoost.dest)))
it.boostVersion.set(BOOST_VERSION)
it.outputDir.set(new File(thirdPartyNdkDir, "boost"))
}

task downloadDoubleConversion(dependsOn: createNativeDepsDirectories, type: Download) {
Expand Down Expand Up @@ -120,26 +118,12 @@ task downloadLibevent(dependsOn: createNativeDepsDirectories, type: Download) {
dest(new File(downloadsDir, "libevent-${LIBEVENT_VERSION}.tar.gz"))
}

task prepareLibevent(dependsOn: dependenciesPath ? [] : [downloadLibevent], type: Copy) {
from(dependenciesPath ?: tarTree(downloadLibevent.dest))
from("src/main/jni/third-party/libevent/Android.mk")
from("src/main/jni/third-party/libevent/event-config.h")
from("src/main/jni/third-party/libevent/evconfig-private.h")
include(
"libevent-${LIBEVENT_VERSION}-stable/*.c",
"libevent-${LIBEVENT_VERSION}-stable/*.h",
"libevent-${LIBEVENT_VERSION}-stable/include/**/*",
"evconfig-private.h",
"event-config.h",
"Android.mk"
)
eachFile { fname -> fname.path = (fname.path - "libevent-${LIBEVENT_VERSION}-stable/") }
includeEmptyDirs = false
into("$thirdPartyNdkDir/libevent")

doLast {
ant.move(file: "$thirdPartyNdkDir/libevent/event-config.h", tofile: "$thirdPartyNdkDir/libevent/include/event2/event-config.h")
}
final def prepareLibevent = tasks.register("prepareLibevent", PrepareLibeventTask) {
it.dependsOn(dependenciesPath ? [] : [downloadLibevent])
it.libeventPath.setFrom(dependenciesPath ?: tarTree(downloadLibevent.dest))
it.libeventVersion.set(LIBEVENT_VERSION)
it.outputDir.set(new File(thirdPartyNdkDir, "libevent"))
}

task prepareHermes(dependsOn: createNativeDepsDirectories, type: Copy) {
Expand Down Expand Up @@ -169,73 +153,19 @@ task downloadGlog(dependsOn: createNativeDepsDirectories, type: Download) {

// Prepare glog sources to be compiled, this task will perform steps that normally should've been
// executed by automake. This way we can avoid dependencies on make/automake
task prepareGlog(dependsOn: dependenciesPath ? [] : [downloadGlog], type: Copy) {
duplicatesStrategy("warn")
from(dependenciesPath ?: tarTree(downloadGlog.dest))
from("src/main/jni/third-party/glog/")
include("glog-${GLOG_VERSION}/src/**/*", "Android.mk", "config.h")
includeEmptyDirs = false
filesMatching("**/*.h.in") {
filter(ReplaceTokens, tokens: [
ac_cv_have_unistd_h : "1",
ac_cv_have_stdint_h : "1",
ac_cv_have_systypes_h : "1",
ac_cv_have_inttypes_h : "1",
ac_cv_have_libgflags : "0",
ac_google_start_namespace : "namespace google {",
ac_cv_have_uint16_t : "1",
ac_cv_have_u_int16_t : "1",
ac_cv_have___uint16 : "0",
ac_google_end_namespace : "}",
ac_cv_have___builtin_expect : "1",
ac_google_namespace : "google",
ac_cv___attribute___noinline : "__attribute__ ((noinline))",
ac_cv___attribute___noreturn : "__attribute__ ((noreturn))",
ac_cv___attribute___printf_4_5: "__attribute__((__format__ (__printf__, 4, 5)))"
])
it.path = (it.name - ".in")
}
into("$thirdPartyNdkDir/glog")

doLast {
copy {
from(fileTree(dir: "$thirdPartyNdkDir/glog", includes: ["stl_logging.h", "logging.h", "raw_logging.h", "vlog_is_on.h", "**/src/glog/log_severity.h"]).files)
includeEmptyDirs = false
into("$thirdPartyNdkDir/glog/exported/glog")
}
}
final def prepareGlog = tasks.register("prepareGlog", PrepareGlogTask) {
it.dependsOn(dependenciesPath ? [] : [downloadGlog])
it.glogPath.setFrom(dependenciesPath ?: tarTree(downloadGlog.dest))
it.glogVersion.set(GLOG_VERSION)
it.outputDir.set(new File(thirdPartyNdkDir, "glog"))
}

// Create Android.mk library module based on jsc from npm
task prepareJSC {
doLast {
def jscPackagePath = findNodeModulePath(projectDir, "jsc-android")
if (!jscPackagePath) {
throw new GradleScriptException("Could not find the jsc-android npm package", null)
}

def jscDist = file("$jscPackagePath/dist")
if (!jscDist.exists()) {
throw new GradleScriptException("The jsc-android npm package is missing its \"dist\" directory", null)
}

def jscAAR = fileTree(jscDist).matching({ it.include "**/android-jsc/**/*.aar" }).singleFile
def soFiles = zipTree(jscAAR).matching({ it.include "**/*.so" })

def headerFiles = fileTree(jscDist).matching({ it.include "**/include/*.h" })

copy {
from(soFiles)
from(headerFiles)
from("src/main/jni/third-party/jsc/Android.mk")

filesMatching("**/*.h", { it.path = "JavaScriptCore/${it.name}" })

includeEmptyDirs(false)
into("$thirdPartyNdkDir/jsc")
}
}
tasks.register('prepareJSC', PrepareJSCTask) {
it.jscPackagePath.set(findNodeModulePath(projectDir, "jsc-android"))
it.outputDir = project.layout.buildDirectory.dir("third-party-ndk/jsc")
}

task downloadNdkBuildDependencies {
if (!boostPath) {
dependsOn(downloadBoost)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class ReactPlugin : Plugin<Project> {
}

private fun applyAppPlugin(project: Project, config: ReactExtension) {
if (config.applyAppPlugin.getOrElse(false)) {
project.afterEvaluate {
project.afterEvaluate {
if (config.applyAppPlugin.getOrElse(false)) {
val androidConfiguration = project.extensions.getByType(BaseExtension::class.java)
project.configureDevPorts(androidConfiguration)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,23 @@ internal fun Project.configureReactTasks(variant: BaseVariant, config: ReactExte
packageTask.configure {
if (config.enableVmCleanup.get()) {
val libDir = "$buildDir/intermediates/transforms/"
val targetVariant = ".*/transforms/[^/]*/$targetPath/.*".toRegex()
val targetVariant = ".*/transforms/[^/]*/${variant.name}/.*".toRegex()
it.doFirst { cleanupVMFiles(libDir, targetVariant, enableHermes, cleanup) }
}
}

stripDebugSymbolsTask?.configure {
if (config.enableVmCleanup.get()) {
val libDir = "$buildDir/intermediates/stripped_native_libs/${targetPath}/out/lib/"
val targetVariant = ".*/stripped_native_libs/$targetPath/out/lib/.*".toRegex()
val libDir = "$buildDir/intermediates/stripped_native_libs/${variant.name}/out/lib/"
val targetVariant = ".*/stripped_native_libs/${variant.name}/out/lib/.*".toRegex()
it.doLast { cleanupVMFiles(libDir, targetVariant, enableHermes, cleanup) }
}
}

mergeNativeLibsTask?.configure {
if (config.enableVmCleanup.get()) {
val libDir = "$buildDir/intermediates/merged_native_libs/${targetPath}/out/lib/"
val targetVariant = ".*/merged_native_libs/$targetPath/out/lib/.*".toRegex()
val libDir = "$buildDir/intermediates/merged_native_libs/${variant.name}/out/lib/"
val targetVariant = ".*/merged_native_libs/${variant.name}/out/lib/.*".toRegex()
it.doLast { cleanupVMFiles(libDir, targetVariant, enableHermes, cleanup) }
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.tasks.internal

import java.io.File
import org.gradle.api.DefaultTask
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.*

/**
* A task that takes care of extracting Boost from a source folder/zip and preparing it to be
* consumed by the NDK
*/
abstract class PrepareBoostTask : DefaultTask() {

@get:InputFiles abstract val boostPath: ConfigurableFileCollection

@get:Input abstract val boostVersion: Property<String>

@get:OutputDirectory abstract val outputDir: DirectoryProperty

@TaskAction
fun taskAction() {
project.copy { it ->
it.from(boostPath)
it.from(project.file("src/main/jni/third-party/boost"))
it.include(
"Android.mk",
"boost_${boostVersion.get()}/boost/**/*.hpp",
"boost/boost/**/*.hpp",
"asm/**/*.S")
it.includeEmptyDirs = false
it.into(outputDir)
}
File(outputDir.asFile.get(), "boost").apply {
renameTo(File(this.parentFile, "boost_${boostVersion.get()}"))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.tasks.internal

import java.io.File
import org.apache.tools.ant.filters.ReplaceTokens
import org.gradle.api.DefaultTask
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.provider.Property
import org.gradle.api.tasks.*

/**
* A task that takes care of extracting Glog from a source folder/zip and preparing it to be
* consumed by the NDK. This task will also take care of applying the mapping for Glog parameters.
*/
abstract class PrepareGlogTask : DefaultTask() {

@get:InputFiles abstract val glogPath: ConfigurableFileCollection

@get:Input abstract val glogVersion: Property<String>

@get:OutputDirectory abstract val outputDir: DirectoryProperty

@TaskAction
fun taskAction() {
project.copy {
it.from(glogPath)
it.from(project.file("src/main/jni/third-party/glog/"))
it.include("glog-${glogVersion.get()}/src/**/*", "Android.mk", "config.h")
it.duplicatesStrategy = DuplicatesStrategy.WARN
it.includeEmptyDirs = false
it.filesMatching("**/*.h.in") { matchedFile ->
matchedFile.filter(
mapOf(
"tokens" to
mapOf(
"ac_cv_have_unistd_h" to "1",
"ac_cv_have_stdint_h" to "1",
"ac_cv_have_systypes_h" to "1",
"ac_cv_have_inttypes_h" to "1",
"ac_cv_have_libgflags" to "0",
"ac_google_start_namespace" to "namespace google {",
"ac_cv_have_uint16_t" to "1",
"ac_cv_have_u_int16_t" to "1",
"ac_cv_have___uint16" to "0",
"ac_google_end_namespace" to "}",
"ac_cv_have___builtin_expect" to "1",
"ac_google_namespace" to "google",
"ac_cv___attribute___noinline" to "__attribute__ ((noinline))",
"ac_cv___attribute___noreturn" to "__attribute__ ((noreturn))",
"ac_cv___attribute___printf_4_5" to
"__attribute__((__format__ (__printf__, 4, 5)))")),
ReplaceTokens::class.java)
matchedFile.path = (matchedFile.name.removeSuffix(".in"))
}
it.into(outputDir)
}
val exportedDir = File(outputDir.asFile.get(), "exported/glog/").apply { mkdirs() }
project.copy {
it.from(outputDir)
it.include(
"stl_logging.h",
"logging.h",
"raw_logging.h",
"vlog_is_on.h",
"**/src/glog/log_severity.h")
it.eachFile { file -> file.path = file.name }
it.includeEmptyDirs = false
it.into(exportedDir)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.tasks.internal

import java.io.File
import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.*

/**
* A task that takes care of unbundling JSC and preparing it for be consumed by the Android NDK.
* Specifically it will unbundle shared libs, headers and will copy over the Makefile from
* `src/main/jni/third-party/jsc/`
*/
abstract class PrepareJSCTask : DefaultTask() {

@get:Input abstract val jscPackagePath: Property<String>

@get:OutputDirectory abstract val outputDir: DirectoryProperty

@TaskAction
fun taskAction() {
if (!jscPackagePath.isPresent || jscPackagePath.orNull == null) {
error("Could not find the jsc-android npm package")
}
val jscDist = File(jscPackagePath.get(), "dist")
if (!jscDist.exists()) {
error("The jsc-android npm package is missing its \"dist\" directory")
}
val jscAAR =
project.fileTree(jscDist).matching { it.include("**/android-jsc/**/*.aar") }.singleFile
val soFiles = project.zipTree(jscAAR).matching { it.include("**/*.so") }
val headerFiles = project.fileTree(jscDist).matching { it.include("**/include/*.h") }

project.copy { it ->
it.from(soFiles)
it.from(headerFiles)
it.from(project.file("src/main/jni/third-party/jsc/Android.mk"))
it.filesMatching("**/*.h") { it.path = "JavaScriptCore/${it.name}" }
it.includeEmptyDirs = false
it.into(outputDir)
}
}
}
Loading