Skip to content

Commit

Permalink
Exclude generated folders from the GenerateCodegenSchemaTask
Browse files Browse the repository at this point in the history
Summary:
I'm adding a series of excludes to the `GenerateCodegenSchemaTaskTest`.
The reason is that RN Tester is setting `packages/rn-tester` as the root of the
specs as they're not isolated.

This is causing the Gradle task to crawl inside the `android/app/build` folder
where we store sourcemaps and other files that have .js files. As those files
gets updated when you build, the codegen task gets invalidated over and over
and Gradle is firing warning about it.

Changelog:
[Internal] [Changed] - Exclude generated folders from the GenerateCodegenSchemaTask

Reviewed By: cipolleschi

Differential Revision: D40098418

fbshipit-source-id: fcffbc73e8258c4e9eefda062e1fad77be650002
  • Loading branch information
cortinico authored and facebook-github-bot committed Oct 5, 2022
1 parent 0857238 commit 881f1de
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Expand Up @@ -34,7 +34,14 @@ abstract class GenerateCodegenSchemaTask : Exec() {
project.fileTree(jsRootDir) {
it.include("**/*.js")
it.include("**/*.ts")
// Those are known build paths where the source map or other
// .js files could be stored/generated. We want to make sure we don't pick them up
// for execution avoidance.
it.exclude("**/generated/source/codegen/**/*")
it.exclude("**/build/generated/assets/react/**/*")
it.exclude("**/build/generated/res/react/**/*")
it.exclude("**/build/generated/sourcemaps/react/**/*")
it.exclude("**/build/intermediates/sourcemaps/react/**/*")
}

@get:OutputFile
Expand Down
Expand Up @@ -41,6 +41,45 @@ class GenerateCodegenSchemaTaskTest {
setOf(File(jsRootDir, "file.js"), File(jsRootDir, "file.ts")), task.jsInputFiles.files)
}

@Test
fun generateCodegenSchema_inputFilesInExcludedPath_areExcluded() {
fun File.createFileAndPath() {
parentFile.mkdirs()
createNewFile()
}

val jsRootDir =
tempFolder.newFolder("js").apply {
File(this, "afolder/includedfile.js").createFileAndPath()
// Those files should be excluded due to their filepath
File(this, "afolder/generated/source/codegen/anotherfolder/excludedfile.js")
.createFileAndPath()
File(this, "afolder/build/generated/assets/react/anotherfolder/excludedfile.js")
.createFileAndPath()
File(this, "afolder/build/generated/res/react/anotherfolder/excludedfile.js")
.createFileAndPath()
File(this, "afolder/build/generated/sourcemaps/react/anotherfolder/excludedfile.js")
.createFileAndPath()
File(this, "afolder/build/intermediates/sourcemaps/react/anotherfolder/excludedfile.js")
.createFileAndPath()
}

val task = createTestTask<GenerateCodegenSchemaTask> { it.jsRootDir.set(jsRootDir) }

assertEquals(jsRootDir, task.jsInputFiles.dir)
assertEquals(
setOf(
"**/generated/source/codegen/**/*",
"**/build/generated/assets/react/**/*",
"**/build/generated/res/react/**/*",
"**/build/generated/sourcemaps/react/**/*",
"**/build/intermediates/sourcemaps/react/**/*",
),
task.jsInputFiles.excludes)
assertEquals(1, task.jsInputFiles.files.size)
assertEquals(setOf(File(jsRootDir, "afolder/includedfile.js")), task.jsInputFiles.files)
}

@Test
fun generateCodegenSchema_outputFile_isSetCorrectly() {
val outputDir = tempFolder.newFolder("output")
Expand Down

0 comments on commit 881f1de

Please sign in to comment.