Initial commit

This commit is contained in:
fekt
2022-06-30 01:53:12 -04:00
commit 0131016214
703 changed files with 33394 additions and 0 deletions

View File

@@ -0,0 +1,102 @@
import com.android.build.api.dsl.CommonExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
pluginManager.withPlugin("com.android.application") {
project.the<com.android.build.gradle.AppExtension>().apply {
configureBaseExtension()
defaultConfig {
minSdk = project.property("ANDROID_MIN_SDK_VERSION").toString().toInt()
targetSdk = project.property("ANDROID_TARGET_SDK_VERSION").toString().toInt()
// en_XA and ar_XB are pseudolocales for debugging.
// The rest of the locales provides an explicit list of the languages to keep in the
// final app. Doing this will strip out additional locales from libraries like
// Google Play Services and Firebase, which add unnecessary bloat.
resourceConfigurations.addAll(listOf("en", "en-rUS", "en-rGB", "en-rAU", "en_XA", "ar_XB"))
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
if (project.property("IS_USE_TEST_ORCHESTRATOR").toString().toBoolean()) {
testInstrumentationRunnerArguments["clearPackageData"] = "true"
}
}
}
}
pluginManager.withPlugin("com.android.library") {
project.the<com.android.build.gradle.LibraryExtension>().apply {
configureBaseExtension()
defaultConfig {
minSdk = project.property("ANDROID_MIN_SDK_VERSION").toString().toInt()
targetSdk = project.property("ANDROID_TARGET_SDK_VERSION").toString().toInt()
// The last two are for support of pseudolocales in debug builds.
// If we add other localizations, they should be included in this list.
// By explicitly setting supported locales, we strip out unused localizations from third party
// libraries (e.g. play services)
resourceConfigurations.addAll(listOf("en", "en-rUS", "en-rGB", "en-rAU", "en_XA", "ar_XB"))
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("proguard-consumer.txt")
if (project.property("IS_USE_TEST_ORCHESTRATOR").toString().toBoolean()) {
testInstrumentationRunnerArguments["clearPackageData"] = "true"
}
}
testCoverage {
jacocoVersion = project.property("JACOCO_VERSION").toString()
}
}
}
fun com.android.build.gradle.BaseExtension.configureBaseExtension() {
compileSdkVersion(project.property("ANDROID_COMPILE_SDK_VERSION").toString().toInt())
ndkVersion = project.property("ANDROID_NDK_VERSION").toString()
compileOptions {
val javaVersion = JavaVersion.toVersion(project.property("ANDROID_JVM_TARGET").toString())
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}
buildTypes {
getByName("debug").apply {
isTestCoverageEnabled = project.property("IS_ANDROID_INSTRUMENTATION_TEST_COVERAGE_ENABLED")
.toString().toBoolean()
}
}
signingConfigs {
val debugKeystorePath = project.property("ZCASH_DEBUG_KEYSTORE_PATH").toString()
val isExplicitDebugSigningEnabled = !debugKeystorePath.isNullOrBlank()
if (isExplicitDebugSigningEnabled) {
// If this block doesn't execute, the output will still be signed with the default keystore
getByName("debug").apply {
storeFile = File(debugKeystorePath)
}
}
}
testOptions {
animationsDisabled = true
if (project.property("IS_USE_TEST_ORCHESTRATOR").toString().toBoolean()) {
execution = "ANDROIDX_TEST_ORCHESTRATOR"
}
}
if (this is CommonExtension<*, *, *, *>) {
kotlinOptions {
jvmTarget = project.property("ANDROID_JVM_TARGET").toString()
allWarningsAsErrors = project.property("ZCASH_IS_TREAT_WARNINGS_AS_ERRORS").toString().toBoolean()
freeCompilerArgs = freeCompilerArgs + "-opt-in=kotlin.RequiresOptIn" +
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi" + "-opt-in=kotlinx.coroutines.FlowPreview"
}
}
}
fun CommonExtension<*, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
(this as ExtensionAware).extensions.configure("kotlinOptions", block)
}

View File

@@ -0,0 +1,15 @@
//dependencyLocking {
// lockAllConfigurations()
//}
tasks {
register("resolveAll") {
doLast {
configurations.filter {
// Add any custom filtering on the configurations to be resolved
it.isCanBeResolved
}.forEach { it.resolve() }
}
}
}

