11import Foundation
2- import PackagePlugin
2+ @ preconcurrency import PackagePlugin
33
44@main
55struct SwiftProtobufPlugin {
@@ -107,40 +107,40 @@ struct SwiftProtobufPlugin {
107107 /// - tool: The tool method from the context.
108108 /// - Returns: The build commands configured based on the arguments.
109109 func createBuildCommands(
110- pluginWorkDirectory: PackagePlugin . Path ,
110+ pluginWorkDirectory: URL ,
111111 sourceFiles: FileList ,
112112 tool: ( String ) throws -> PackagePlugin . PluginContext . Tool
113113 ) throws -> [ Command ] {
114114 guard
115115 let configurationFilePath = sourceFiles. first (
116116 where: {
117- $0. path . lastComponent == Self . configurationFileName
117+ $0. url . lastPathComponent == Self . configurationFileName
118118 }
119- ) ? . path
119+ ) ? . url
120120 else {
121121 throw PluginError . noConfigFound ( Self . configurationFileName)
122122 }
123- let data = try Data ( contentsOf: URL ( fileURLWithPath : " \( configurationFilePath) " ) )
123+ let data = try Data ( contentsOf: configurationFilePath)
124124 let configuration = try JSONDecoder ( ) . decode ( Configuration . self, from: data)
125125 try validateConfiguration ( configuration)
126126
127127 // We need to find the path of protoc and protoc-gen-swift
128- let protocPath : Path
128+ let protocPath : URL
129129 if let configuredProtocPath = configuration. protocPath {
130130 // The user set the config path in the file. So let's take that
131- protocPath = Path ( configuredProtocPath)
131+ protocPath = URL ( fileURLWithPath : configuredProtocPath)
132132 } else if let environmentPath = ProcessInfo . processInfo. environment [ " PROTOC_PATH " ] {
133133 // The user set the env variable. So let's take that
134- protocPath = Path ( environmentPath)
134+ protocPath = URL ( fileURLWithPath : environmentPath)
135135 } else {
136136 // The user didn't set anything so let's try see if SPM can find a binary for us
137- protocPath = try tool ( " protoc " ) . path
137+ protocPath = try tool ( " protoc " ) . url
138138 }
139- let protocGenSwiftPath = try tool ( " protoc-gen-swift " ) . path
139+ let protocGenSwiftPath = try tool ( " protoc-gen-swift " ) . url
140140
141141 return configuration. invocations. map { invocation in
142142 self . invokeProtoc (
143- directory: configurationFilePath. removingLastComponent ( ) ,
143+ directory: configurationFilePath. deletingLastPathComponent ( ) ,
144144 invocation: invocation,
145145 protocPath: protocPath,
146146 protocGenSwiftPath: protocGenSwiftPath,
@@ -159,22 +159,22 @@ struct SwiftProtobufPlugin {
159159 /// - outputDirectory: The output directory for the generated files.
160160 /// - Returns: The build command configured based on the arguments.
161161 private func invokeProtoc(
162- directory: PackagePlugin . Path ,
162+ directory: URL ,
163163 invocation: Configuration . Invocation ,
164- protocPath: Path ,
165- protocGenSwiftPath: Path ,
166- outputDirectory: Path
164+ protocPath: URL ,
165+ protocGenSwiftPath: URL ,
166+ outputDirectory: URL
167167 ) -> Command {
168168 // Construct the `protoc` arguments.
169169 var protocArgs = [
170- " --plugin=protoc-gen-swift= \( protocGenSwiftPath) " ,
171- " --swift_out= \( outputDirectory) " ,
170+ " --plugin=protoc-gen-swift= \( protocGenSwiftPath. path ( ) ) " ,
171+ " --swift_out= \( outputDirectory. path ( ) ) " ,
172172 ]
173173
174174 // We need to add the target directory as a search path since we require the user to specify
175175 // the proto files relative to it.
176176 protocArgs. append ( " -I " )
177- protocArgs. append ( " \( directory) " )
177+ protocArgs. append ( directory. path ( ) )
178178
179179 // Add the visibility if it was set
180180 if let visibility = invocation. visibility {
@@ -196,20 +196,20 @@ struct SwiftProtobufPlugin {
196196 protocArgs. append ( " --swift_opt=UseAccessLevelOnImports= \( useAccessLevelOnImports) " )
197197 }
198198
199- var inputFiles = [ Path ] ( )
200- var outputFiles = [ Path ] ( )
199+ var inputFiles = [ URL ] ( )
200+ var outputFiles = [ URL ] ( )
201201
202202 for var file in invocation. protoFiles {
203203 // Append the file to the protoc args so that it is used for generating
204- protocArgs. append ( " \( file) " )
205- inputFiles. append ( directory. appending ( file) )
204+ protocArgs. append ( file)
205+ inputFiles. append ( directory. appending ( path : file) )
206206
207207 // The name of the output file is based on the name of the input file.
208208 // We validated in the beginning that every file has the suffix of .proto
209209 // This means we can just drop the last 5 elements and append the new suffix
210210 file. removeLast ( 5 )
211211 file. append ( " pb.swift " )
212- let protobufOutputPath = outputDirectory. appending ( file)
212+ let protobufOutputPath = outputDirectory. appending ( path : file)
213213
214214 // Add the outputPath as an output file
215215 outputFiles. append ( protobufOutputPath)
@@ -248,7 +248,7 @@ extension SwiftProtobufPlugin: BuildToolPlugin {
248248 throw PluginError . invalidTarget ( target)
249249 }
250250 return try createBuildCommands (
251- pluginWorkDirectory: context. pluginWorkDirectory ,
251+ pluginWorkDirectory: context. pluginWorkDirectoryURL ,
252252 sourceFiles: swiftTarget. sourceFiles,
253253 tool: context. tool
254254 )
@@ -264,7 +264,7 @@ extension SwiftProtobufPlugin: XcodeBuildToolPlugin {
264264 target: XcodeTarget
265265 ) throws -> [ Command ] {
266266 try createBuildCommands (
267- pluginWorkDirectory: context. pluginWorkDirectory ,
267+ pluginWorkDirectory: context. pluginWorkDirectoryURL ,
268268 sourceFiles: target. inputFiles,
269269 tool: context. tool
270270 )
0 commit comments