-
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 prepareLibevent to an internal task
Summary: This diff refactors the `prepareLibevent` task to a separate Gradle task in the `.internal` package. The reason for this change is that `prepareLibevent` was defining a `doLast` action and would result in being invalidated whenever the `build.gradle` file would change. This means that the Libevent headers/source files would have been extracted again, effectively invalidating the timestamps for the native build. Changelog: [Internal] [Changed] - Export prepareLibevent to an internal task Differential Revision: D31661988 fbshipit-source-id: 0f3915dd61ddbf9facbc696a7de2243bf7a92c54
- Loading branch information
1 parent
eaf97b5
commit b2503ea
Showing
3 changed files
with
159 additions
and
19 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
53 changes: 53 additions & 0 deletions
53
...ve-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/internal/PrepareLibeventTask.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,53 @@ | ||
/* | ||
* 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 Libevent from a source folder/zip and preparing it to be | ||
* consumed by the NDK. | ||
*/ | ||
abstract class PrepareLibeventTask : DefaultTask() { | ||
|
||
@get:InputFiles abstract val libeventPath: ConfigurableFileCollection | ||
|
||
@get:Input abstract val libeventVersion: Property<String> | ||
|
||
@get:OutputDirectory abstract val outputDir: DirectoryProperty | ||
|
||
@TaskAction | ||
fun taskAction() { | ||
project.copy { it -> | ||
it.from(libeventPath) | ||
it.from(project.file("src/main/jni/third-party/libevent/Android.mk")) | ||
it.from(project.file("src/main/jni/third-party/libevent/event-config.h")) | ||
it.from(project.file("src/main/jni/third-party/libevent/evconfig-private.h")) | ||
it.include( | ||
"libevent-${libeventVersion.get()}-stable/*.c", | ||
"libevent-${libeventVersion.get()}-stable/*.h", | ||
"libevent-${libeventVersion.get()}-stable/include/**/*", | ||
"evconfig-private.h", | ||
"event-config.h", | ||
"Android.mk") | ||
it.eachFile { it.path = it.path.removePrefix("libevent-${libeventVersion.get()}-stable/") } | ||
it.includeEmptyDirs = false | ||
it.into(outputDir) | ||
} | ||
File(outputDir.asFile.get(), "event-config.h").apply { | ||
val destination = | ||
File(this.parentFile, "include/event2/event-config.h").apply { parentFile.mkdirs() } | ||
renameTo(destination) | ||
} | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
...radle-plugin/src/test/kotlin/com/facebook/react/tasks/internal/PrepareLibeventTaskTest.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,101 @@ | ||
/* | ||
* 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 PrepareLibeventTaskTest { | ||
|
||
@get:Rule val tempFolder = TemporaryFolder() | ||
|
||
@Test(expected = IllegalStateException::class) | ||
fun prepareBoostTask_withMissingConfiguration_fails() { | ||
val task = createTestTask<PrepareLibeventTask>() | ||
|
||
task.taskAction() | ||
} | ||
|
||
@Test | ||
fun prepareBoostTask_copiesMakefile() { | ||
val libeventPath = tempFolder.newFolder("libeventPath") | ||
val output = tempFolder.newFolder("output") | ||
val project = createProject() | ||
val task = | ||
createTestTask<PrepareLibeventTask>(project = project) { | ||
it.libeventPath.setFrom(libeventPath) | ||
it.libeventVersion.set("1.0.0") | ||
it.outputDir.set(output) | ||
} | ||
File(project.projectDir, "src/main/jni/third-party/libevent/Android.mk").apply { | ||
parentFile.mkdirs() | ||
createNewFile() | ||
} | ||
task.taskAction() | ||
|
||
assertTrue(File(output, "Android.mk").exists()) | ||
} | ||
|
||
@Test | ||
fun prepareBoostTask_copiesConfigFiles() { | ||
val libeventPath = tempFolder.newFolder("libeventPath") | ||
val output = tempFolder.newFolder("output") | ||
val project = createProject() | ||
val task = | ||
createTestTask<PrepareLibeventTask>(project = project) { | ||
it.libeventPath.setFrom(libeventPath) | ||
it.libeventVersion.set("1.0.0") | ||
it.outputDir.set(output) | ||
} | ||
File(project.projectDir, "src/main/jni/third-party/libevent/event-config.h").apply { | ||
parentFile.mkdirs() | ||
createNewFile() | ||
} | ||
File(project.projectDir, "src/main/jni/third-party/libevent/evconfig-private.h").createNewFile() | ||
|
||
task.taskAction() | ||
|
||
assertTrue(File(output, "evconfig-private.h").exists()) | ||
assertTrue(File(output, "include/event2/event-config.h").exists()) | ||
} | ||
|
||
@Test | ||
fun prepareBoostTask_copiesSourceFiles() { | ||
val libeventPath = tempFolder.newFolder("libeventPath") | ||
val output = tempFolder.newFolder("output") | ||
val task = | ||
createTestTask<PrepareLibeventTask> { | ||
it.libeventPath.setFrom(libeventPath) | ||
it.libeventVersion.set("1.0.0") | ||
it.outputDir.set(output) | ||
} | ||
File(libeventPath, "libevent-1.0.0-stable/sample.c").apply { | ||
parentFile.mkdirs() | ||
createNewFile() | ||
} | ||
File(libeventPath, "libevent-1.0.0-stable/sample.h").apply { | ||
parentFile.mkdirs() | ||
createNewFile() | ||
} | ||
File(libeventPath, "libevent-1.0.0-stable/include/sample.h").apply { | ||
parentFile.mkdirs() | ||
createNewFile() | ||
} | ||
|
||
task.taskAction() | ||
|
||
assertTrue(File(output, "sample.c").exists()) | ||
assertTrue(File(output, "sample.h").exists()) | ||
assertTrue(File(output, "include/sample.h").exists()) | ||
} | ||
} |