Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewparmet committed Dec 15, 2024
1 parent 6ccf5b0 commit 40650bd
Show file tree
Hide file tree
Showing 9 changed files with 2,225 additions and 12 deletions.
7 changes: 6 additions & 1 deletion extensions/protokt-extensions-lite/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ protokt {

kotlin {
sourceSets {
val commonMain by getting {}
// todo: not sure why this is needed
val commonMain by getting {
dependencies {
api(project(":protokt-core-lite"))
}
}

val jvmMain by getting {
dependencies {
Expand Down
3 changes: 3 additions & 0 deletions extensions/protokt-extensions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ kotlin {
val commonMain by getting {
dependencies {
api(project(":extensions:protokt-extensions-lite"))

// todo: not sure why this is needed
api(project(":protokt-core"))
}
}
}
Expand Down
2,175 changes: 2,175 additions & 0 deletions gradle-plugin-integration-test/kotlin-js-store/yarn.lock

Large diffs are not rendered by default.

19 changes: 8 additions & 11 deletions gradle-plugin-integration-test/multiplatform/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
* limitations under the License.
*/

import protokt.v1.gradle.ProtoktExtension
import protokt.v1.gradle.ProtoktPlugin
import protokt.v1.gradle.protoktExtensions

plugins {
kotlin("multiplatform")
id("com.toasttab.protokt")
}

kotlin {
Expand All @@ -45,7 +44,12 @@ kotlin {
}

sourceSets {
val commonMain by getting {}
val commonMain by getting {
dependencies {
// todo: not sure why this is needed
implementation("com.toasttab.protokt:protokt-core:$version")
}
}

val commonTest by getting {
dependencies {
Expand Down Expand Up @@ -87,13 +91,6 @@ tasks.named<Test>("jvmTest") {
useJUnitPlatform()
}

// awkward that we have to apply the plugin after source sets are configured
apply<ProtoktPlugin>()

configure<ProtoktExtension> {
formatOutput = false // https://github.com/pinterest/ktlint/issues/1195
}

dependencies {
protoktExtensions("com.toasttab.protokt:protokt-extensions:$version")
}
Expand All @@ -114,6 +111,6 @@ java {

kotlin {
jvmToolchain {
(this as JavaToolchainSpec).languageVersion.set(JavaLanguageVersion.of(System.getProperty("java-integration.version", libs.versions.java.get()).toInt()))
languageVersion.set(JavaLanguageVersion.of(System.getProperty("java-integration.version", libs.versions.java.get()).toInt()))
}
}
4 changes: 4 additions & 0 deletions gradle-plugin-integration-test/wrapper-types/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ java {

kotlin {
jvmToolchain(libs.versions.java.get().toInt())

compilerOptions {
freeCompilerArgs.add("-Xsuppress-version-warnings")
}
}
7 changes: 7 additions & 0 deletions protokt-reflect/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ localProtokt(false)

kotlin {
sourceSets {
// todo: not sure why this is needed
val commonMain by getting {
dependencies {
api(project(":protokt-core"))
}
}

val jvmMain by getting {
dependencies {
api(project(":protokt-core"))
Expand Down
12 changes: 12 additions & 0 deletions shared-src/gradle-plugin/protokt/v1/gradle/ProtoktBuild.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.gradle.api.Project
import org.gradle.api.artifacts.Dependency
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.file.SourceDirectorySet
import org.gradle.api.logging.LogLevel
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.jvm.tasks.Jar
Expand All @@ -48,6 +49,8 @@ const val EXTENSIONS = "protoktExtensions"

const val TEST_EXTENSIONS = "testProtoktExtensions"

private val level = LogLevel.QUIET

internal fun configureProtokt(
project: Project,
protoktVersion: Any?,
Expand Down Expand Up @@ -97,6 +100,7 @@ private fun Project.createExtensionConfigurationsAndConfigureProtobuf(
}

pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
logger.log(level, "Configuring protokt for Kotlin multiplatform")
configureProtobufPlugin(project, ext, disableJava, KotlinTarget.MultiplatformCommon, resolveBinary())
linkGenerateProtoToSourceCompileForKotlinMpp("commonMain", "commonTest")

Expand All @@ -105,6 +109,7 @@ private fun Project.createExtensionConfigurationsAndConfigureProtobuf(
.targets
.filterNot { it.targetName == "metadata" }
.forEach {
logger.log(level, "Handling Kotlin multiplatform target {}", it.targetName)
configureProtobufPlugin(project, ext, disableJava, KotlinTarget.fromString("${it.targetName}-mp"), resolveBinary())
configureProtoktConfigurations(KotlinMultiplatformExtension::class, "${it.targetName}Main", "${it.targetName}Test")
linkGenerateProtoToSourceCompileForKotlinMpp("${it.targetName}Main", "${it.targetName}Test")
Expand All @@ -117,11 +122,13 @@ private fun Project.createExtensionConfigurationsAndConfigureProtobuf(
}

pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
logger.log(level, "Configuring protokt for Kotlin JVM")
configureProtobufPlugin(project, ext, disableJava, KotlinTarget.Jvm, resolveBinary())
otherwise()
}

pluginManager.withPlugin("org.jetbrains.kotlin.android") {
logger.log(level, "Configuring protokt for Kotlin Android")
configureProtobufPlugin(project, ext, disableJava, KotlinTarget.Android, resolveBinary())
otherwise()
}
Expand All @@ -133,6 +140,8 @@ private fun Project.linkGenerateProtoToSourceCompileForKotlinMpp(mainSourceSetNa

tasks.withType<Jar> {
from(fileTree("${layout.buildDirectory.get()}/extracted-protos/main"))

// see also multiplatform-published-proto-conventions for jsProcessResources handling of the same issue
duplicatesStrategy = DuplicatesStrategy.EXCLUDE // TODO: figure out how to get rid of this
}
}
Expand All @@ -144,8 +153,11 @@ private fun Project.linkGenerateProtoTasksAndIncludeGeneratedSource(sourceSetNam

extension.generateProtoTasks.ofSourceSet(protoSourceSetRoot).forEach { genProtoTask ->
configureSourceSets(sourceSetName, protoSourceSetRoot, genProtoTask)

// todo: it would be better to avoid this by making the outputs of genProtoTask an input of the correct compile task
tasks.withType<AbstractKotlinCompile<*>> {
if ((test && name.contains("Test")) || (!test && !name.contains("Test"))) {
logger.log(level, "Making task {} a dependency of {}", genProtoTask.name, name)
dependsOn(genProtoTask)
}
}
Expand Down
7 changes: 7 additions & 0 deletions third-party/proto-google-common-protos-lite/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ dependencies {

kotlin {
sourceSets {
// todo: not sure why this is needed
val commonMain by getting {
dependencies {
api(project(":protokt-core-lite"))
}
}

val commonTest by getting {
dependencies {
implementation(kotlin("test"))
Expand Down
3 changes: 3 additions & 0 deletions third-party/proto-google-common-protos/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ kotlin {
val commonMain by getting {
dependencies {
api(project(":third-party:proto-google-common-protos-lite"))

// todo: not sure why this is needed
api(project(":protokt-core"))
}
}

Expand Down

0 comments on commit 40650bd

Please sign in to comment.