|
@@ -20,13 +20,27 @@ import PackagePlugin
|
|
|
@main
|
|
@main
|
|
|
struct GRPCSwiftPlugin {
|
|
struct GRPCSwiftPlugin {
|
|
|
/// Errors thrown by the `GRPCSwiftPlugin`
|
|
/// Errors thrown by the `GRPCSwiftPlugin`
|
|
|
- enum PluginError: Error {
|
|
|
|
|
|
|
+ enum PluginError: Error, CustomStringConvertible {
|
|
|
/// Indicates that the target where the plugin was applied to was not `SourceModuleTarget`.
|
|
/// Indicates that the target where the plugin was applied to was not `SourceModuleTarget`.
|
|
|
- case invalidTarget
|
|
|
|
|
|
|
+ case invalidTarget(Target)
|
|
|
/// Indicates that the file extension of an input file was not `.proto`.
|
|
/// Indicates that the file extension of an input file was not `.proto`.
|
|
|
- case invalidInputFileExtension
|
|
|
|
|
|
|
+ case invalidInputFileExtension(String)
|
|
|
/// Indicates that there was no configuration file at the required location.
|
|
/// Indicates that there was no configuration file at the required location.
|
|
|
- case noConfigFound
|
|
|
|
|
|
|
+ case noConfigFound(String)
|
|
|
|
|
+
|
|
|
|
|
+ var description: String {
|
|
|
|
|
+ switch self {
|
|
|
|
|
+ case let .invalidTarget(target):
|
|
|
|
|
+ return "Expected a SwiftSourceModuleTarget but got '\(type(of: target))'."
|
|
|
|
|
+ case let .invalidInputFileExtension(path):
|
|
|
|
|
+ return "The input file '\(path)' does not have a '.proto' extension."
|
|
|
|
|
+ case let .noConfigFound(path):
|
|
|
|
|
+ return """
|
|
|
|
|
+ No configuration file found named '\(path)'. The file must not be listed in the \
|
|
|
|
|
+ 'exclude:' argument for the target in Package.swift.
|
|
|
|
|
+ """
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// The configuration of the plugin.
|
|
/// The configuration of the plugin.
|
|
@@ -88,7 +102,7 @@ struct GRPCSwiftPlugin {
|
|
|
$0.path.lastComponent == Self.configurationFileName
|
|
$0.path.lastComponent == Self.configurationFileName
|
|
|
}
|
|
}
|
|
|
)?.path else {
|
|
)?.path else {
|
|
|
- throw PluginError.noConfigFound
|
|
|
|
|
|
|
+ throw PluginError.noConfigFound(Self.configurationFileName)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
let data = try Data(contentsOf: URL(fileURLWithPath: "\(configurationFilePath)"))
|
|
let data = try Data(contentsOf: URL(fileURLWithPath: "\(configurationFilePath)"))
|
|
@@ -208,7 +222,7 @@ struct GRPCSwiftPlugin {
|
|
|
for invocation in configuration.invocations {
|
|
for invocation in configuration.invocations {
|
|
|
for protoFile in invocation.protoFiles {
|
|
for protoFile in invocation.protoFiles {
|
|
|
if !protoFile.hasSuffix(".proto") {
|
|
if !protoFile.hasSuffix(".proto") {
|
|
|
- throw PluginError.invalidInputFileExtension
|
|
|
|
|
|
|
+ throw PluginError.invalidInputFileExtension(protoFile)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -221,7 +235,7 @@ extension GRPCSwiftPlugin: BuildToolPlugin {
|
|
|
target: Target
|
|
target: Target
|
|
|
) async throws -> [Command] {
|
|
) async throws -> [Command] {
|
|
|
guard let swiftTarget = target as? SwiftSourceModuleTarget else {
|
|
guard let swiftTarget = target as? SwiftSourceModuleTarget else {
|
|
|
- throw PluginError.invalidTarget
|
|
|
|
|
|
|
+ throw PluginError.invalidTarget(target)
|
|
|
}
|
|
}
|
|
|
return try self.createBuildCommands(
|
|
return try self.createBuildCommands(
|
|
|
pluginWorkDirectory: context.pluginWorkDirectory,
|
|
pluginWorkDirectory: context.pluginWorkDirectory,
|