Skip to content

Commit 07b645d

Browse files
maciekstosiokkafar
authored andcommitted
chore: change gradle task for copying to new archs into JS scripts (software-mansion#2224)
## Description This task is rewrite to JS of software-mansion#2168 with some improvements. General point of creating those tasks is: > When changing native props on Fabric, codegen generates corresponding interfaces and delegates. To make sure both implementations are consistent, we implement those interfaces on Paper too. Currently, after generating interfaces using codegen, developer needs to copy corresponding files for paper manually. This task adds Gradle task, that automates this. ## Changes Current assumption: Two scripts: `check-archs-consistency` and `sync-archs`. The first one generates codegen interfaces and compares them with what we have for paper, the second generates and copies for paper to sync the archs. - sync is run pre build on example app - sync is run when staged on changes to `src/paper` - check is run on CI when `src/paper` or `android/src/paper/java/com/facebook/react/viewmanagers` changes What it improves: - JS tasks are much faster, as codegen is JS script anyway, we skip gradle and java setup all together (CI task down from 7min to 30s), - we do not put code to library, so it shouldn't be possible to mess up something for end users, - instead of syncing archs when running codegen we do that on paper example build and when staged, so: when developer didn't touch the code it will have changes after commit, when developer switched to working on paper interfaces should be always up to date when building the app. ## Test code and steps to reproduce Open `src/fabric/ScreenStackHeaderConfigNativeComponent.ts` and remove any proper form interface. Now: - when building paper, interface should be updated - when committing, interface should be updated - if committed and pushed, Test consistency between Paper & Fabric should fail :) Brining back the prop and repeating up should cause the interface back and CI green. Posting changes in other places should cause CI task to run. You can also run those commands yourself using `yarn check-archs-consistency` and `yarn sync-archs` --------- Co-authored-by: Kacper Kafara <kacper.kafara@swmansion.com>
1 parent d0ae2f5 commit 07b645d

File tree

13 files changed

+179
-92
lines changed

13 files changed

+179
-92
lines changed

.github/workflows/android-build-test.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ jobs:
3535
with:
3636
node-version: 18
3737
cache: 'yarn'
38-
cache-dependency-path: 'Example/yarn.lock'
39-
- name: Install node dependencies
38+
cache-dependency-path: |
39+
yarn.lock
40+
Example/yarn.lock
41+
- name: Install dependencies
42+
run: yarn
43+
- name: Install Example app dependencies
4044
working-directory: ${{ env.WORKING_DIRECTORY }}
4145
run: yarn
4246
- name: Build app
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Test consistency between Paper & Fabric
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
paths:
7+
- src/fabric/**
8+
- android/src/paper/java/com/facebook/react/viewmanagers/**
9+
jobs:
10+
check:
11+
runs-on: ubuntu-latest
12+
concurrency:
13+
group: check-archs-consistency-${{ github.ref }}
14+
cancel-in-progress: true
15+
steps:
16+
- name: checkout
17+
uses: actions/checkout@v2
18+
- name: Use Node.js 18
19+
uses: actions/setup-node@v2
20+
with:
21+
node-version: 18
22+
cache: 'yarn'
23+
- name: Install node dependencies
24+
run: yarn
25+
- name: Check Android Paper & Fabric generated interfaces consistency
26+
run: yarn check-archs-consistency

Example/android/app/build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,13 @@ dependencies {
135135
}
136136

137137
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
138+
apply plugin: 'com.github.node-gradle.node'
139+
140+
task syncArchs(type: NodeTask) {
141+
group = 'Build'
142+
description = 'Run sync beetwen Paper and Fabric arch'
143+
yarn_install
144+
script = file('../../../scripts/codegen-sync-archs.js')
145+
}
146+
147+
tasks['preBuild'].dependsOn(syncArchs)

Example/android/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ buildscript {
1010
repositories {
1111
google()
1212
mavenCentral()
13+
gradlePluginPortal() // Added to run node ./scripts/codegen-sync-archs.js using syncArchs task
1314
}
1415
dependencies {
1516
classpath("com.android.tools.build:gradle")
1617
classpath("com.facebook.react:react-native-gradle-plugin")
1718
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
19+
classpath("com.github.node-gradle:gradle-node-plugin:7.0.2") // Added to run node ./scripts/codegen-sync-archs.js using syncArchs task
1820
}
1921
}
2022

Example/android/gradle.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,3 @@ hermesEnabled=true
4949
# This is necessary, because the code checking for multiple instances
5050
# detects package versions from other example applications in the repository.
5151
disableMultipleInstancesCheck=true
52-
53-
isScreensExampleApp=true

FabricExample/android/gradle.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,3 @@ newArchEnabled=true
3939
# Use this property to enable or disable the Hermes JS engine.
4040
# If set to false, you will be using JSC instead.
4141
hermesEnabled=true
42-
43-
isScreensExampleApp=true

TVOSExample/android/gradle.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,3 @@ newArchEnabled=false
4040
# If set to false, you will be using JSC instead.
4141
hermesEnabled=true
4242

43-
isScreensExampleApp=true

android/build.gradle

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -196,79 +196,3 @@ dependencies {
196196
}
197197
}
198198
}
199-
200-
def isScreensExampleApp() {
201-
return project.hasProperty('isScreensExampleApp') && project.property('isScreensExampleApp') == "true"
202-
}
203-
204-
def getAbsoluteCodegenArtifactsPaperDestination() {
205-
if (!project.hasProperty('codegenArtifactsPaperDestination')) {
206-
throw new Exception('[RNScreens] Please fill codegenArtifactsPaperDestination variable in android/gradle.properties correct path to paper paper destination')
207-
}
208-
209-
return "${project.rootDir}/../../${project.property('codegenArtifactsPaperDestination')}"
210-
}
211-
212-
def getAbsoluteCodegenArtifactsSource() {
213-
if (!project.hasProperty('codegenArtifactsSource')) {
214-
throw new Exception('[RNScreens] Please fill codegenArtifactsSource variable in android/gradle.properties correct path to codegenerated artifacts')
215-
}
216-
217-
return "${project.rootDir}/../../${project.property('codegenArtifactsSource')}"
218-
}
219-
220-
221-
tasks.register("copyCodegenArtifacts") {
222-
group 'After build tasks'
223-
description 'Tasks which copy codegen artifacts to paper architecture'
224-
225-
if (!isScreensExampleApp() || !isNewArchitectureEnabled()) {
226-
return
227-
}
228-
229-
dependsOn tasks.generateCodegenArtifactsFromSchema
230-
231-
doLast {
232-
233-
def absoluteCodegenArtifactsPaperDestination = getAbsoluteCodegenArtifactsPaperDestination()
234-
def absoluteCodegenArtifactsSource = getAbsoluteCodegenArtifactsSource()
235-
236-
def existingFiles = fileTree(absoluteCodegenArtifactsPaperDestination).matching {
237-
include '**/*.java'
238-
}
239-
240-
def generatedFiles = fileTree(absoluteCodegenArtifactsSource).matching {
241-
include '**/*.java'
242-
}
243-
244-
def existingFilesMap = [:]
245-
246-
existingFiles.forEach { existingFile ->
247-
existingFilesMap[existingFile.name] = 1
248-
}
249-
250-
generatedFiles.forEach { generatedFile ->
251-
if (!existingFilesMap.containsKey(generatedFile.name)) {
252-
logger.warn("[RNScreens] ${generatedFile.name} not found in paper dir, if it's used in Android you need to copy it manually and implement yourself before using auto-copy feature")
253-
}
254-
}
255-
256-
if (existingFiles.size() == 0) {
257-
logger.warn("[RNScreens] Paper destination with codegen interfaces is empty. This might be okay if you don't have any interfaces/delegates used in Android, if that's not the case please check if codegenArtifactsPaperDestination in android/gradle.properties is correct")
258-
}
259-
260-
if (existingFiles.size() > generatedFiles.size()) {
261-
throw new Exception("[RNScreens] Number od generated artifacts should be greather then or equal to paper interfaces. Please check if codegenArtifactsSource in android/gradle.properties is correct")
262-
}
263-
264-
copy {
265-
from absoluteCodegenArtifactsSource
266-
include existingFiles.collect { it.name }
267-
into absoluteCodegenArtifactsPaperDestination
268-
}
269-
}
270-
}
271-
272-
if (isScreensExampleApp() && isNewArchitectureEnabled()) {
273-
tasks.generateCodegenArtifactsFromSchema.finalizedBy('copyCodegenArtifacts')
274-
}

