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: Add gradle task to automatically copy the codegen artifacts for paper #2168

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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 Example/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ hermesEnabled=true
# This is necessary, because the code checking for multiple instances
# detects package versions from other example applications in the repository.
disableMultipleInstancesCheck=true

isScreensExampleApp=true
maciekstosio marked this conversation as resolved.
Show resolved Hide resolved
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

isScreensExampleApp=true
kkafar marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions FabricTestExample/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ newArchEnabled=true
hermesEnabled=true

disableMultipleInstancesCheck=true

isScreensExampleApp=true
2 changes: 2 additions & 0 deletions TVOSExample/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ android.enableJetifier=true

# Version of flipper SDK to use with React Native
FLIPPER_VERSION=0.75.1

isScreensExampleApp=true
maciekstosio marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions TestsExample/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ newArchEnabled=false
hermesEnabled=true

disableMultipleInstancesCheck=true

isScreensExampleApp=true
maciekstosio marked this conversation as resolved.
Show resolved Hide resolved
76 changes: 76 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,79 @@ dependencies {
}
}
}

def isScreensExampleApp() {
return project.hasProperty('isScreensExampleApp') && project.property('isScreensExampleApp')
kkafar marked this conversation as resolved.
Show resolved Hide resolved
}

def getAbsoluteCodegenArtifactsPaperDestination() {
if (!project.hasProperty('codegenArtifactsPaperDestination')) {
throw new Exception('[RNScreens] Please fill codegenArtifactsPaperDestination variable in android/gradle.properties correct path to paper paper destination')
}

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

def getAbsoluteCodegenArtifactsSource() {
if (!project.hasProperty('codegenArtifactsSource')) {
throw new Exception('[RNScreens] Please fill codegenArtifactsSource variable in android/gradle.properties correct path to codegenerated artifacts')
}

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


tasks.register("copyCodegenArtifacts") {
group 'After build tasks'
description 'Tasks which copy codegen artifacts to paper architecture'

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

dependsOn tasks.generateCodegenArtifactsFromSchema
kkafar marked this conversation as resolved.
Show resolved Hide resolved

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 ->
existingFilesMap[existingFile.name] = 1
}

generatedFiles.forEach { generatedFile ->
if (!existingFilesMap.containsKey(generatedFile.name)) {
println("[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")
}
}

if (existingFiles.size() == 0) {
throw new Exception("[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")
kkafar marked this conversation as resolved.
Show resolved Hide resolved
}

if (existingFiles.size() > generatedFiles.size()) {
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")
}

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

if (isScreensExampleApp() && isNewArchitectureEnabled()) {
tasks.generateCodegenArtifactsFromSchema.finalizedBy('copyCodegenArtifacts')
}
maciekstosio marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ android.useAndroidX=true
android.enableJetifier=true

kotlin.code.style=official

# Path to codegen artifacts, used for task (copyCodegenArtifacts) that automates copying them to paper destination
maciekstosio marked this conversation as resolved.
Show resolved Hide resolved
codegenArtifactsSource=android/build/generated/source/codegen/java/com/facebook/react/viewmanagers
maciekstosio marked this conversation as resolved.
Show resolved Hide resolved
# Destination to peper path where codegen interfaces should stored and then implemented, so we have consistency in both architectures.
maciekstosio marked this conversation as resolved.
Show resolved Hide resolved
# Used for task (copyCodegenArtifacts) that automates copying those interfaces/delegates when codegen is run
codegenArtifactsPaperDestination=android/src/paper/java/com/facebook/react/viewmanagers/
maciekstosio marked this conversation as resolved.
Show resolved Hide resolved
Loading