From f66f018ec330c04d7b96ed92ff9bf7f70e0acb8c Mon Sep 17 00:00:00 2001 From: Pavlo Stavytskyi Date: Wed, 1 Nov 2023 10:13:08 -0700 Subject: [PATCH] allow multiple configuration overrides --- .../airin/ConfigurationOverridesHolder.kt | 15 ++++++++----- .../morfly/airin/DependencyOverridesHolder.kt | 4 ++-- .../kotlin/io/morfly/airin/FeatureContext.kt | 4 ++-- .../io/morfly/airin/PackageDescriptor.kt | 21 +++++++++++-------- .../airin/feature/AndroidBinaryFeature.kt | 1 - samples/simple-android/app/BUILD.bazel | 8 +++---- samples/simple-android/feature-A/BUILD.bazel | 4 ++-- samples/simple-android/feature-B/BUILD.bazel | 4 ++-- .../airin/sample/featureB/ui/SecondScreen.kt | 2 +- .../third_party/maven_dependencies.bzl | 4 ++-- 10 files changed, 37 insertions(+), 30 deletions(-) diff --git a/airin-core/src/jvmMain/kotlin/io/morfly/airin/ConfigurationOverridesHolder.kt b/airin-core/src/jvmMain/kotlin/io/morfly/airin/ConfigurationOverridesHolder.kt index 073d5ce1..252d57cd 100644 --- a/airin-core/src/jvmMain/kotlin/io/morfly/airin/ConfigurationOverridesHolder.kt +++ b/airin-core/src/jvmMain/kotlin/io/morfly/airin/ConfigurationOverridesHolder.kt @@ -3,21 +3,26 @@ package io.morfly.airin data class ConfigurationOverride(val configuration: String) typealias ConfigurationName = String +typealias ConfigurationOverrideCollection = MutableMap> interface ConfigurationOverridesHolder { - val configurationOverrides: MutableMap + val configurationOverrides: ConfigurationOverrideCollection fun onConfiguration( configuration: String, - override: ConfigurationOverrideContext.() -> ConfigurationOverride + override: ConfigurationOverrideContext.() -> Unit ) { - configurationOverrides[configuration] = ConfigurationOverrideContext().override() + val overrides = ConfigurationOverrideContext().apply(override).configurationOverrides + configurationOverrides.getOrPut(configuration, ::mutableListOf) += overrides } } class ConfigurationOverrideContext { - fun overrideWith(newConfiguration: String): ConfigurationOverride = - ConfigurationOverride(newConfiguration) + val configurationOverrides: MutableList = mutableListOf() + + fun overrideWith(newConfiguration: String) { + configurationOverrides += ConfigurationOverride(newConfiguration) + } } diff --git a/airin-core/src/jvmMain/kotlin/io/morfly/airin/DependencyOverridesHolder.kt b/airin-core/src/jvmMain/kotlin/io/morfly/airin/DependencyOverridesHolder.kt index aebc21c8..7ab6addc 100644 --- a/airin-core/src/jvmMain/kotlin/io/morfly/airin/DependencyOverridesHolder.kt +++ b/airin-core/src/jvmMain/kotlin/io/morfly/airin/DependencyOverridesHolder.kt @@ -4,11 +4,11 @@ import io.morfly.airin.label.BazelLabel import io.morfly.airin.label.Label typealias StringLabel = String -typealias DependencyOverridesCollection = MutableMap> +typealias DependencyOverrideCollection = MutableMap> interface DependencyOverridesHolder { - val dependencyOverrides: DependencyOverridesCollection + val dependencyOverrides: DependencyOverrideCollection fun onDependency( label: String, diff --git a/airin-core/src/jvmMain/kotlin/io/morfly/airin/FeatureContext.kt b/airin-core/src/jvmMain/kotlin/io/morfly/airin/FeatureContext.kt index 1afa0a2f..9ef9ecf0 100644 --- a/airin-core/src/jvmMain/kotlin/io/morfly/airin/FeatureContext.kt +++ b/airin-core/src/jvmMain/kotlin/io/morfly/airin/FeatureContext.kt @@ -9,9 +9,9 @@ class FeatureContext : ModifiersHolder, DependencyOverridesHolder, Configuration override val modifiers: ModifierCollection = linkedMapOf() - override val dependencyOverrides: DependencyOverridesCollection = mutableMapOf() + override val dependencyOverrides: DependencyOverrideCollection = mutableMapOf() - override val configurationOverrides = mutableMapOf() + override val configurationOverrides: ConfigurationOverrideCollection = mutableMapOf() override val addedDependencies = mutableMapOf>() } diff --git a/airin-core/src/jvmMain/kotlin/io/morfly/airin/PackageDescriptor.kt b/airin-core/src/jvmMain/kotlin/io/morfly/airin/PackageDescriptor.kt index 9f06144e..b64324d1 100644 --- a/airin-core/src/jvmMain/kotlin/io/morfly/airin/PackageDescriptor.kt +++ b/airin-core/src/jvmMain/kotlin/io/morfly/airin/PackageDescriptor.kt @@ -36,14 +36,16 @@ fun PackageDescriptor.transformDependencies(features: List): Map for (dependency in labels) { val overrides = feature.dependencyOverrides[dependency.asComparable().toString()] val depOverride = overrides?.get(configuration) ?: overrides?.get(null) - val configOverride = feature.configurationOverrides[configuration] + val configOverrides = feature.configurationOverrides[configuration] if (depOverride is DependencyOverride.Override) { - val config = depOverride.configuration - ?: configOverride?.configuration + val configs = depOverride.configuration?.let(::listOf) + ?: configOverrides?.map { it.configuration } ?: continue - val dep = depOverride.label - transformedDependencies.getOrPut(config, ::mutableSetOf) += dep + for (config in configs) { + val dep = depOverride.label + transformedDependencies.getOrPut(config, ::mutableSetOf) += dep + } } if (depOverride != null) { @@ -58,10 +60,11 @@ fun PackageDescriptor.transformDependencies(features: List): Map for (dependency in labels) { if (dependency in processedDependencies[configuration].orEmpty()) continue - val configOverride = feature.configurationOverrides[configuration] - val config = configOverride?.configuration - ?: continue - transformedDependencies.getOrPut(config, ::mutableSetOf) += dependency + val configOverrides = feature.configurationOverrides[configuration] + for (override in configOverrides.orEmpty()) { + val config = override.configuration + transformedDependencies.getOrPut(config, ::mutableSetOf) += dependency + } } } } diff --git a/airin-gradle-android/src/main/kotlin/io/morfly/airin/feature/AndroidBinaryFeature.kt b/airin-gradle-android/src/main/kotlin/io/morfly/airin/feature/AndroidBinaryFeature.kt index 31534f8c..2f5047bd 100644 --- a/airin-gradle-android/src/main/kotlin/io/morfly/airin/feature/AndroidBinaryFeature.kt +++ b/airin-gradle-android/src/main/kotlin/io/morfly/airin/feature/AndroidBinaryFeature.kt @@ -19,7 +19,6 @@ abstract class AndroidBinaryFeature : GradleFeatureComponent() { onContext(AndroidLibraryModule.ID_BUILD) { android_binary { name = "${packageDescriptor.name}_bin" - dex_shards = 5 incremental_dexing = 1 manifest = "src/main/AndroidManifest.xml" manifest_values = dict { diff --git a/samples/simple-android/app/BUILD.bazel b/samples/simple-android/app/BUILD.bazel index 4ac076fd..5cc06fa7 100644 --- a/samples/simple-android/app/BUILD.bazel +++ b/samples/simple-android/app/BUILD.bazel @@ -10,15 +10,15 @@ kt_android_library( visibility = ["//visibility:public"], deps = [ "//:hilt-android", + "//feature-A:feature-A", + "//feature-B:feature-B", + artifact("androidx.activity:activity-compose"), + artifact("androidx.compose.material3:material3"), artifact("androidx.compose.ui:ui"), artifact("androidx.compose.ui:ui-graphics"), artifact("androidx.compose.ui:ui-tooling-preview"), - artifact("androidx.compose.material3:material3"), - "//feature-A:feature-A", - "//feature-B:feature-B", artifact("androidx.core:core-ktx"), artifact("androidx.lifecycle:lifecycle-runtime-ktx"), - artifact("androidx.activity:activity-compose"), artifact("androidx.navigation:navigation-compose"), ], plugins = ["//third_party:jetpack_compose_compiler_plugin"], diff --git a/samples/simple-android/feature-A/BUILD.bazel b/samples/simple-android/feature-A/BUILD.bazel index 9c680d17..ca917095 100644 --- a/samples/simple-android/feature-A/BUILD.bazel +++ b/samples/simple-android/feature-A/BUILD.bazel @@ -10,12 +10,12 @@ kt_android_library( visibility = ["//visibility:public"], deps = [ "//:hilt-android", + artifact("androidx.compose.material3:material3"), artifact("androidx.compose.ui:ui"), artifact("androidx.compose.ui:ui-graphics"), artifact("androidx.compose.ui:ui-tooling-preview"), - artifact("androidx.compose.material3:material3"), - artifact("androidx.navigation:navigation-compose"), artifact("androidx.hilt:hilt-navigation-compose"), + artifact("androidx.navigation:navigation-compose"), ], plugins = ["//third_party:jetpack_compose_compiler_plugin"], ) diff --git a/samples/simple-android/feature-B/BUILD.bazel b/samples/simple-android/feature-B/BUILD.bazel index dcf08545..09f28fb3 100644 --- a/samples/simple-android/feature-B/BUILD.bazel +++ b/samples/simple-android/feature-B/BUILD.bazel @@ -10,12 +10,12 @@ kt_android_library( visibility = ["//visibility:public"], deps = [ "//:hilt-android", + artifact("androidx.compose.material3:material3"), artifact("androidx.compose.ui:ui"), artifact("androidx.compose.ui:ui-graphics"), artifact("androidx.compose.ui:ui-tooling-preview"), - artifact("androidx.compose.material3:material3"), - artifact("androidx.navigation:navigation-compose"), artifact("androidx.hilt:hilt-navigation-compose"), + artifact("androidx.navigation:navigation-compose"), ], plugins = ["//third_party:jetpack_compose_compiler_plugin"], ) diff --git a/samples/simple-android/feature-B/src/main/kotlin/io/morfly/airin/sample/featureB/ui/SecondScreen.kt b/samples/simple-android/feature-B/src/main/kotlin/io/morfly/airin/sample/featureB/ui/SecondScreen.kt index f11f830e..a0f572e2 100644 --- a/samples/simple-android/feature-B/src/main/kotlin/io/morfly/airin/sample/featureB/ui/SecondScreen.kt +++ b/samples/simple-android/feature-B/src/main/kotlin/io/morfly/airin/sample/featureB/ui/SecondScreen.kt @@ -13,7 +13,7 @@ fun SecondScreen( viewModel: SecondViewModel = hiltViewModel() ) { Text( - text = "FirstScreen", + text = "Second Screen", Modifier.clickable { onNextClick() } ) } \ No newline at end of file diff --git a/samples/simple-android/third_party/maven_dependencies.bzl b/samples/simple-android/third_party/maven_dependencies.bzl index a06e62f2..a03a7217 100644 --- a/samples/simple-android/third_party/maven_dependencies.bzl +++ b/samples/simple-android/third_party/maven_dependencies.bzl @@ -1,11 +1,11 @@ MAVEN_ARTIFACTS = [ + "androidx.activity:activity-compose:1.8.0", + "androidx.compose.material3:material3:1.1.1", "androidx.compose.ui:ui:1.4.3", "androidx.compose.ui:ui-graphics:1.4.3", "androidx.compose.ui:ui-tooling-preview:1.4.3", - "androidx.compose.material3:material3:1.1.1", "androidx.core:core-ktx:1.12.0", "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1", - "androidx.activity:activity-compose:1.8.0", "androidx.navigation:navigation-compose:2.6.0", "androidx.hilt:hilt-navigation-compose:1.0.0", ]