Skip to content

Commit

Permalink
Export prepareBoost to an internal task (#32424)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #32424

This diff refactors the `prepareBoost` task to a separate Gradle task in the `.internal` package.
The reason for this change is that `prepareBoost` was defining a `doLast` action and would result in being
invalidated whenever the `build.gradle` file would change. This means that the Boost headers/source files
would have been extracted again, effectively invalidating the timestamps for the native build.

Changelog:
[Internal] [Changed] - Export prepareBoost to an internal task

Reviewed By: ShikaSD

Differential Revision: D31662120

fbshipit-source-id: 87ba82c634da832ee54c3d13561df45d3fd71381
  • Loading branch information
cortinico authored and facebook-github-bot committed Oct 18, 2021
1 parent bb981b2 commit 52b0cc0
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 9 deletions.
14 changes: 5 additions & 9 deletions ReactAndroid/build.gradle
Expand Up @@ -56,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
@@ -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()}"))
}
}
}
@@ -0,0 +1,105 @@
/*
* 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 com.facebook.react.tests.createProject
import com.facebook.react.tests.createTestTask
import java.io.*
import org.junit.Assert.*
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder

class PrepareBoostTaskTest {

@get:Rule val tempFolder = TemporaryFolder()

@Test(expected = IllegalStateException::class)
fun prepareBoostTask_withMissingConfiguration_fails() {
val task = createTestTask<PrepareBoostTask>()

task.taskAction()
}

@Test
fun prepareBoostTask_copiesMakefile() {
val boostpath = tempFolder.newFolder("boostpath")
val output = tempFolder.newFolder("output")
val project = createProject()
val task =
createTestTask<PrepareBoostTask>(project = project) {
it.boostPath.setFrom(boostpath)
it.boostVersion.set("1.0.0")
it.outputDir.set(output)
}
File(project.projectDir, "src/main/jni/third-party/boost/Android.mk").apply {
parentFile.mkdirs()
createNewFile()
}
task.taskAction()

assertTrue(output.listFiles()!!.any { it.name == "Android.mk" })
}

@Test
fun prepareBoostTask_copiesAsmFiles() {
val boostpath = tempFolder.newFolder("boostpath")
val output = tempFolder.newFolder("output")
val task =
createTestTask<PrepareBoostTask>() {
it.boostPath.setFrom(boostpath)
it.boostVersion.set("1.0.0")
it.outputDir.set(output)
}
File(boostpath, "asm/asm.S").apply {
parentFile.mkdirs()
createNewFile()
}
task.taskAction()

assertTrue(File(output, "asm/asm.S").exists())
}

@Test
fun prepareBoostTask_copiesBoostSourceFiles() {
val boostpath = tempFolder.newFolder("boostpath")
val output = tempFolder.newFolder("output")
val task =
createTestTask<PrepareBoostTask> {
it.boostPath.setFrom(boostpath)
it.boostVersion.set("1.0.0")
it.outputDir.set(output)
}
File(boostpath, "boost_1.0.0/boost/config.hpp").apply {
parentFile.mkdirs()
createNewFile()
}
task.taskAction()

assertTrue(File(output, "boost_1.0.0/boost/config.hpp").exists())
}

@Test
fun prepareBoostTask_copiesVersionlessBoostSourceFiles() {
val boostpath = tempFolder.newFolder("boostpath")
val output = tempFolder.newFolder("output")
val task =
createTestTask<PrepareBoostTask> {
it.boostPath.setFrom(boostpath)
it.boostVersion.set("1.0.0")
it.outputDir.set(output)
}
File(boostpath, "boost/boost/config.hpp").apply {
parentFile.mkdirs()
createNewFile()
}
task.taskAction()

assertTrue(File(output, "boost_1.0.0/boost/config.hpp").exists())
}
}

0 comments on commit 52b0cc0

Please sign in to comment.