From b7a41b483f34081491c6761f83622efa61530f83 Mon Sep 17 00:00:00 2001 From: George Barnett Date: Fri, 18 Jul 2025 16:21:58 +0100 Subject: [PATCH] Use relative path for input files to protoc Motivation: protoc requires the import path (-I/--import-path) to be an exact prefix of the input files. The plugin currently uses the absolute path of a file for input paths without modifying the import path. The result of this is that the user must always specify an absolute import path (because the default chosen by is protoc is "."). Modifications: - Use the relative path for input files (this will be whatever the user provides, which may be an absolute path) rather than the absolute path which will get the full absolute path even if the user specified "foo.proto" as input. Result: Users can do: swift package generate-grpc-code-from-protos foo.proto --- Plugins/PluginsShared/PluginUtils.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/PluginsShared/PluginUtils.swift b/Plugins/PluginsShared/PluginUtils.swift index 16fc416..f912dcd 100644 --- a/Plugins/PluginsShared/PluginUtils.swift +++ b/Plugins/PluginsShared/PluginUtils.swift @@ -68,7 +68,7 @@ func constructProtocGenSwiftArguments( protocArgs.append("--swift_opt=Visibility=\(config.accessLevel.rawValue)") protocArgs.append("--swift_opt=FileNaming=\(config.fileNaming.rawValue)") protocArgs.append("--swift_opt=UseAccessLevelOnImports=\(config.accessLevelOnImports)") - protocArgs.append(contentsOf: inputFiles.map { $0.absoluteStringNoScheme }) + protocArgs.append(contentsOf: inputFiles.map { $0.relativePath }) return protocArgs } @@ -104,7 +104,7 @@ func constructProtocGenGRPCSwiftArguments( protocArgs.append("--grpc-swift_opt=Client=\(config.clients)") protocArgs.append("--grpc-swift_opt=FileNaming=\(config.fileNaming.rawValue)") protocArgs.append("--grpc-swift_opt=UseAccessLevelOnImports=\(config.accessLevelOnImports)") - protocArgs.append(contentsOf: inputFiles.map { $0.absoluteStringNoScheme }) + protocArgs.append(contentsOf: inputFiles.map { $0.relativePath }) return protocArgs }