View File

@@ -0,0 +1,33 @@
// Emulator WTF has min and max values that might differ from our project's
// These are determined by `ew-cli --models`
@Suppress("MagicNumber", "PropertyName", "VariableNaming")
val EMULATOR_WTF_MIN_SDK = 23
@Suppress("MagicNumber", "PropertyName", "VariableNaming")
val EMULATOR_WTF_MAX_SDK = 31
pluginManager.withPlugin("wtf.emulator.gradle") {
project.the<wtf.emulator.EwExtension>().apply {
val tokenString = project.properties["ZCASH_EMULATOR_WTF_API_KEY"].toString()
if (tokenString.isNotEmpty()) {
token.set(tokenString)
}
val libraryMinSdkVersion = run {
val buildMinSdk = project.properties["ANDROID_MIN_SDK_VERSION"].toString().toInt()
buildMinSdk.coerceAtLeast(EMULATOR_WTF_MIN_SDK).toString()
}
val targetSdkVersion = run {
val buildTargetSdk = project.properties["ANDROID_TARGET_SDK_VERSION"].toString().toInt()
buildTargetSdk.coerceAtMost(EMULATOR_WTF_MAX_SDK).toString()
}
devices.set(
listOf(
mapOf("model" to "Pixel2", "version" to libraryMinSdkVersion),
mapOf("model" to "Pixel2", "version" to targetSdkVersion)
)
)
}
}

View File

@@ -0,0 +1,41 @@
plugins {
id("java")
}
val ktlint by configurations.creating
dependencies {
ktlint("com.pinterest:ktlint:${project.property("KTLINT_VERSION")}") {
attributes {
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named<Bundling>(Bundling.EXTERNAL))
}
}
}
tasks {
val editorConfigFile = rootProject.file(".editorconfig")
val ktlintArgs = listOf("**/src/**/*.kt", "!**/build/**.kt", "--editorconfig=$editorConfigFile")
register("ktlint", org.gradle.api.tasks.JavaExec::class) {
description = "Check code style with ktlint"
classpath = ktlint
mainClass.set("com.pinterest.ktlint.Main")
args = ktlintArgs
}
register("ktlintFormat", org.gradle.api.tasks.JavaExec::class) {
// https://github.com/pinterest/ktlint/issues/1195#issuecomment-1009027802
jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
description = "Apply code style formatting with ktlint"
classpath = ktlint
mainClass.set("com.pinterest.ktlint.Main")
args = listOf("-F") + ktlintArgs
}
}
java {
val javaVersion = JavaVersion.toVersion(project.property("ANDROID_JVM_TARGET").toString())
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}

View File

@@ -0,0 +1,47 @@
import java.util.concurrent.TimeUnit
if (isRosetta()) {
logger.warn("This Gradle invocation is running under Rosetta. Use an ARM (aarch64) JDK to " +
"improve performance. One can be downloaded from https://adoptium.net/temurin/releases")
}
@Suppress("MagicNumber")
private val maxTimeoutMillis = 5000L
/**
* This method is safe to call from any operating system or CPU architecture.
*
* @return True if the application is running under Rosetta.
*/
fun isRosetta(): Boolean {
if (System.getProperty("os.name").toLowerCase(java.util.Locale.ROOT).startsWith("mac")) {
// Counterintuitive, but running under Rosetta is reported as Intel64 to the JVM
if (!System.getProperty("os.arch").toLowerCase(java.util.Locale.ROOT).contains("aarch64")) {
val outputValue = Runtime.getRuntime()
.exec("sysctl -in sysctl.proc_translated")
.scanOutputLine()
?.toIntOrNull()
if (1 == outputValue) {
return true
}
}
}
return false
}
fun Process.scanOutputLine(): String? {
var outputString = ""
inputStream.use { inputStream ->
java.util.Scanner(inputStream).useDelimiter("\\A").use { scanner ->
while (scanner.hasNext()) {
outputString = scanner.next()
}
}
}
waitFor(maxTimeoutMillis, TimeUnit.MILLISECONDS)
return outputString.trim()
}