Skip to content

Commit

Permalink
add config file as a registered input file
Browse files Browse the repository at this point in the history
  • Loading branch information
rnro committed Jan 14, 2025
1 parent af7cfe0 commit 256b3e9
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions Plugins/GRPCProtobufGenerator/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct GRPCProtobufGenerator {

var commands: [Command] = []
for inputFile in inputFiles {
guard let config = configs.findApplicableConfig(for: inputFile) else {
guard let (configFilePath, config) = configs.findApplicableConfig(for: inputFile) else {
throw PluginError.noConfigurationFilesFound
}

Expand All @@ -60,7 +60,8 @@ struct GRPCProtobufGenerator {
config: config,
protoDirectoryPath: protoDirectoryPath,
protocPath: protocPath,
protocGenSwiftPath: protocGenSwiftPath
protocGenSwiftPath: protocGenSwiftPath,
configFilePath: configFilePath
)
commands.append(protoCommand)
}
Expand Down Expand Up @@ -96,15 +97,15 @@ extension [URL: GenerationConfig] {
/// Finds the most precisely relevant config file for a given proto file URL.
/// - Parameters:
/// - file: The path to the proto file to be matched.
/// - Returns: The path to the most precisely relevant config file if one is found, otherwise `nil`.
func findApplicableConfig(for file: URL) -> GenerationConfig? {
/// - Returns: The path to the most precisely relevant config file if one is found and the config itself, otherwise `nil`.
func findApplicableConfig(for file: URL) -> (URL, GenerationConfig)? {
let filePathComponents = file.pathComponents
for endComponent in (0 ..< filePathComponents.count).reversed() {
for (configFilePath, config) in self {
if filePathComponents[..<endComponent]
== configFilePath.pathComponents[..<(configFilePath.pathComponents.count - 1)]
{
return config
return (configFilePath, config)
}
}
}
Expand Down Expand Up @@ -162,13 +163,15 @@ func protocGenGRPCSwiftCommand(
/// - protoDirectoryPath: The root path to the source `.proto` files used as the reference for relative path naming schemes.
/// - protocPath: The path to `protoc`
/// - protocGenSwiftPath: The path to `proto-gen-grpc-swift`.
/// - configFilePath: The path to the config file in use.
/// - Returns: The command to invoke `protoc` with the `proto-gen-swift` plugin.
func protocGenSwiftCommand(
inputFile: URL,
config: GenerationConfig,
protoDirectoryPath: URL,
protocPath: URL,
protocGenSwiftPath: URL
protocGenSwiftPath: URL,
configFilePath: URL
) throws -> PackagePlugin.Command {
let outputPathURL = URL(fileURLWithPath: config.outputPath)

Expand All @@ -192,7 +195,11 @@ func protocGenSwiftCommand(
displayName: "Generating Swift Protobuf files for \(inputFile.relativePath)",
executable: protocPath,
arguments: arguments,
inputFiles: [inputFile, protocGenSwiftPath],
inputFiles: [
inputFile,
protocGenSwiftPath,
configFilePath
],
outputFiles: [outputFilePath]
)
}
Expand Down

0 comments on commit 256b3e9

Please sign in to comment.