Skip to content

Commit

Permalink
tweaking
Browse files Browse the repository at this point in the history
  • Loading branch information
rnro committed Dec 24, 2024
1 parent a15d9bd commit 9eb1cf0
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/matrices/plugin-tests.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"config":[{"name":"Plugin tests (6.0)","swift_version":"6.0","runner":"ubuntu-latest","image":"swift:6.0-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl","command":"curl -s https://raw.githubusercontent.com/rnro/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""},{"name":"Plugin tests (nightly-6.0)","swift_version":"nightly-6.0","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-6.0-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl","command":"curl -s https://raw.githubusercontent.com/rnro/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""},{"name":"Plugin tests (nightly-main)","swift_version":"nightly-main","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-main-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl","command":"curl -s https://raw.githubusercontent.com/rnro/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""}]}
{"config":[{"name":"Plugin tests (6.0)","swift_version":"6.0","runner":"ubuntu-latest","image":"swift:6.0-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl","command":"curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""},{"name":"Plugin tests (nightly-6.0)","swift_version":"nightly-6.0","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-6.0-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl","command":"curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""},{"name":"Plugin tests (nightly-main)","swift_version":"nightly-main","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-main-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl","command":"curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""}]}
Original file line number Diff line number Diff line change
@@ -1,37 +1,51 @@
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
/*
* Copyright 2024, gRPC Authors All rights reserved.
*
* 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.
*/

import PackageDescription

let package = Package(
name: "grpc-adopter",
platforms: [
.macOS(.v15),
.iOS(.v18),
.tvOS(.v18),
.watchOS(.v11),
.visionOS(.v2),
],
dependencies: [
.package(
path: "../../../../grpc-swift-protobuf"
),
.package(
url: "https://github.com/grpc/grpc-swift.git",
from: "1.28.2"
)
],
targets: [
.executableTarget(
name: "grpc-adopter",
dependencies: [
.product(name: "GRPCCore", package: "grpc-swift"),
.product(name: "GRPCInProcessTransport", package: "grpc-swift"),
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"),
],
plugins: [
.plugin(name: "GRPCGeneratorPlugin", package: "grpc-swift-protobuf")
]
)
]
name: "grpc-adopter",
platforms: [
.macOS(.v15),
.iOS(.v18),
.tvOS(.v18),
.watchOS(.v11),
.visionOS(.v2),
],
dependencies: [
.package(
path: "../../../../grpc-swift-protobuf"
),
.package(
url: "https://github.com/grpc/grpc-swift.git",
from: "1.28.2"
),
],
targets: [
.executableTarget(
name: "grpc-adopter",
dependencies: [
.product(name: "GRPCCore", package: "grpc-swift"),
.product(name: "GRPCInProcessTransport", package: "grpc-swift"),
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"),
],
plugins: [
.plugin(name: "GRPCGeneratorPlugin", package: "grpc-swift-protobuf")
]
)
]
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 gRPC authors.
// Copyright 2015, gRPC Authors All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
76 changes: 45 additions & 31 deletions IntegrationTests/PluginTests/test_02_peer_config_file/Package.swift
Original file line number Diff line number Diff line change
@@ -1,37 +1,51 @@
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
/*
* Copyright 2024, gRPC Authors All rights reserved.
*
* 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.
*/

import PackageDescription

let package = Package(
name: "grpc-adopter",
platforms: [
.macOS(.v15),
.iOS(.v18),
.tvOS(.v18),
.watchOS(.v11),
.visionOS(.v2),
],
dependencies: [
.package(
path: "../../../../grpc-swift-protobuf"
),
.package(
url: "https://github.com/grpc/grpc-swift.git",
from: "1.28.2"
)
],
targets: [
.executableTarget(
name: "grpc-adopter",
dependencies: [
.product(name: "GRPCCore", package: "grpc-swift"),
.product(name: "GRPCInProcessTransport", package: "grpc-swift"),
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"),
],
plugins: [
.plugin(name: "GRPCGeneratorPlugin", package: "grpc-swift-protobuf")
]
)
]
name: "grpc-adopter",
platforms: [
.macOS(.v15),
.iOS(.v18),
.tvOS(.v18),
.watchOS(.v11),
.visionOS(.v2),
],
dependencies: [
.package(
path: "../../../../grpc-swift-protobuf"
),
.package(
url: "https://github.com/grpc/grpc-swift.git",
from: "1.28.2"
),
],
targets: [
.executableTarget(
name: "grpc-adopter",
dependencies: [
.product(name: "GRPCCore", package: "grpc-swift"),
.product(name: "GRPCInProcessTransport", package: "grpc-swift"),
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"),
],
plugins: [
.plugin(name: "GRPCGeneratorPlugin", package: "grpc-swift-protobuf")
]
)
]
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 gRPC authors.
// Copyright 2015, gRPC Authors All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,51 @@
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
/*
* Copyright 2024, gRPC Authors All rights reserved.
*
* 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.
*/

import PackageDescription

let package = Package(
name: "grpc-adopter",
platforms: [
.macOS(.v15),
.iOS(.v18),
.tvOS(.v18),
.watchOS(.v11),
.visionOS(.v2),
],
dependencies: [
.package(
path: "../../../../grpc-swift-protobuf"
),
.package(
url: "https://github.com/grpc/grpc-swift.git",
from: "1.28.2"
)
],
targets: [
.executableTarget(
name: "grpc-adopter",
dependencies: [
.product(name: "GRPCCore", package: "grpc-swift"),
.product(name: "GRPCInProcessTransport", package: "grpc-swift"),
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"),
],
plugins: [
.plugin(name: "GRPCGeneratorPlugin", package: "grpc-swift-protobuf")
]
)
]
name: "grpc-adopter",
platforms: [
.macOS(.v15),
.iOS(.v18),
.tvOS(.v18),
.watchOS(.v11),
.visionOS(.v2),
],
dependencies: [
.package(
path: "../../../../grpc-swift-protobuf"
),
.package(
url: "https://github.com/grpc/grpc-swift.git",
from: "1.28.2"
),
],
targets: [
.executableTarget(
name: "grpc-adopter",
dependencies: [
.product(name: "GRPCCore", package: "grpc-swift"),
.product(name: "GRPCInProcessTransport", package: "grpc-swift"),
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"),
],
plugins: [
.plugin(name: "GRPCGeneratorPlugin", package: "grpc-swift-protobuf")
]
)
]
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 gRPC authors.
// Copyright 2015, gRPC Authors All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 gRPC authors.
// Copyright 2015, gRPC Authors All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
11 changes: 7 additions & 4 deletions Plugins/GRPCGeneratorCommand/ConfigurationArguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ extension CommandConfiguration {
case .useAccessLevelOnImports:
self.common.useAccessLevelOnImports = .init(value)
case .importPath:
self.common.importPaths!.append(value) // ! is safe because we set it to an empty array at the top of the method
// ! is safe because we set it to an empty array at the top of the method
self.common.importPaths!.append(value)
case .protocPath:
self.common.protocPath = value
case .output:
Expand Down Expand Up @@ -134,7 +135,7 @@ enum Flag: CaseIterable {

case dryRun

init (_ argument: String) throws {
init(_ argument: String) throws {
switch argument {
case "--visibility":
self = .visibility
Expand Down Expand Up @@ -179,7 +180,8 @@ extension Flag {
case .message:
return "--message Whether message code is generated."
case .fileNaming:
return "--file-naming The naming of output files with respect to the path of the source file."
return
"--file-naming The naming of output files with respect to the path of the source file."
case .protoPathModuleMappings:
return "--proto-path-module-mappings Path to module map .asciipb file."
case .useAccessLevelOnImports:
Expand All @@ -191,7 +193,8 @@ extension Flag {
case .dryRun:
return "--dry-run Print but do not execute the protoc commands."
case .output:
return "--output The path into which the generated source files are created."
return
"--output The path into which the generated source files are created."
}
}

Expand Down
14 changes: 7 additions & 7 deletions Plugins/GRPCGeneratorCommand/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import PackagePlugin
import Foundation
import PackagePlugin

@main
struct GRPCGeneratorCommandPlugin: CommandPlugin {
Expand All @@ -28,7 +28,7 @@ struct GRPCGeneratorCommandPlugin: CommandPlugin {
commandConfig = try CommandConfiguration(arguments: arguments)
} catch PluginError.helpRequested {
Flag.printHelp()
return // don't throw, the user requested this
return // don't throw, the user requested this
} catch {
Flag.printHelp()
throw error
Expand All @@ -42,18 +42,19 @@ struct GRPCGeneratorCommandPlugin: CommandPlugin {
let protocGenGRPCSwiftPath = try context.tool(named: "protoc-gen-grpc-swift").url
let protocGenSwiftPath = try context.tool(named: "protoc-gen-swift").url

let outputDirectory = config.outputPath.map{ URL(fileURLWithPath:$0) } ?? context.pluginWorkDirectoryURL
let outputDirectory =
config.outputPath.map { URL(fileURLWithPath: $0) } ?? context.pluginWorkDirectoryURL
print("Generated files will be written to: '\(outputDirectory.formatted())'")

let inputFileURLs = inputFiles.map{ URL(fileURLWithPath: $0) }
let inputFileURLs = inputFiles.map { URL(fileURLWithPath: $0) }

// MARK: proto-gen-grpc-swift
if config.client != false || config.server != false {
let arguments = constructProtocGenGRPCSwiftArguments(
config: config,
using: config.fileNaming,
inputFiles: inputFileURLs,
protoDirectoryPaths: inputFileURLs.map{ $0.deletingLastPathComponent() },
protoDirectoryPaths: inputFileURLs.map { $0.deletingLastPathComponent() },
protocGenGRPCSwiftPath: protocGenGRPCSwiftPath,
outputDirectory: outputDirectory
)
Expand All @@ -78,7 +79,7 @@ struct GRPCGeneratorCommandPlugin: CommandPlugin {
config: config,
using: config.fileNaming,
inputFiles: inputFileURLs,
protoDirectoryPaths: inputFileURLs.map{ $0.deletingLastPathComponent() },
protoDirectoryPaths: inputFileURLs.map { $0.deletingLastPathComponent() },
protocGenSwiftPath: protocGenSwiftPath,
outputDirectory: outputDirectory
)
Expand Down Expand Up @@ -113,4 +114,3 @@ func printProtocInvocation(_ executableURL: URL, _ arguments: [String]) {
print(" \(lastArgument)")
}
}

7 changes: 4 additions & 3 deletions Plugins/GRPCGeneratorPlugin/ConfigurationFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*/

/// The configuration of the plugin.
struct ConfigurationFile: Codable { /// The visibility of the generated files.
struct ConfigurationFile: Codable {
/// The visibility of the generated files.
enum Visibility: String, Codable {
/// The generated files should have `internal` access level.
case `internal`
Expand All @@ -33,8 +34,8 @@ struct ConfigurationFile: Codable { /// The visibility of the generated files.
var client: Bool?
/// Whether message code is generated.
var message: Bool?
// /// Whether reflection data is generated.
// var reflectionData: Bool?
// /// Whether reflection data is generated.
// var reflectionData: Bool?
/// Path to module map .asciipb file.
var protoPathModuleMappings: String?
/// Whether imports should have explicit access levels.
Expand Down
Loading

0 comments on commit 9eb1cf0

Please sign in to comment.