-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export prepareBoost to an internal task
Summary: 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: 1af56d1e4405cb7da66b246498d30f1b364a9ca3
- Loading branch information
1 parent
b2503ea
commit 351f6ad
Showing
3 changed files
with
156 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...ative-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/internal/PrepareBoostTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()}")) | ||
} | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
...e-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/internal/PrepareBoostTaskTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) | ||
} | ||
} |