Skip to content

Commit

Permalink
fix(build, android-sdk): refine copy task, task in task file, bump gr…
Browse files Browse the repository at this point in the history
…adle to 8.1.1
  • Loading branch information
varuntandon-ql committed Sep 24, 2023
1 parent 0141c9b commit 4bef471
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 32 deletions.
4 changes: 2 additions & 2 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ tasks:
lint:android:
desc: Lint the android codebase with in-built lint checks
cmds:
- ./gradlew :android-client:lint
- ./gradlew :android-sdk:lint
- ./gradlew :sdks:android:sdk:lint
- ./gradlew :sdks:android:test-app:lint
# database
db:up:
desc: Bring up the local database
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
org.gradle.parallel=true
org.gradle.kotlin.dsl.allWarningsAsErrors=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ coreKtx = "1.12.0"
espressoCore = "3.5.1"
junit = "4.13.2"
junitVersion = "1.1.5"
androidGradlePlugin = "8.1.0"
androidGradlePlugin = "8.1.1"
kotlinVersion = "1.9.0"

[libraries]
Expand Down
5 changes: 0 additions & 5 deletions sdks/android/sdk/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ local.properties
gateway/
promptModels/

# Android Studio generated files and folders
#captures/
#.externalNativeBuild/
#.cxx/

# IntelliJ
.idea/
misc.xml
79 changes: 59 additions & 20 deletions sdks/android/sdk/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
id("org.jetbrains.kotlin.jvm") apply false
}

android {
Expand Down Expand Up @@ -40,46 +41,84 @@ dependencies {
androidTestImplementation(libs.androidx.espresso.core)
}

// directories
private val generatedKotlinDir = "../gen/kt"
private val destinationDir = "src/main/java/com/basemind/client/gateway"
// root directories
private val androidCoreDir = "$rootDir/sdks/android"
private val androidSdkDir = "$androidCoreDir/sdk"
private val androidSdkMainDir = "$androidSdkDir/src/main/java/com/basemind/client"

// directories in focus
private val genKtGatewayDir = "$rootDir/gen/kt/gateway/v1"
private val copyDestinationGatewayDir = "$androidSdkMainDir/gateway"
private val copyDestinationPModelsDir = "$androidSdkMainDir/promptModels"

// tasks
private val taskCopyGenKtToSrc = "copyGeneratedKotlinToSrc"
private val taskCleanGenCopies = "cleanGenCopies"
private val taskDefaultBuild = "build"

// messages
private val descTaskCopyGenKtToSrc = "Copying Generated Kotlin Files from $generatedKotlinDir ..."
private val conclusionTaskCopyGenKtToSrc = "Files copied from %s to $destinationDir!"
private val descTaskCleanGenCopies = "Cleaning the contents from $destinationDir ..."
private val conclusionTaskCleanGenCopies = "Directory \"$destinationDir\" is cleaned!"
private val descTaskCopy = "Copying Generated Kotlin Files from $genKtGatewayDir ..."
private val positiveConclusionTaskCopy = "Files copied from %s to %s"
private val negativeConclusionTaskCopy = "There was an problem copying files from %s to %s"
private val descTaskClean = "Cleaning the contents from %s ..."
private val conclusionTaskClean = "Directory %s is cleaned!"

tasks.register(taskCleanGenCopies) {
println(descTaskCleanGenCopies)

val destDir = project.file(destinationDir)
// Delete the contents of the folder
destDir.deleteRecursively()
println(descTaskClean)

// Optionally, recreate the empty folder if needed
destDir.mkdirs()
deleteContents(project.file(copyDestinationGatewayDir))
println(String.format(conclusionTaskClean, copyDestinationGatewayDir))

println(conclusionTaskCleanGenCopies)
deleteContents(project.file(copyDestinationPModelsDir))
println(String.format(conclusionTaskClean, copyDestinationPModelsDir))
}

tasks.register(taskCopyGenKtToSrc) {
println(descTaskCopyGenKtToSrc)
println(descTaskCopy)

val sourceDir = file(genKtGatewayDir)

// Copy gateway files to the sdk's 'gateway' folder
val copiedGatewayFiles = project.copy {
val destDir = project.file(copyDestinationGatewayDir)

from(sourceDir)
into(destDir)

exclude("**/*Prompt*")
}

val sourceDir = file(generatedKotlinDir)
val destDir = project.file(destinationDir)
printConclusionMessage(copiedGatewayFiles.didWork, sourceDir, copyDestinationGatewayDir)

// Copy promptReq/Res files to the sdk's 'promptModels' folder
val copiedPromptFiles = project.copy {
val destDir = project.file(copyDestinationPModelsDir)

project.copy {
from(sourceDir)
into(destDir)

include("**/*Prompt*")
}

printConclusionMessage(copiedPromptFiles.didWork, sourceDir, copyDestinationPModelsDir)
}

fun deleteContents(file: File) {
// Delete the contents of the folder
file.deleteRecursively()

// Optionally, recreate the empty folder if needed
file.mkdirs()
}

fun printConclusionMessage(copyStatus: Boolean, sourceDir: File, destinationDir: String) {
val conclusionMessage = if (copyStatus) {
positiveConclusionTaskCopy
} else {
negativeConclusionTaskCopy
}

println(String.format(conclusionTaskCopyGenKtToSrc, sourceDir))
println(String.format(conclusionMessage, sourceDir, destinationDir))
}

tasks.named(taskDefaultBuild) {
Expand Down
3 changes: 0 additions & 3 deletions sdks/android/test-app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ build/
local.properties

# Android Studio generated files and folders
#captures/
#.externalNativeBuild/
#.cxx/
*.apk
output.json

Expand Down
Empty file.

0 comments on commit 4bef471

Please sign in to comment.