Skip to content

Commit

Permalink
allow multiple configuration overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
Morfly committed Nov 1, 2023
1 parent 5975744 commit f66f018
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,26 @@ package io.morfly.airin
data class ConfigurationOverride(val configuration: String)

typealias ConfigurationName = String
typealias ConfigurationOverrideCollection = MutableMap<ConfigurationName, MutableList<ConfigurationOverride>>

interface ConfigurationOverridesHolder {

val configurationOverrides: MutableMap<ConfigurationName, ConfigurationOverride>
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<ConfigurationOverride> = mutableListOf()

fun overrideWith(newConfiguration: String) {
configurationOverrides += ConfigurationOverride(newConfiguration)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import io.morfly.airin.label.BazelLabel
import io.morfly.airin.label.Label

typealias StringLabel = String
typealias DependencyOverridesCollection = MutableMap<StringLabel, MutableMap<ConfigurationName?, DependencyOverride>>
typealias DependencyOverrideCollection = MutableMap<StringLabel, MutableMap<ConfigurationName?, DependencyOverride>>

interface DependencyOverridesHolder {

val dependencyOverrides: DependencyOverridesCollection
val dependencyOverrides: DependencyOverrideCollection

fun onDependency(
label: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConfigurationName, ConfigurationOverride>()
override val configurationOverrides: ConfigurationOverrideCollection = mutableMapOf()

override val addedDependencies = mutableMapOf<ConfigurationName, MutableSet<Label>>()
}
21 changes: 12 additions & 9 deletions airin-core/src/jvmMain/kotlin/io/morfly/airin/PackageDescriptor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ fun PackageDescriptor.transformDependencies(features: List<FeatureContext>): 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) {
Expand All @@ -58,10 +60,11 @@ fun PackageDescriptor.transformDependencies(features: List<FeatureContext>): 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
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ abstract class AndroidBinaryFeature : GradleFeatureComponent() {
onContext<BuildContext>(AndroidLibraryModule.ID_BUILD) {
android_binary {
name = "${packageDescriptor.name}_bin"
dex_shards = 5
incremental_dexing = 1
manifest = "src/main/AndroidManifest.xml"
manifest_values = dict {
Expand Down
8 changes: 4 additions & 4 deletions samples/simple-android/app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
4 changes: 2 additions & 2 deletions samples/simple-android/feature-A/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
4 changes: 2 additions & 2 deletions samples/simple-android/feature-B/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fun SecondScreen(
viewModel: SecondViewModel = hiltViewModel()
) {
Text(
text = "FirstScreen",
text = "Second Screen",
Modifier.clickable { onNextClick() }
)
}
4 changes: 2 additions & 2 deletions samples/simple-android/third_party/maven_dependencies.bzl
Original file line number Diff line number Diff line change
@@ -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",
]
Expand Down

0 comments on commit f66f018

Please sign in to comment.