android/gradle.properties

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,3 @@ android.useAndroidX=true
2121
android.enableJetifier=true
2222

2323
kotlin.code.style=official
24-
25-
# Path to codegen output directory with this library view manager's interfaces & delegates. Used by `copyCodegenArtifacts` task that helps to synchronise newly generated files with their Paper conterparts.
26-
codegenArtifactsSource=android/build/generated/source/codegen/java/com/facebook/react/viewmanagers
27-
28-
# Path to directory with view manager's interfaces & delegates used while running on Paper architecture. This property is used as output path for `copyCodegenArtifacts` task.
29-
# Used for task (copyCodegenArtifacts) that automates copying those interfaces/delegates when codegen is run
30-
codegenArtifactsPaperDestination=android/src/paper/java/com/facebook/react/viewmanagers/

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
"lint-android": "./android/gradlew -p android spotlessCheck -q",
1919
"lint": "yarn lint-js && yarn lint-android",
2020
"release": "yarn prepare && npm login && release-it",
21-
"prepare": "bob build && husky install"
21+
"prepare": "bob build && husky install",
22+
"check-archs-consistency": "node ./scripts/codegen-check-consistency.js",
23+
"sync-archs": "node ./scripts/codegen-sync-archs.js"
2224
},
2325
"main": "lib/commonjs/index",
2426
"module": "lib/module/index",
@@ -127,7 +129,8 @@
127129
"cpp/**/*.{h,cpp}": "yarn format-cpp",
128130
"android/src/main/cpp/.{cpp, h}": "yarn format-android-cpp",
129131
"android/**/*.kt": "yarn format-android",
130-
"ios/**/*.{h,m,mm,cpp}": "yarn format-ios"
132+
"ios/**/*.{h,m,mm,cpp}": "yarn format-ios",
133+
"src/fabric/*.ts": "yarn sync-archs"
131134
},
132135
"react-native-builder-bob": {
133136
"source": "src",

0 commit comments

Comments
 (0)