Skip to content

Commit 2f5ef06

Browse files
authored
Use relative path for input files to protoc (#79)
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
1 parent 44a0230 commit 2f5ef06

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Plugins/PluginsShared/PluginUtils.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func constructProtocGenSwiftArguments(
6868
protocArgs.append("--swift_opt=Visibility=\(config.accessLevel.rawValue)")
6969
protocArgs.append("--swift_opt=FileNaming=\(config.fileNaming.rawValue)")
7070
protocArgs.append("--swift_opt=UseAccessLevelOnImports=\(config.accessLevelOnImports)")
71-
protocArgs.append(contentsOf: inputFiles.map { $0.absoluteStringNoScheme })
71+
protocArgs.append(contentsOf: inputFiles.map { $0.relativePath })
7272

7373
return protocArgs
7474
}
@@ -104,7 +104,7 @@ func constructProtocGenGRPCSwiftArguments(
104104
protocArgs.append("--grpc-swift_opt=Client=\(config.clients)")
105105
protocArgs.append("--grpc-swift_opt=FileNaming=\(config.fileNaming.rawValue)")
106106
protocArgs.append("--grpc-swift_opt=UseAccessLevelOnImports=\(config.accessLevelOnImports)")
107-
protocArgs.append(contentsOf: inputFiles.map { $0.absoluteStringNoScheme })
107+
protocArgs.append(contentsOf: inputFiles.map { $0.relativePath })
108108

109109
return protocArgs
110110
}

0 commit comments

Comments
 (0)