Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dnkoutso committed Oct 4, 2023
1 parent bb6f672 commit 28e24ce
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 0 deletions.
23 changes: 23 additions & 0 deletions gen-tests.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,28 @@ 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 +484,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
@@ -0,0 +1,91 @@
// Code generated by Wire protocol buffer compiler, do not edit.
// Source: squareup.protos.kotlin.swift_module_one.SwiftModuleOneMessage in swift_module_one.proto
import Foundation
import Wire

public struct SwiftModuleOneMessage {

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 SwiftModuleOneMessage {

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

}
#endif

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

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

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

extension SwiftModuleOneMessage : ProtoMessage {

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

}

extension SwiftModuleOneMessage : 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 SwiftModuleOneMessage : 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
104 changes: 104 additions & 0 deletions wire-tests-swift/src/main/swift/module_two/SwiftModuleTwoMessage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Code generated by Wire protocol buffer compiler, do not edit.
// Source: squareup.protos.kotlin.swift_module_two.SwiftModuleTwoMessage in swift_module_two.proto
import Foundation
import Wire
import module_one

public struct SwiftModuleTwoMessage {

public var name: String?
public var module_one_names: [SwiftModuleOneMessage] = []
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, module_one_names: [module_one.SwiftModuleOneMessage] = []) {
self.name = name
self.module_one_names = module_one_names
}

}
#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_module_two.SwiftModuleTwoMessage"
}

}

extension SwiftModuleTwoMessage : Proto2Codable {

public init(from protoReader: Wire.ProtoReader) throws {
var name: Swift.String? = nil
var module_one_names: [module_one.SwiftModuleOneMessage] = []

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

self.name = name
self.module_one_names = module_one_names
}

public func encode(to protoWriter: Wire.ProtoWriter) throws {
try protoWriter.encode(tag: 1, value: self.name)
try protoWriter.encode(tag: 2, value: self.module_one_names)
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")
self.module_one_names = try container.decodeProtoArray(module_one.SwiftModuleOneMessage.self, firstOfKeys: "moduleOneNames", "module_one_names")
}

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

try container.encodeIfPresent(self.name, forKey: "name")
if includeDefaults || !self.module_one_names.isEmpty {
try container.encodeProtoArray(self.module_one_names, forKey: preferCamelCase ? "moduleOneNames" : "module_one_names")
}
}

}
#endif
22 changes: 22 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,22 @@
/*
* 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_module_one;

message SwiftModuleOneMessage {
optional string name = 1;
}
25 changes: 25 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,25 @@
/*
* 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_module_two;

import "swift_module_one.proto";

message SwiftModuleTwoMessage {
optional string name = 1;
repeated squareup.protos.kotlin.swift_module_one.SwiftModuleOneMessage module_one_names = 2;
}
29 changes: 29 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,29 @@
#
# 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_module1.proto and swift_module2.proto

---
module_one:
roots:
- squareup.protos.kotlin.swift_module_one.SwiftModuleOneMessage
prunes:
- google.protobuf.*
module_two:
roots:
- squareup.protos.kotlin.swift_module_two.SwiftModuleTwoMessage
dependencies:
- module_one

0 comments on commit 28e24ce

Please sign in to comment.