Skip to content

Commit

Permalink
Merge pull request #2525 from square/bquenaudon.2023-07-07.mpp
Browse files Browse the repository at this point in the history
WireSchemaTests as MPP module
  • Loading branch information
oldergod authored Jul 8, 2023
2 parents a4eabf7 + c5dcc6f commit 2f23076
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
1 change: 0 additions & 1 deletion wire-runtime/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion wire-schema-tests/api/wire-schema-tests.api
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ public final class com/squareup/wire/SchemaBuilder {
public fun <init> ()V
public final fun add (Lokio/Path;Ljava/lang/String;)Lcom/squareup/wire/SchemaBuilder;
public final fun add (Lokio/Path;Ljava/lang/String;Lokio/Path;)Lcom/squareup/wire/SchemaBuilder;
public static synthetic fun add$default (Lcom/squareup/wire/SchemaBuilder;Lokio/Path;Ljava/lang/String;Lokio/Path;ILjava/lang/Object;)Lcom/squareup/wire/SchemaBuilder;
public final fun addProtoPath (Lokio/Path;Ljava/lang/String;)Lcom/squareup/wire/SchemaBuilder;
public final fun build ()Lcom/squareup/wire/schema/Schema;
}
Expand Down
66 changes: 50 additions & 16 deletions wire-schema-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -15,21 +13,57 @@ 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 {
// Required by MavenPublishBaseExtension even though we do not have Java sources.
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()
}
}
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 (project.rootProject.name == "wire") {
configure<MavenPublishBaseExtension> {
configure(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,18 @@ class SchemaBuilder {
* @param name The qualified name of the file.
* @param protoFile The content of the file.
*/
@JvmOverloads
fun add(name: Path, protoFile: String, path: Path = sourcePath): SchemaBuilder {
fun add(name: Path, protoFile: String): SchemaBuilder {
return add(name, protoFile, sourcePath)
}

/**
* Add a file to be loaded into the schema.
*
* @param name The qualified name of the file.
* @param protoFile The content of the file.
* @param path The path on which [name] is based.
*/
fun add(name: Path, protoFile: String, path: Path): SchemaBuilder {
require(name.toString().endsWith(".proto")) {
"unexpected file extension for $name. Proto files should use the '.proto' extension"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions wire-schema/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ kotlin {
browser()
}
}

sourceSets {
val commonMain by getting {
dependencies {
api(projects.wireRuntime)
}
}
val commonTest by getting {
}
val jvmMain by getting {
dependencies {
api(libs.okio.core)
Expand Down Expand Up @@ -69,7 +70,6 @@ kotlin {
}
}


if (project.rootProject.name == "wire") {
configure<MavenPublishBaseExtension> {
configure(
Expand Down

0 comments on commit 2f23076

Please sign in to comment.