diff --git a/wire-compiler/src/main/java/com/squareup/wire/WireCompiler.kt b/wire-compiler/src/main/java/com/squareup/wire/WireCompiler.kt index 75b62c76bf..07faec05a3 100644 --- a/wire-compiler/src/main/java/com/squareup/wire/WireCompiler.kt +++ b/wire-compiler/src/main/java/com/squareup/wire/WireCompiler.kt @@ -150,7 +150,8 @@ class WireCompiler internal constructor( emitDeclaredOptions = emitDeclaredOptions, emitAppliedOptions = emitAppliedOptions, ) - } else if (kotlinOut != null) { + } + if (kotlinOut != null) { targets += KotlinTarget( exclusive = kotlinExclusive, outDirectory = kotlinOut, @@ -167,11 +168,13 @@ class WireCompiler internal constructor( escapeKotlinKeywords = kotlinEscapeKeywords, emitProtoReader32 = emitProtoReader32, ) - } else if (swiftOut != null) { + } + if (swiftOut != null) { targets += SwiftTarget( outDirectory = swiftOut, ) - } else if (customOut != null || schemaHandlerFactoryClass != null) { + } + if (customOut != null || schemaHandlerFactoryClass != null) { if (customOut == null || schemaHandlerFactoryClass == null) { throw IllegalArgumentException("Both custom_out and schema_handler_factory_class need to be set") } diff --git a/wire-compiler/src/test/java/com/squareup/wire/WireCompilerTest.kt b/wire-compiler/src/test/java/com/squareup/wire/WireCompilerTest.kt index 93824f703a..85a5a9aa12 100644 --- a/wire-compiler/src/test/java/com/squareup/wire/WireCompilerTest.kt +++ b/wire-compiler/src/test/java/com/squareup/wire/WireCompilerTest.kt @@ -115,6 +115,45 @@ class WireCompilerTest { assertThat(logs).containsExactly("artifactHandled(com.squareup.wire.protos.person.Person, Java)") } + @Test + fun runMultipleTargets() { + val sources = arrayOf("person.proto") + + val args = ArrayList() + args.add(TargetLanguage.JAVA.protoPathArg()) + args.add(TargetLanguage.JAVA.outArg("/".toPath() / testDir)) + args.add(TargetLanguage.KOTLIN.protoPathArg()) + args.add(TargetLanguage.KOTLIN.outArg("/".toPath() / testDir)) + args.add("--no_kotlin_exclusive") + args.add("--dry_run") + args.addAll(sources) + + val logs = mutableListOf() + val logger = object : WireLogger { + override fun artifactHandled(outputPath: Path, qualifiedName: String, targetName: String) { + logs.add("artifactHandled($qualifiedName, $targetName)") + } + override fun artifactSkipped(type: ProtoType, targetName: String) = Unit + override fun unusedRoots(unusedRoots: Set) = Unit + override fun unusedPrunes(unusedPrunes: Set) = Unit + override fun unusedIncludesInTarget(unusedIncludes: Set) = Unit + override fun unusedExcludesInTarget(unusedExcludes: Set) = Unit + } + val fs = fileSystem + val compiler = WireCompiler.forArgs(fs, logger, *args.toTypedArray()) + compiler.compile() + + // We assert nothing has been generated. + assertJavaOutputs(arrayOf()) + assertKotlinOutputs(arrayOf()) + assertSwiftOutputs(arrayOf()) + // But we logged things because we're dry-running. + assertThat(logs).containsExactly( + "artifactHandled(com.squareup.wire.protos.person.Person, Kotlin)", + "artifactHandled(com.squareup.wire.protos.person.Person, Java)", + ) + } + @Test fun testPersonAndroid() { val sources = arrayOf("person.proto") @@ -726,6 +765,9 @@ class WireCompilerTest { private fun assertKotlinOutputs(outputs: Array, suffix: String = "") = assertOutputs(TargetLanguage.KOTLIN, outputs, suffix) + private fun assertSwiftOutputs(outputs: Array, suffix: String = "") = + assertOutputs(TargetLanguage.SWIFT, outputs, suffix) + private fun assertOutputs(target: TargetLanguage, outputs: Array, suffix: String = "") { val filesAfter = paths assertThat(filesAfter.size) @@ -770,6 +812,11 @@ class WireCompilerTest { override fun outArg(testDirPath: Path) = "--kotlin_out=$testDirPath" override fun protoFolderSuffix() = "kotlin" }, + SWIFT { + override fun protoPathArg() = "--proto_path=../wire-tests/src/commonTest/proto/kotlin" + override fun outArg(testDirPath: Path) = "--swift_out=$testDirPath" + override fun protoFolderSuffix() = "swift" + }, ; abstract fun protoPathArg(): String