Skip to content

Commit

Permalink
[swift] Ensure imports of parameterized type names are emitted
Browse files Browse the repository at this point in the history
  • Loading branch information
dnkoutso committed Oct 4, 2023
1 parent 2d58614 commit 1a76168
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
22 changes: 22 additions & 0 deletions gen-tests.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,27 @@ val generateSwiftProto3Tests by tasks.creating(JavaExec::class) {
)
}

val generateSwiftProto2ManifestTests by tasks.creating(JavaExec::class) {
val swiftOut = "wire-tests-swift/src/main/swift"
doFirst {
val outFile = file(swiftOut)
outFile.deleteRecursively()
outFile.mkdir()
}

group = "Generate Tests"
description = "Generates Swift classes from the test protos using a manifest"
classpath = wire
mainClass.set("com.squareup.wire.WireCompiler")
args = listOf(
"--proto_path=wire-tests/src/commonTest/proto/kotlin",
"--swift_out=$swiftOut",
"--experimental-module-manifest=wire-tests/src/commonTest/proto/kotlin/swift_modules_manifest.yaml",
// "swift_module_one.proto",
"swift_module_two.proto"
)
}

val generateSwiftProto2Tests by tasks.creating(JavaExec::class) {
val swiftOut = "wire-tests-swift/src/main/swift/"
doFirst {
Expand Down Expand Up @@ -462,6 +483,7 @@ val generateSwiftTests by tasks.creating {
description = "Generates Swift classes from the test protos"
dependsOn(
generateSwiftProto2Tests,
generateSwiftProto2ManifestTests,
generateSwiftProto3Tests,
":wire-runtime-swift:generateTestProtos"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,12 @@ class SwiftGenerator private constructor(
if (typeName is DeclaredTypeName) {
imports.add(typeName.moduleName)
}
// if (field.isRepeated && typeName is ParameterizedTypeName) {
// val declaredTypeName = typeName.typeArguments[0]
// if (declaredTypeName is DeclaredTypeName) {
// imports.add(declaredTypeName.moduleName)
// }
// }

val property = PropertySpec.varBuilder(field.name, field.typeName, visibility)
if (!forStorageType && field.documentation.isNotBlank()) {
Expand Down
24 changes: 24 additions & 0 deletions wire-tests/src/commonTest/proto/kotlin/swift_module_one.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2023 Square Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
syntax = "proto2";

package squareup.protos.kotlin.swift_modules;

enum SwiftModuleOneType {
DO_NOT_USE = 0;
ONE = 1;
TWO = 2;
}
28 changes: 28 additions & 0 deletions wire-tests/src/commonTest/proto/kotlin/swift_module_two.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2023 Square Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
syntax = "proto2";

package squareup.protos.kotlin.swift_modules;

import "swift_module_one.proto";

message SwiftModuleTwoMessage {
optional string name = 1;

message NestedMessage {
repeated SwiftModuleOneType types = 2;
}
}
28 changes: 28 additions & 0 deletions wire-tests/src/commonTest/proto/kotlin/swift_modules_manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Copyright 2023 Square Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#/

# Used between swift_module_one.proto and swift_module_two.proto

---
module_one:
roots:
- squareup.protos.kotlin.swift_modules.SwiftModuleOneType
module_two:
roots:
- squareup.protos.kotlin.swift_modules.SwiftModuleTwoMessage
- squareup.protos.kotlin.swift_modules.SwiftModuleTwoMessage.NestedMessage
dependencies:
- module_one

0 comments on commit 1a76168

Please sign in to comment.