Skip to content

Commit efb85fd

Browse files
Re-copy the prefab headers when a header changes
PreparePrefabHeadersTask declared only the directory paths it copies from, so Gradle found it up to date after a header under them changed and the prefab package every app and library compiles against kept the old header. The headers it copies are now its input files, read through the same file trees the copy uses, and each library's folder is rebuilt from scratch so a removed header leaves no copy behind.
1 parent b5d770c commit efb85fd

1 file changed

Lines changed: 51 additions & 27 deletions

File tree

‎packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/internal/PreparePrefabHeadersTask.kt‎

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ import java.io.File
1212
import javax.inject.Inject
1313
import org.gradle.api.DefaultTask
1414
import org.gradle.api.file.DirectoryProperty
15+
import org.gradle.api.file.FileCollection
1516
import org.gradle.api.file.FileSystemOperations
17+
import org.gradle.api.file.FileTree
1618
import org.gradle.api.file.RegularFile
19+
import org.gradle.api.model.ObjectFactory
1720
import org.gradle.api.provider.ListProperty
1821
import org.gradle.api.tasks.Input
22+
import org.gradle.api.tasks.InputFiles
1923
import org.gradle.api.tasks.OutputDirectory
2024
import org.gradle.api.tasks.TaskAction
2125

@@ -35,44 +39,64 @@ abstract class PreparePrefabHeadersTask : DefaultTask() {
3539

3640
@get:OutputDirectory abstract val outputDir: DirectoryProperty
3741

42+
@get:InputFiles
43+
val headers: FileCollection
44+
get() =
45+
objects
46+
.fileCollection()
47+
.from(
48+
input.map { entries ->
49+
entries.flatMap { (_, pathToPrefixCouples) ->
50+
pathToPrefixCouples.map { (headerPath, _) -> headersUnder(headerPath) }
51+
}
52+
}
53+
)
54+
3855
@get:Inject abstract val fs: FileSystemOperations
3956

57+
@get:Inject abstract val objects: ObjectFactory
58+
4059
@TaskAction
4160
fun taskAction() {
4261
input.get().forEach { (libraryName, pathToPrefixCouples) ->
4362
val outputFolder: RegularFile = outputDir.file(libraryName).get()
63+
fs.delete { deleteSpec -> deleteSpec.delete(outputFolder) }
4464
pathToPrefixCouples.forEach { (headerPath, headerPrefix) ->
4565
fs.copy { copySpec ->
46-
copySpec.from(headerPath)
47-
copySpec.include("**/*.h")
48-
copySpec.exclude("**/*.cpp")
49-
copySpec.exclude("**/*.txt")
50-
// We don't want to copy all the boost headers as they are 250Mb+
51-
copySpec.include("boost/config.hpp")
52-
copySpec.include("boost/config/**/*.hpp")
53-
copySpec.include("boost/core/*.hpp")
54-
copySpec.include("boost/detail/workaround.hpp")
55-
copySpec.include("boost/operators.hpp")
56-
copySpec.include("boost/preprocessor/**/*.hpp")
57-
// Headers needed for exposing rrc_text and rrc_textinput
58-
copySpec.include("boost/container_hash/**/*.hpp")
59-
copySpec.include("boost/detail/**/*.hpp")
60-
copySpec.include("boost/intrusive/**/*.hpp")
61-
copySpec.include("boost/iterator/**/*.hpp")
62-
copySpec.include("boost/move/**/*.hpp")
63-
copySpec.include("boost/mpl/**/*.hpp")
64-
copySpec.include("boost/mp11/**/*.hpp")
65-
copySpec.include("boost/describe/**/*.hpp")
66-
copySpec.include("boost/type_traits/**/*.hpp")
67-
copySpec.include("boost/utility/**/*.hpp")
68-
copySpec.include("boost/assert.hpp")
69-
copySpec.include("boost/static_assert.hpp")
70-
copySpec.include("boost/cstdint.hpp")
71-
copySpec.include("boost/utility.hpp")
72-
copySpec.include("boost/version.hpp")
66+
copySpec.from(headersUnder(headerPath))
7367
copySpec.into(File(outputFolder.asFile, headerPrefix))
7468
}
7569
}
7670
}
7771
}
72+
73+
private fun headersUnder(headerPath: String): FileTree =
74+
objects.fileTree().from(headerPath).matching { patterns ->
75+
patterns.include("**/*.h")
76+
patterns.exclude("**/*.cpp")
77+
patterns.exclude("**/*.txt")
78+
// We don't want to copy all the boost headers as they are 250Mb+
79+
patterns.include("boost/config.hpp")
80+
patterns.include("boost/config/**/*.hpp")
81+
patterns.include("boost/core/*.hpp")
82+
patterns.include("boost/detail/workaround.hpp")
83+
patterns.include("boost/operators.hpp")
84+
patterns.include("boost/preprocessor/**/*.hpp")
85+
// Headers needed for exposing rrc_text and rrc_textinput
86+
patterns.include("boost/container_hash/**/*.hpp")
87+
patterns.include("boost/detail/**/*.hpp")
88+
patterns.include("boost/intrusive/**/*.hpp")
89+
patterns.include("boost/iterator/**/*.hpp")
90+
patterns.include("boost/move/**/*.hpp")
91+
patterns.include("boost/mpl/**/*.hpp")
92+
patterns.include("boost/mp11/**/*.hpp")
93+
patterns.include("boost/describe/**/*.hpp")
94+
patterns.include("boost/type_traits/**/*.hpp")
95+
patterns.include("boost/utility/**/*.hpp")
96+
patterns.include("boost/assert.hpp")
97+
patterns.include("boost/static_assert.hpp")
98+
patterns.include("boost/cstdint.hpp")
99+
patterns.include("boost/utility.hpp")
100+
patterns.include("boost/version.hpp")
101+
}
78102
}

0 commit comments

Comments
 (0)