@@ -51,6 +51,13 @@ struct GRPCSwiftPlugin: BuildToolPlugin {
51
51
var keepMethodCasing : Bool ?
52
52
}
53
53
54
+ /// Specify the directory in which to search for
55
+ /// imports. May be specified multiple times;
56
+ /// directories will be searched in order.
57
+ /// The target source directory is always appended
58
+ /// to the import paths.
59
+ var importPaths : [ String ] ?
60
+
54
61
/// The path to the `protoc` binary.
55
62
///
56
63
/// If this is not set, SPM will try to find the tool itself.
@@ -75,6 +82,11 @@ struct GRPCSwiftPlugin: BuildToolPlugin {
75
82
76
83
try self . validateConfiguration ( configuration)
77
84
85
+ var importPaths : [ Path ] = [ target. directory]
86
+ if let configuredImportPaths = configuration. importPaths {
87
+ importPaths. append ( contentsOf: configuredImportPaths. map { Path ( $0) } )
88
+ }
89
+
78
90
// We need to find the path of protoc and protoc-gen-grpc-swift
79
91
let protocPath : Path
80
92
if let configuredProtocPath = configuration. protocPath {
@@ -97,7 +109,8 @@ struct GRPCSwiftPlugin: BuildToolPlugin {
97
109
invocation: invocation,
98
110
protocPath: protocPath,
99
111
protocGenGRPCSwiftPath: protocGenGRPCSwiftPath,
100
- outputDirectory: outputDirectory
112
+ outputDirectory: outputDirectory,
113
+ importPaths: importPaths
101
114
)
102
115
}
103
116
}
@@ -110,23 +123,27 @@ struct GRPCSwiftPlugin: BuildToolPlugin {
110
123
/// - protocPath: The path to the `protoc` binary.
111
124
/// - protocGenSwiftPath: The path to the `protoc-gen-swift` binary.
112
125
/// - outputDirectory: The output directory for the generated files.
126
+ /// - importPaths: List of paths to pass with "-I <path>" to `protoc`
113
127
/// - Returns: The build command.
114
128
private func invokeProtoc(
115
129
target: Target ,
116
130
invocation: Configuration . Invocation ,
117
131
protocPath: Path ,
118
132
protocGenGRPCSwiftPath: Path ,
119
- outputDirectory: Path
133
+ outputDirectory: Path ,
134
+ importPaths: [ Path ]
120
135
) -> Command {
121
136
// Construct the `protoc` arguments.
122
137
var protocArgs = [
123
138
" --plugin=protoc-gen-grpc-swift= \( protocGenGRPCSwiftPath) " ,
124
139
" --grpc-swift_out= \( outputDirectory) " ,
125
- // We include the target directory as a proto search path
126
- " -I " ,
127
- " \( target. directory) " ,
128
140
]
129
141
142
+ importPaths. forEach { path in
143
+ protocArgs. append ( " -I " )
144
+ protocArgs. append ( " \( path) " )
145
+ }
146
+
130
147
if let visibility = invocation. visibility {
131
148
protocArgs. append ( " --grpc-swift_opt=Visibility= \( visibility. rawValue. capitalized) " )
132
149
}
0 commit comments