From 963206a7684bef05f6854c558ff0601eadd7bb72 Mon Sep 17 00:00:00 2001 From: Benoit Quenaudon Date: Fri, 7 Jul 2023 12:09:41 +0200 Subject: [PATCH] WireSchemaTests as MPP module --- wire-bom/build.gradle.kts | 1 + .../wire/kotlin/grpcserver/GoldenTestUtils.kt | 3 +- wire-runtime/build.gradle.kts | 1 - wire-schema-tests/build.gradle.kts | 122 +++++++++++++++--- .../com/squareup/wire/SchemaBuilder.kt | 0 .../com/squareup/wire/WireTestLogger.kt | 0 .../com/squareup/wire/SchemaBuilderTest.kt | 2 +- .../recipes/ErrorReportingSchemaHandler.kt | 0 .../ErrorReportingSchemaHandlerTest.kt | 0 .../squareup/wire/recipes/LogToFileHandler.kt | 0 .../wire/recipes/LogToFileHandlerTest.kt | 0 .../wire/recipes/LogToWireLoggerHandler.kt | 0 .../recipes/LogToWireLoggerHandlerTest.kt | 0 .../squareup/wire/recipes/MarkdownHandler.kt | 0 .../wire/recipes/MarkdownHandlerTest.kt | 0 wire-schema/build.gradle.kts | 59 +++++++++ 16 files changed, 168 insertions(+), 20 deletions(-) rename wire-schema-tests/src/{main/java => commonMain/kotlin}/com/squareup/wire/SchemaBuilder.kt (100%) rename wire-schema-tests/src/{main/java => commonMain/kotlin}/com/squareup/wire/WireTestLogger.kt (100%) rename wire-schema-tests/src/{test/java => commonTest/kotlin}/com/squareup/wire/SchemaBuilderTest.kt (98%) rename wire-schema-tests/src/{test/java => commonTest/kotlin}/com/squareup/wire/recipes/ErrorReportingSchemaHandler.kt (100%) rename wire-schema-tests/src/{test/java => commonTest/kotlin}/com/squareup/wire/recipes/ErrorReportingSchemaHandlerTest.kt (100%) rename wire-schema-tests/src/{test/java => commonTest/kotlin}/com/squareup/wire/recipes/LogToFileHandler.kt (100%) rename wire-schema-tests/src/{test/java => commonTest/kotlin}/com/squareup/wire/recipes/LogToFileHandlerTest.kt (100%) rename wire-schema-tests/src/{test/java => commonTest/kotlin}/com/squareup/wire/recipes/LogToWireLoggerHandler.kt (100%) rename wire-schema-tests/src/{test/java => commonTest/kotlin}/com/squareup/wire/recipes/LogToWireLoggerHandlerTest.kt (100%) rename wire-schema-tests/src/{test/java => jvmTest/kotlin}/com/squareup/wire/recipes/MarkdownHandler.kt (100%) rename wire-schema-tests/src/{test/java => jvmTest/kotlin}/com/squareup/wire/recipes/MarkdownHandlerTest.kt (100%) diff --git a/wire-bom/build.gradle.kts b/wire-bom/build.gradle.kts index 1594c2ac8d..c09e76c3c7 100644 --- a/wire-bom/build.gradle.kts +++ b/wire-bom/build.gradle.kts @@ -22,6 +22,7 @@ dependencies { api(projects.wireSchema) api(projects.wireSchema.group + ":wire-schema-jvm:" + projects.wireSchema.version) api(projects.wireSchemaTests) + api(projects.wireSchemaTests.group + ":wire-schema-jvm:" + projects.wireSchemaTests.version) api(projects.wireSwiftGenerator) } } diff --git a/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/GoldenTestUtils.kt b/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/GoldenTestUtils.kt index 004f736634..48486812a1 100644 --- a/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/GoldenTestUtils.kt +++ b/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/GoldenTestUtils.kt @@ -16,7 +16,6 @@ package com.squareup.wire.kotlin.grpcserver import com.squareup.kotlinpoet.FileSpec -import com.squareup.wire.WireCompiler import java.io.File import okio.buffer import okio.source @@ -25,7 +24,7 @@ import org.assertj.core.api.Assertions object GoldenTestUtils { fun assertFileEquals(expectedFileName: String, spec: FileSpec) { val finalSpec = spec.toBuilder() - .addFileComment(WireCompiler.CODE_GENERATED_BY_WIRE) + .addFileComment("Code generated by Wire protocol buffer compiler, do not edit.") .build() val expected = File("src/test/golden/$expectedFileName").source().buffer().readUtf8() diff --git a/wire-runtime/build.gradle.kts b/wire-runtime/build.gradle.kts index 0fba8be38f..8a54b0690c 100644 --- a/wire-runtime/build.gradle.kts +++ b/wire-runtime/build.gradle.kts @@ -2,7 +2,6 @@ import com.vanniktech.maven.publish.JavadocJar.Dokka import com.vanniktech.maven.publish.KotlinMultiplatform import com.vanniktech.maven.publish.MavenPublishBaseExtension -// apply(plugin = "org.jetbrains.kotlin.multiplatform") plugins { kotlin("multiplatform") id("com.github.gmazzo.buildconfig") diff --git a/wire-schema-tests/build.gradle.kts b/wire-schema-tests/build.gradle.kts index 470430b0a9..94aca09045 100644 --- a/wire-schema-tests/build.gradle.kts +++ b/wire-schema-tests/build.gradle.kts @@ -2,10 +2,8 @@ import com.vanniktech.maven.publish.JavadocJar.Dokka import com.vanniktech.maven.publish.KotlinJvm import com.vanniktech.maven.publish.MavenPublishBaseExtension -// TODO(Benoit) this module can be multiplatform. - plugins { - kotlin("jvm") + kotlin("multiplatform") id("org.jetbrains.dokka") id("com.vanniktech.maven.publish.base").apply(false) } @@ -15,20 +13,112 @@ if (project.rootProject.name == "wire") { apply(plugin = "binary-compatibility-validator") } -dependencies { - api(libs.junit) - api(projects.wireCompiler) - api(projects.wireSchema) - implementation(projects.wireKotlinGenerator) - implementation(projects.wireJavaGenerator) - implementation(projects.wireSwiftGenerator) - implementation(libs.okio.core) - implementation(libs.okio.fakefilesystem) - testImplementation(libs.assertj) - testImplementation(libs.kotlin.test.junit) - testImplementation(projects.wireTestUtils) -} +kotlin { + jvm { + withJava() + } + if (System.getProperty("kjs", "true").toBoolean()) { + js(IR) { + configure(listOf(compilations.getByName("main"), compilations.getByName("test"))) { + tasks.getByName(compileKotlinTaskName) { + kotlinOptions { + moduleKind = "umd" + sourceMap = true + metaInfo = true + } + } + } + nodejs() + browser() + } + } + if (System.getProperty("knative", "true").toBoolean()) { + iosX64() + iosArm64() + iosSimulatorArm64() + // Required to generate tests tasks: https://youtrack.jetbrains.com/issue/KT-26547 + linuxX64() + macosX64() + macosArm64() + mingwX64() + tvosX64() + tvosArm64() + tvosSimulatorArm64() + } + sourceSets { + val commonMain by getting { + dependencies { + api(libs.okio.core) + api(projects.wireSchema) + implementation(libs.okio.fakefilesystem) + } + } + val commonTest by getting { + dependencies { + implementation(libs.kotlin.test.common) + implementation(libs.kotlin.test.annotations) + } + } + val jvmTest by getting { + dependencies { + implementation(libs.assertj) + implementation(libs.kotlin.test.junit) + implementation(projects.wireTestUtils) + } + } + if (System.getProperty("kjs", "true").toBoolean()) { + val jsTest by getting { + dependencies { + implementation(libs.kotlin.test.js) + } + } + } + if (System.getProperty("knative", "true").toBoolean()) { + val nativeMain by creating { + dependsOn(commonMain) + } + val nativeTest by creating { + dependsOn(commonTest) + } + val darwinMain by creating { + dependsOn(commonMain) + } + val iosX64Main by getting + val iosArm64Main by getting + val iosSimulatorArm64Main by getting + val linuxX64Main by getting + val macosX64Main by getting + val macosArm64Main by getting + val mingwX64Main by getting + val tvosX64Main by getting + val tvosArm64Main by getting + val tvosSimulatorArm64Main by getting + val iosX64Test by getting + val iosArm64Test by getting + val iosSimulatorArm64Test by getting + val linuxX64Test by getting + val macosX64Test by getting + val macosArm64Test by getting + val mingwX64Test by getting + val tvosX64Test by getting + val tvosArm64Test by getting + val tvosSimulatorArm64Test by getting + + for (it in listOf(iosX64Main, iosArm64Main, iosSimulatorArm64Main, linuxX64Main, macosX64Main, macosArm64Main, mingwX64Main, tvosX64Main, tvosArm64Main, tvosSimulatorArm64Main)) { + it.dependsOn(nativeMain) + } + + for (it in listOf(iosX64Test, iosArm64Test, iosSimulatorArm64Test, linuxX64Test, macosX64Test, macosArm64Test, mingwX64Test, tvosX64Test, tvosArm64Test, tvosSimulatorArm64Test)) { + it.dependsOn(nativeTest) + } + + for (it in listOf(iosX64Main, iosArm64Main, macosX64Main, macosArm64Main, tvosX64Main, tvosArm64Main)) { + it.dependsOn(darwinMain) + } + } + } +} if (project.rootProject.name == "wire") { configure { diff --git a/wire-schema-tests/src/main/java/com/squareup/wire/SchemaBuilder.kt b/wire-schema-tests/src/commonMain/kotlin/com/squareup/wire/SchemaBuilder.kt similarity index 100% rename from wire-schema-tests/src/main/java/com/squareup/wire/SchemaBuilder.kt rename to wire-schema-tests/src/commonMain/kotlin/com/squareup/wire/SchemaBuilder.kt diff --git a/wire-schema-tests/src/main/java/com/squareup/wire/WireTestLogger.kt b/wire-schema-tests/src/commonMain/kotlin/com/squareup/wire/WireTestLogger.kt similarity index 100% rename from wire-schema-tests/src/main/java/com/squareup/wire/WireTestLogger.kt rename to wire-schema-tests/src/commonMain/kotlin/com/squareup/wire/WireTestLogger.kt diff --git a/wire-schema-tests/src/test/java/com/squareup/wire/SchemaBuilderTest.kt b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/SchemaBuilderTest.kt similarity index 98% rename from wire-schema-tests/src/test/java/com/squareup/wire/SchemaBuilderTest.kt rename to wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/SchemaBuilderTest.kt index 7c1dbf77c4..b1e145495d 100644 --- a/wire-schema-tests/src/test/java/com/squareup/wire/SchemaBuilderTest.kt +++ b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/SchemaBuilderTest.kt @@ -19,7 +19,7 @@ import com.squareup.wire.schema.Location import com.squareup.wire.schema.SchemaException import okio.Path.Companion.toPath import org.assertj.core.api.Assertions.assertThat -import org.junit.Test +import kotlin.test.Test import kotlin.test.assertFailsWith class SchemaBuilderTest { diff --git a/wire-schema-tests/src/test/java/com/squareup/wire/recipes/ErrorReportingSchemaHandler.kt b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandler.kt similarity index 100% rename from wire-schema-tests/src/test/java/com/squareup/wire/recipes/ErrorReportingSchemaHandler.kt rename to wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandler.kt diff --git a/wire-schema-tests/src/test/java/com/squareup/wire/recipes/ErrorReportingSchemaHandlerTest.kt b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandlerTest.kt similarity index 100% rename from wire-schema-tests/src/test/java/com/squareup/wire/recipes/ErrorReportingSchemaHandlerTest.kt rename to wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandlerTest.kt diff --git a/wire-schema-tests/src/test/java/com/squareup/wire/recipes/LogToFileHandler.kt b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToFileHandler.kt similarity index 100% rename from wire-schema-tests/src/test/java/com/squareup/wire/recipes/LogToFileHandler.kt rename to wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToFileHandler.kt diff --git a/wire-schema-tests/src/test/java/com/squareup/wire/recipes/LogToFileHandlerTest.kt b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToFileHandlerTest.kt similarity index 100% rename from wire-schema-tests/src/test/java/com/squareup/wire/recipes/LogToFileHandlerTest.kt rename to wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToFileHandlerTest.kt diff --git a/wire-schema-tests/src/test/java/com/squareup/wire/recipes/LogToWireLoggerHandler.kt b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandler.kt similarity index 100% rename from wire-schema-tests/src/test/java/com/squareup/wire/recipes/LogToWireLoggerHandler.kt rename to wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandler.kt diff --git a/wire-schema-tests/src/test/java/com/squareup/wire/recipes/LogToWireLoggerHandlerTest.kt b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandlerTest.kt similarity index 100% rename from wire-schema-tests/src/test/java/com/squareup/wire/recipes/LogToWireLoggerHandlerTest.kt rename to wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandlerTest.kt diff --git a/wire-schema-tests/src/test/java/com/squareup/wire/recipes/MarkdownHandler.kt b/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/MarkdownHandler.kt similarity index 100% rename from wire-schema-tests/src/test/java/com/squareup/wire/recipes/MarkdownHandler.kt rename to wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/MarkdownHandler.kt diff --git a/wire-schema-tests/src/test/java/com/squareup/wire/recipes/MarkdownHandlerTest.kt b/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/MarkdownHandlerTest.kt similarity index 100% rename from wire-schema-tests/src/test/java/com/squareup/wire/recipes/MarkdownHandlerTest.kt rename to wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/MarkdownHandlerTest.kt diff --git a/wire-schema/build.gradle.kts b/wire-schema/build.gradle.kts index bc1acc27c8..3458ff337b 100644 --- a/wire-schema/build.gradle.kts +++ b/wire-schema/build.gradle.kts @@ -32,6 +32,19 @@ kotlin { browser() } } + if (System.getProperty("knative", "true").toBoolean()) { + iosX64() + iosArm64() + iosSimulatorArm64() + // Required to generate tests tasks: https://youtrack.jetbrains.com/issue/KT-26547 + linuxX64() + macosX64() + macosArm64() + mingwX64() + tvosX64() + tvosArm64() + tvosSimulatorArm64() + } sourceSets { val commonMain by getting { @@ -39,6 +52,8 @@ kotlin { api(projects.wireRuntime) } } + val commonTest by getting { + } val jvmMain by getting { dependencies { api(libs.okio.core) @@ -66,6 +81,50 @@ kotlin { } } } + if (System.getProperty("knative", "true").toBoolean()) { + val nativeMain by creating { + dependsOn(commonMain) + } + val nativeTest by creating { + dependsOn(commonTest) + } + val darwinMain by creating { + dependsOn(commonMain) + } + + val iosX64Main by getting + val iosArm64Main by getting + val iosSimulatorArm64Main by getting + val linuxX64Main by getting + val macosX64Main by getting + val macosArm64Main by getting + val mingwX64Main by getting + val tvosX64Main by getting + val tvosArm64Main by getting + val tvosSimulatorArm64Main by getting + val iosX64Test by getting + val iosArm64Test by getting + val iosSimulatorArm64Test by getting + val linuxX64Test by getting + val macosX64Test by getting + val macosArm64Test by getting + val mingwX64Test by getting + val tvosX64Test by getting + val tvosArm64Test by getting + val tvosSimulatorArm64Test by getting + + for (it in listOf(iosX64Main, iosArm64Main, iosSimulatorArm64Main, linuxX64Main, macosX64Main, macosArm64Main, mingwX64Main, tvosX64Main, tvosArm64Main, tvosSimulatorArm64Main)) { + it.dependsOn(nativeMain) + } + + for (it in listOf(iosX64Test, iosArm64Test, iosSimulatorArm64Test, linuxX64Test, macosX64Test, macosArm64Test, mingwX64Test, tvosX64Test, tvosArm64Test, tvosSimulatorArm64Test)) { + it.dependsOn(nativeTest) + } + + for (it in listOf(iosX64Main, iosArm64Main, macosX64Main, macosArm64Main, tvosX64Main, tvosArm64Main)) { + it.dependsOn(darwinMain) + } + } } }