@@ -34,7 +34,7 @@ struct GRPCProtobufGenerator {
34
34
35
35
var commands : [ Command ] = [ ]
36
36
for inputFile in inputFiles {
37
- guard let config = configs. findApplicableConfig ( for: inputFile) else {
37
+ guard let ( configFilePath , config) = configs. findApplicableConfig ( for: inputFile) else {
38
38
throw PluginError . noConfigurationFilesFound
39
39
}
40
40
@@ -60,7 +60,8 @@ struct GRPCProtobufGenerator {
60
60
config: config,
61
61
protoDirectoryPath: protoDirectoryPath,
62
62
protocPath: protocPath,
63
- protocGenSwiftPath: protocGenSwiftPath
63
+ protocGenSwiftPath: protocGenSwiftPath,
64
+ configFilePath: configFilePath
64
65
)
65
66
commands. append ( protoCommand)
66
67
}
@@ -96,15 +97,15 @@ extension [URL: GenerationConfig] {
96
97
/// Finds the most precisely relevant config file for a given proto file URL.
97
98
/// - Parameters:
98
99
/// - file: The path to the proto file to be matched.
99
- /// - Returns: The path to the most precisely relevant config file if one is found, otherwise `nil`.
100
- func findApplicableConfig( for file: URL ) -> GenerationConfig ? {
100
+ /// - Returns: The path to the most precisely relevant config file if one is found and the config itself , otherwise `nil`.
101
+ func findApplicableConfig( for file: URL ) -> ( URL , GenerationConfig ) ? {
101
102
let filePathComponents = file. pathComponents
102
103
for endComponent in ( 0 ..< filePathComponents. count) . reversed ( ) {
103
104
for (configFilePath, config) in self {
104
105
if filePathComponents [ ..< endComponent]
105
106
== configFilePath. pathComponents [ ..< ( configFilePath. pathComponents. count - 1 ) ]
106
107
{
107
- return config
108
+ return ( configFilePath , config)
108
109
}
109
110
}
110
111
}
@@ -162,13 +163,15 @@ func protocGenGRPCSwiftCommand(
162
163
/// - protoDirectoryPath: The root path to the source `.proto` files used as the reference for relative path naming schemes.
163
164
/// - protocPath: The path to `protoc`
164
165
/// - protocGenSwiftPath: The path to `proto-gen-grpc-swift`.
166
+ /// - configFilePath: The path to the config file in use.
165
167
/// - Returns: The command to invoke `protoc` with the `proto-gen-swift` plugin.
166
168
func protocGenSwiftCommand(
167
169
inputFile: URL ,
168
170
config: GenerationConfig ,
169
171
protoDirectoryPath: URL ,
170
172
protocPath: URL ,
171
- protocGenSwiftPath: URL
173
+ protocGenSwiftPath: URL ,
174
+ configFilePath: URL
172
175
) throws -> PackagePlugin . Command {
173
176
let outputPathURL = URL ( fileURLWithPath: config. outputPath)
174
177
@@ -192,7 +195,11 @@ func protocGenSwiftCommand(
192
195
displayName: " Generating Swift Protobuf files for \( inputFile. relativePath) " ,
193
196
executable: protocPath,
194
197
arguments: arguments,
195
- inputFiles: [ inputFile, protocGenSwiftPath] ,
198
+ inputFiles: [
199
+ inputFile,
200
+ protocGenSwiftPath,
201
+ configFilePath
202
+ ] ,
196
203
outputFiles: [ outputFilePath]
197
204
)
198
205
}
0 commit comments