mirror of
https://github.com/servo/servo.git
synced 2025-09-30 08:39:16 +01:00
Conversion to Gradle KTS (#33772)
* Convert settings.gradle to Kotlin Script Stage 1 of #33742 Signed-off-by: clocks <doomsdayrs@gmail.com> * servoview-local: Convert build.gradle to Kotlin Script Stage 1 of #33742 Signed-off-by: clocks <doomsdayrs@gmail.com> * Convert build.gradle to Kotlin Script This was a trickier one, as I wanted to maintain compatibility with the rest of the files while facilitating this migration. Closures are annoying, another annoyance of loosely typed languages in an OOP project. Migration of child build scripts will require the reverse code and or migration of this scripts functions to kotlin lambdas / functions (which are just jvm functions). Code based off of the following guide. https://docs.gradle.org/current/userguide/kotlin_dsl.html#groovy_closures_from_kotlin Stage 1 of #33742 Signed-off-by: clocks <doomsdayrs@gmail.com> * servoapp: Convert build.gradle to Kotlin Script Migrated deprecated API usages. There are two more, but ignored for now. ("splits.density", "capitalize") Stage 1 of #33742 Signed-off-by: clocks <doomsdayrs@gmail.com> * servoview: Convert build.gradle to Kotlin Script Migrated deprecated API usages. There are two more, but ignored for now. ("splits.density", "capitalize") Stage 1 of #33742 Signed-off-by: clocks <doomsdayrs@gmail.com> * servoview: Replace ResourceGroovyMethods with Kotlin File.walk Signed-off-by: clocks <doomsdayrs@gmail.com> * Replace Groovy Closures with Kotlin Lambda types Stage 1 of #33742 Signed-off-by: clocks <doomsdayrs@gmail.com> * Move Utility fields to buildSrc Using extra fields is quite annoying and makes it hard to maintain API stability. "buildSrc" is designed for this task, and thus is being used for said task. This means that when editing build.gradle files in an Android Studio, there is a direct reference to the source of a function. (Easier time referring to documentation, source of function, etc). More information here: https://docs.gradle.org/current/userguide/sharing_build_logic_between_subprojects.html Stage 1 of #33742 Signed-off-by: clocks <doomsdayrs@gmail.com> * Sync target SDK to 33 Signed-off-by: clocks <doomsdayrs@gmail.com> * Make Notification actions immutable. Otherwise android lint will be upset. Signed-off-by: clocks <doomsdayrs@gmail.com> * Move dependencies from servoview to servoapp ServoView does not use them. Signed-off-by: clocks <doomsdayrs@gmail.com> * Add POST_NOTIFICATIONS to manifest Signed-off-by: clocks <doomsdayrs@gmail.com> * Add host to intent-filter Use "*" for any host, lets hope this works. Signed-off-by: clocks <doomsdayrs@gmail.com> * Solve ndkBuild tasks not being linked The problem stems from something something groovy wishy washy unclear execution order something Kotlin explicit execution order. Merge tasks exist after the project is evaluated. The problem is that simply running afterEvaluate causes an ConcurrentModificationException. This is because of creating a new task while looping over existing tasks. To remedy this we simply filter the tasks first, than create and link the new task. Signed-off-by: clocks <doomsdayrs@gmail.com> * Add documentation to why some functions are extensions to Project Signed-off-by: clocks <doomsdayrs@gmail.com> * android: drop the host directives from AndroidManifest.xml Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com> --------- Signed-off-by: clocks <doomsdayrs@gmail.com> Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
This commit is contained in:
parent
0d7fa75447
commit
cc6f7c5bc4
18 changed files with 602 additions and 569 deletions
2
support/android/apk/buildSrc/.gitignore
vendored
Normal file
2
support/android/apk/buildSrc/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.gradle/
|
||||
build/
|
7
support/android/apk/buildSrc/build.gradle.kts
Normal file
7
support/android/apk/buildSrc/build.gradle.kts
Normal file
|
@ -0,0 +1,7 @@
|
|||
plugins {
|
||||
`kotlin-dsl`
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
15
support/android/apk/buildSrc/src/main/kotlin/Android.kt
Normal file
15
support/android/apk/buildSrc/src/main/kotlin/Android.kt
Normal file
|
@ -0,0 +1,15 @@
|
|||
import java.io.File
|
||||
|
||||
fun getSigningKeyInfo(): Map<String, Any>? {
|
||||
val storeFilePath = System.getenv("APK_SIGNING_KEY_STORE_PATH")
|
||||
return if (storeFilePath != null) {
|
||||
mapOf(
|
||||
"storeFile" to File(storeFilePath),
|
||||
"storePassword" to System.getenv("APK_SIGNING_KEY_STORE_PASS"),
|
||||
"keyAlias" to System.getenv("APK_SIGNING_KEY_ALIAS"),
|
||||
"keyPassword" to System.getenv("APK_SIGNING_KEY_PASS"),
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
71
support/android/apk/buildSrc/src/main/kotlin/Interop.kt
Normal file
71
support/android/apk/buildSrc/src/main/kotlin/Interop.kt
Normal file
|
@ -0,0 +1,71 @@
|
|||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.Project
|
||||
import java.io.File
|
||||
import java.util.Locale
|
||||
import java.util.Properties
|
||||
|
||||
/*
|
||||
Some functions are extensions to the Project class, as to allow access to its public members.
|
||||
*/
|
||||
|
||||
fun Project.getTargetDir(debug: Boolean, arch: String): String {
|
||||
val basePath = project.rootDir.parentFile.parentFile.parentFile.absolutePath
|
||||
return basePath + "/target/android/" + getSubTargetDir(debug, arch)
|
||||
}
|
||||
|
||||
fun Project.getNativeTargetDir(debug: Boolean, arch: String): String {
|
||||
val basePath = project.rootDir.parentFile.parentFile.parentFile.absolutePath
|
||||
return basePath + "/target/" + getSubTargetDir(debug, arch)
|
||||
}
|
||||
|
||||
fun getSubTargetDir(debug: Boolean, arch: String): String {
|
||||
return getRustTarget(arch) + "/" + if (debug) "debug" else "release"
|
||||
}
|
||||
|
||||
fun Project.getJniLibsPath(debug: Boolean, arch: String): String =
|
||||
getTargetDir(debug, arch) + "/jniLibs"
|
||||
|
||||
fun getRustTarget(arch: String): String {
|
||||
return when (arch.lowercase(Locale.getDefault())) {
|
||||
"armv7" -> "armv7-linux-androideabi"
|
||||
"arm64" -> "aarch64-linux-android"
|
||||
"x86" -> "i686-linux-android"
|
||||
"x64" -> "x86_64-linux-android"
|
||||
else -> throw GradleException("Invalid target architecture $arch")
|
||||
}
|
||||
}
|
||||
|
||||
fun getNDKAbi(arch: String): String {
|
||||
return when (arch.lowercase(Locale.getDefault())) {
|
||||
"armv7" -> "armeabi-v7a"
|
||||
"arm64" -> "arm64-v8a"
|
||||
"x86" -> "x86"
|
||||
"x64" -> "x86_64"
|
||||
else -> throw GradleException("Invalid target architecture $arch")
|
||||
}
|
||||
}
|
||||
|
||||
fun Project.getNdkDir(): String {
|
||||
// Read environment variable used in rust build system
|
||||
var ndkRoot = System.getenv("ANDROID_NDK_ROOT")
|
||||
if (ndkRoot == null) {
|
||||
// Fallback to ndkDir in local.properties
|
||||
val rootDir = project.rootDir
|
||||
val localProperties = File(rootDir, "local.properties")
|
||||
val properties = Properties()
|
||||
localProperties.inputStream().use { instr ->
|
||||
properties.load(instr)
|
||||
}
|
||||
|
||||
ndkRoot = properties.getProperty("ndk.dir")
|
||||
}
|
||||
|
||||
val ndkDir = if (ndkRoot != null) File(ndkRoot) else null
|
||||
if (ndkDir == null || !ndkDir.exists()) {
|
||||
throw GradleException(
|
||||
"Please set a valid ANDROID_NDK_ROOT environment variable " +
|
||||
"or ndk.dir path in local.properties file"
|
||||
)
|
||||
}
|
||||
return ndkDir.absolutePath
|
||||
}
|
20
support/android/apk/buildSrc/src/main/kotlin/VersionCode.kt
Normal file
20
support/android/apk/buildSrc/src/main/kotlin/VersionCode.kt
Normal file
|
@ -0,0 +1,20 @@
|
|||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
|
||||
// Generate unique version code based on the build date and time to support nightly
|
||||
// builds.
|
||||
//
|
||||
// The version scheme is currently: yyyyMMddXX
|
||||
// where
|
||||
// yyyy is the 4 digit year (e.g 2024)
|
||||
// MMdd is the 2 digit month followed by 2 digit day (e.g 0915 for September 15)
|
||||
// XX is currently hardcoded to 00, but can be used to distinguish multiple builds within
|
||||
// the same day.
|
||||
//
|
||||
// TODO: check if this interferes with caching of local builds and add option to use
|
||||
// a static version.
|
||||
val today = Date()
|
||||
|
||||
val versionCodeString: String = SimpleDateFormat("yyyyMMdd00").format(today)
|
||||
|
||||
val generatedVersionCode = versionCodeString.toInt()
|
Loading…
Add table
Add a link
Reference in a new issue