Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: automatically copy codegen artifacts to paper #2933

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions FabricExample/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ newArchEnabled=true
# Use this property to enable or disable the Hermes JS engine.
# If set to false, you will be using JSC instead.
hermesEnabled=true

isGHExampleApp=true
77 changes: 77 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,80 @@ dependencies {
implementation "androidx.core:core-ktx:1.6.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

def isGHExampleApp() {
return project.hasProperty('isGHExampleApp') && project.property('isGHExampleApp') == "true"
}

def getAbsoluteCodegenArtifactsPaperDestination() {
if (!project.hasProperty('codegenArtifactsPaperDestination')) {
throw new Exception('[RNGH] Please fill codegenArtifactsPaperDestination variable in android/gradle.properties correct path to paper paper destination')
maciekstosio marked this conversation as resolved.
Show resolved Hide resolved
}

return "${project.rootDir}/../../${project.property('codegenArtifactsPaperDestination')}"
}

def getAbsoluteCodegenArtifactsSource() {
if (!project.hasProperty('codegenArtifactsSource')) {
throw new Exception('[RNGH] Please fill codegenArtifactsSource variable in android/gradle.properties correct path to codegenerated artifacts')
maciekstosio marked this conversation as resolved.
Show resolved Hide resolved
}

return "${project.rootDir}/../../${project.property('codegenArtifactsSource')}"
}


tasks.register("copyCodegenArtifacts") {
group 'After build tasks'
description 'Tasks which copy codegen artifacts to paper architecture'
maciekstosio marked this conversation as resolved.
Show resolved Hide resolved

if (!isGHExampleApp() || !isNewArchitectureEnabled()) {
return
}

dependsOn tasks.generateCodegenArtifactsFromSchema

doLast {

def absoluteCodegenArtifactsPaperDestination = getAbsoluteCodegenArtifactsPaperDestination()
def absoluteCodegenArtifactsSource = getAbsoluteCodegenArtifactsSource()

def existingFiles = fileTree(absoluteCodegenArtifactsPaperDestination).matching {
include '**/*.java'
}

def generatedFiles = fileTree(absoluteCodegenArtifactsSource).matching {
include '**/*.java'
}

def existingFilesMap = [:]

existingFiles.forEach { existingFile ->
println existingFile
existingFilesMap[existingFile.name] = 1
}

generatedFiles.forEach { generatedFile ->
if (!existingFilesMap.containsKey(generatedFile.name)) {
logger.warn("[RNGH] ${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")
maciekstosio marked this conversation as resolved.
Show resolved Hide resolved
}
}

if (existingFiles.size() == 0) {
logger.warn("[RNGH] 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")
maciekstosio marked this conversation as resolved.
Show resolved Hide resolved
}

if (existingFiles.size() > generatedFiles.size()) {
throw new Exception("[RNGH] Number od generated artifacts should be greather then or equal to paper interfaces. Please check if codegenArtifactsSource in android/gradle.properties is correct")
maciekstosio marked this conversation as resolved.
Show resolved Hide resolved
}

copy {
from absoluteCodegenArtifactsSource
include existingFiles.collect { it.name }
into absoluteCodegenArtifactsPaperDestination
}
}
}

if (isGHExampleApp() && isNewArchitectureEnabled()) {
tasks.generateCodegenArtifactsFromSchema.finalizedBy('copyCodegenArtifacts')
}
7 changes: 7 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemor
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
RNGH_kotlinVersion=1.6.21

# 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.
maciekstosio marked this conversation as resolved.
Show resolved Hide resolved
codegenArtifactsSource=android/build/generated/source/codegen/java/com/facebook/react/viewmanagers

# 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.
maciekstosio marked this conversation as resolved.
Show resolved Hide resolved
# Used for task (copyCodegenArtifacts) that automates copying those interfaces/delegates when codegen is run
maciekstosio marked this conversation as resolved.
Show resolved Hide resolved
codegenArtifactsPaperDestination=android/paper/src/main/java/com/facebook/react/viewmanagers
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GeneratePropsJavaDelegate.js
*/
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GeneratePropsJavaDelegate.js
*/

package com.facebook.react.viewmanagers;

Expand Down
Loading