Skip to content

Commit

Permalink
Migrate to default hierarchy templates (#1668)
Browse files Browse the repository at this point in the history
This automatically infers the intermediate source sets that we were previously defining manually.
  • Loading branch information
JakeWharton authored Nov 6, 2023
1 parent 4ed92bc commit dfa7cb0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,44 +45,9 @@ fun addAllTargets(project: Project, skipJs: Boolean = false) {
macosArm64()
macosX64()

val commonMain = sourceSets.getByName("commonMain")
val commonTest = sourceSets.getByName("commonTest")

val nativeMain = sourceSets.create("nativeMain").apply {
dependsOn(commonMain)
}
val nativeTest = sourceSets.create("nativeTest").apply {
dependsOn(commonTest)
}

val iosMain = sourceSets.create("iosMain").apply {
dependsOn(nativeMain)
}
val iosTest = sourceSets.create("iosTest").apply {
dependsOn(nativeTest)
}

val macosMain = sourceSets.create("macosMain").apply {
dependsOn(nativeMain)
}
val macosTest = sourceSets.create("macosTest").apply {
dependsOn(nativeTest)
}

targets.all { target ->
// Some Kotlin targets do not have this property, but native ones always will.
if (target.platformType.name == "native") {
if (target.name.startsWith("ios")) {
target.compilations.getByName("main").defaultSourceSet.dependsOn(iosMain)
target.compilations.getByName("test").defaultSourceSet.dependsOn(iosTest)
} else if (target.name.startsWith("macos")) {
target.compilations.getByName("main").defaultSourceSet.dependsOn(macosMain)
target.compilations.getByName("test").defaultSourceSet.dependsOn(macosTest)
} else {
throw AssertionError("Unknown target ${target.name}")
}
}
}
// This will happen by default, but we explicitly invoke it so that projects can add custom
// source sets that depend on the ones produced as a result of these defaults.
applyDefaultHierarchyTemplate()
}
}
}
10 changes: 0 additions & 10 deletions samples/emoji-search/presenter-treehouse/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@ kotlin {
implementation projects.samples.emojiSearch.schema.compose.protocol
}
}

iosMain {
dependsOn(commonMain)
}
targets.all { target ->
// Some Kotlin targets do not have this property, but native ones always will.
if (target.hasProperty('platformType') && target.platformType.name == "native") {
target.compilations.main.defaultSourceSet.dependsOn(sourceSets.iosMain)
}
}
}
}

Expand Down

0 comments on commit dfa7cb0

Please sign in to comment.