Skip to content

Commit 256b3e9

Browse files
committed
add config file as a registered input file
1 parent af7cfe0 commit 256b3e9

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

Plugins/GRPCProtobufGenerator/Plugin.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct GRPCProtobufGenerator {
3434

3535
var commands: [Command] = []
3636
for inputFile in inputFiles {
37-
guard let config = configs.findApplicableConfig(for: inputFile) else {
37+
guard let (configFilePath, config) = configs.findApplicableConfig(for: inputFile) else {
3838
throw PluginError.noConfigurationFilesFound
3939
}
4040

@@ -60,7 +60,8 @@ struct GRPCProtobufGenerator {
6060
config: config,
6161
protoDirectoryPath: protoDirectoryPath,
6262
protocPath: protocPath,
63-
protocGenSwiftPath: protocGenSwiftPath
63+
protocGenSwiftPath: protocGenSwiftPath,
64+
configFilePath: configFilePath
6465
)
6566
commands.append(protoCommand)
6667
}
@@ -96,15 +97,15 @@ extension [URL: GenerationConfig] {
9697
/// Finds the most precisely relevant config file for a given proto file URL.
9798
/// - Parameters:
9899
/// - 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)? {
101102
let filePathComponents = file.pathComponents
102103
for endComponent in (0 ..< filePathComponents.count).reversed() {
103104
for (configFilePath, config) in self {
104105
if filePathComponents[..<endComponent]
105106
== configFilePath.pathComponents[..<(configFilePath.pathComponents.count - 1)]
106107
{
107-
return config
108+
return (configFilePath, config)
108109
}
109110
}
110111
}
@@ -162,13 +163,15 @@ func protocGenGRPCSwiftCommand(
162163
/// - protoDirectoryPath: The root path to the source `.proto` files used as the reference for relative path naming schemes.
163164
/// - protocPath: The path to `protoc`
164165
/// - protocGenSwiftPath: The path to `proto-gen-grpc-swift`.
166+
/// - configFilePath: The path to the config file in use.
165167
/// - Returns: The command to invoke `protoc` with the `proto-gen-swift` plugin.
166168
func protocGenSwiftCommand(
167169
inputFile: URL,
168170
config: GenerationConfig,
169171
protoDirectoryPath: URL,
170172
protocPath: URL,
171-
protocGenSwiftPath: URL
173+
protocGenSwiftPath: URL,
174+
configFilePath: URL
172175
) throws -> PackagePlugin.Command {
173176
let outputPathURL = URL(fileURLWithPath: config.outputPath)
174177

@@ -192,7 +195,11 @@ func protocGenSwiftCommand(
192195
displayName: "Generating Swift Protobuf files for \(inputFile.relativePath)",
193196
executable: protocPath,
194197
arguments: arguments,
195-
inputFiles: [inputFile, protocGenSwiftPath],
198+
inputFiles: [
199+
inputFile,
200+
protocGenSwiftPath,
201+
configFilePath
202+
],
196203
outputFiles: [outputFilePath]
197204
)
198205
}

0 commit comments

Comments
 (0)