Skip to content

Commit

Permalink
Use two different folders as output for Swift generated code as they …
Browse files Browse the repository at this point in the history
…erase each other
  • Loading branch information
dnkoutso committed Oct 4, 2023
1 parent 1a76168 commit ad5bf1e
Show file tree
Hide file tree
Showing 35 changed files with 224 additions and 10 deletions.
8 changes: 4 additions & 4 deletions gen-tests.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ val generateSwiftProto3Tests by tasks.creating(JavaExec::class) {
}

val generateSwiftProto2ManifestTests by tasks.creating(JavaExec::class) {
val swiftOut = "wire-tests-swift/src/main/swift"
val swiftOut = "wire-tests-swift/src/main/swift/manifest"
doFirst {
val outFile = file(swiftOut)
outFile.deleteRecursively()
Expand All @@ -430,13 +430,13 @@ val generateSwiftProto2ManifestTests by tasks.creating(JavaExec::class) {
"--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_one.proto",
"swift_module_two.proto"
)
}

val generateSwiftProto2Tests by tasks.creating(JavaExec::class) {
val swiftOut = "wire-tests-swift/src/main/swift/"
val swiftOut = "wire-tests-swift/src/main/swift/no-manifest"
doFirst {
val outFile = file(swiftOut)
outFile.deleteRecursively()
Expand Down Expand Up @@ -482,8 +482,8 @@ val generateSwiftTests by tasks.creating {
group = "Generate Tests"
description = "Generates Swift classes from the test protos"
dependsOn(
generateSwiftProto2Tests,
generateSwiftProto2ManifestTests,
generateSwiftProto2Tests,
generateSwiftProto3Tests,
":wire-runtime-swift:generateTestProtos"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1206,12 +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)
// }
// }
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Code generated by Wire protocol buffer compiler, do not edit.
// Source: squareup.protos.kotlin.swift_modules.SwiftModuleOneType in swift_module_one.proto
import Foundation
import Wire

public enum SwiftModuleOneType : UInt32, CaseIterable, ProtoEnum {

case DO_NOT_USE = 0
case ONE = 1
case TWO = 2

public var description: String {
switch self {
case .DO_NOT_USE: return "DO_NOT_USE"
case .ONE: return "ONE"
case .TWO: return "TWO"
}
}

}

#if swift(>=5.5)
extension SwiftModuleOneType : Sendable {
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
// Code generated by Wire protocol buffer compiler, do not edit.
// Source: squareup.protos.kotlin.swift_modules.SwiftModuleTwoMessage in swift_module_two.proto
import Foundation
import Wire
import module_one

public struct SwiftModuleTwoMessage {

public var name: String?
public var unknownFields: Foundation.Data = .init()

public init(configure: (inout Self) -> Swift.Void = { _ in }) {
configure(&self)
}

}

#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER
extension SwiftModuleTwoMessage {

@_disfavoredOverload
@available(*, deprecated)
public init(name: Swift.String? = nil) {
self.name = name
}

}
#endif

#if !WIRE_REMOVE_EQUATABLE
extension SwiftModuleTwoMessage : Equatable {
}
#endif

#if !WIRE_REMOVE_HASHABLE
extension SwiftModuleTwoMessage : Hashable {
}
#endif

#if swift(>=5.5)
extension SwiftModuleTwoMessage : Sendable {
}
#endif

extension SwiftModuleTwoMessage : ProtoMessage {

public static func protoMessageTypeURL() -> Swift.String {
return "type.googleapis.com/squareup.protos.kotlin.swift_modules.SwiftModuleTwoMessage"
}

}

extension SwiftModuleTwoMessage : Proto2Codable {

public init(from protoReader: Wire.ProtoReader) throws {
var name: Swift.String? = nil

let token = try protoReader.beginMessage()
while let tag = try protoReader.nextTag(token: token) {
switch tag {
case 1: name = try protoReader.decode(Swift.String.self)
default: try protoReader.readUnknownField(tag: tag)
}
}
self.unknownFields = try protoReader.endMessage(token: token)

self.name = name
}

public func encode(to protoWriter: Wire.ProtoWriter) throws {
try protoWriter.encode(tag: 1, value: self.name)
try protoWriter.writeUnknownFields(unknownFields)
}

}

#if !WIRE_REMOVE_CODABLE
extension SwiftModuleTwoMessage : Codable {

public init(from decoder: Swift.Decoder) throws {
let container = try decoder.container(keyedBy: Wire.StringLiteralCodingKeys.self)
self.name = try container.decodeIfPresent(Swift.String.self, forKey: "name")
}

public func encode(to encoder: Swift.Encoder) throws {
var container = encoder.container(keyedBy: Wire.StringLiteralCodingKeys.self)

try container.encodeIfPresent(self.name, forKey: "name")
}

}
#endif

/**
* Subtypes within SwiftModuleTwoMessage
*/
extension SwiftModuleTwoMessage {

public struct NestedMessage {

public var types: [module_one.SwiftModuleOneType] = []
public var unknownFields: Foundation.Data = .init()

public init(configure: (inout Self) -> Swift.Void = { _ in }) {
configure(&self)
}

}

}

#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER
extension SwiftModuleTwoMessage.NestedMessage {

@_disfavoredOverload
@available(*, deprecated)
public init(types: [module_one.SwiftModuleOneType] = []) {
self.types = types
}

}
#endif

#if !WIRE_REMOVE_EQUATABLE
extension SwiftModuleTwoMessage.NestedMessage : Equatable {
}
#endif

#if !WIRE_REMOVE_HASHABLE
extension SwiftModuleTwoMessage.NestedMessage : Hashable {
}
#endif

#if swift(>=5.5)
extension SwiftModuleTwoMessage.NestedMessage : Sendable {
}
#endif

extension SwiftModuleTwoMessage.NestedMessage : ProtoMessage {

public static func protoMessageTypeURL() -> Swift.String {
return "type.googleapis.com/squareup.protos.kotlin.swift_modules.SwiftModuleTwoMessage.NestedMessage"
}

}

extension SwiftModuleTwoMessage.NestedMessage : Proto2Codable {

public init(from protoReader: Wire.ProtoReader) throws {
var types: [module_one.SwiftModuleOneType] = []

let token = try protoReader.beginMessage()
while let tag = try protoReader.nextTag(token: token) {
switch tag {
case 2: try protoReader.decode(into: &types)
default: try protoReader.readUnknownField(tag: tag)
}
}
self.unknownFields = try protoReader.endMessage(token: token)

self.types = types
}

public func encode(to protoWriter: Wire.ProtoWriter) throws {
try protoWriter.encode(tag: 2, value: self.types)
try protoWriter.writeUnknownFields(unknownFields)
}

}

#if !WIRE_REMOVE_CODABLE
extension SwiftModuleTwoMessage.NestedMessage : Codable {

public init(from decoder: Swift.Decoder) throws {
let container = try decoder.container(keyedBy: Wire.StringLiteralCodingKeys.self)
self.types = try container.decodeProtoArray(module_one.SwiftModuleOneType.self, forKey: "types")
}

public func encode(to encoder: Swift.Encoder) throws {
var container = encoder.container(keyedBy: Wire.StringLiteralCodingKeys.self)
let includeDefaults = encoder.protoDefaultValuesEncodingStrategy == .include

if includeDefaults || !self.types.isEmpty {
try container.encodeProtoArray(self.types, forKey: "types")
}
}

}
#endif
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit ad5bf1e

Please sign in to comment.