@@ -186,6 +186,15 @@ impl CompilerCommand {
186
186
self
187
187
}
188
188
189
+ /// Internal function for starting to build a capnp command.
190
+ fn new_command ( & self ) -> :: std:: process:: Command {
191
+ if let Some ( executable) = & self . executable_path {
192
+ :: std:: process:: Command :: new ( executable)
193
+ } else {
194
+ :: std:: process:: Command :: new ( "capnp" )
195
+ }
196
+ }
197
+
189
198
/// Sets the default parent module. This indicates the scope in your crate where you will
190
199
/// add a module containing the generated code. For example, if you set this option to
191
200
/// `vec!["foo".into(), "bar".into()]`, and you are generating code for `baz.capnp`, then your crate
@@ -222,11 +231,28 @@ impl CompilerCommand {
222
231
/// Runs the command.
223
232
/// Returns an error if `OUT_DIR` or a custom output directory was not set, or if `capnp compile` fails.
224
233
pub fn run ( & mut self ) -> :: capnp:: Result < ( ) > {
225
- let mut command = if let Some ( executable) = & self . executable_path {
226
- :: std:: process:: Command :: new ( executable)
227
- } else {
228
- :: std:: process:: Command :: new ( "capnp" )
229
- } ;
234
+ match self . new_command ( ) . arg ( "--version" ) . output ( ) {
235
+ Err ( error) => {
236
+ return Err ( :: capnp:: Error :: failed ( format ! (
237
+ "Failed to execute `capnp --version`: {error}. \
238
+ Please verify that version 0.5.2 or higher of the capnp executable \
239
+ is installed on your system. See https://capnproto.org/install.html"
240
+ ) ) )
241
+ }
242
+ Ok ( output) => {
243
+ if !output. status . success ( ) {
244
+ return Err ( :: capnp:: Error :: failed ( format ! (
245
+ "`capnp --version` returned an error: {:?}. \
246
+ Please verify that version 0.5.2 or higher of the capnp executable \
247
+ is installed on your system. See https://capnproto.org/install.html",
248
+ output. status
249
+ ) ) ) ;
250
+ }
251
+ // TODO Parse the version string?
252
+ }
253
+ }
254
+
255
+ let mut command = self . new_command ( ) ;
230
256
231
257
command. arg ( "compile" ) . arg ( "-o" ) . arg ( "-" ) ;
232
258
@@ -288,9 +314,7 @@ impl CompilerCommand {
288
314
289
315
run_command ( command, code_generation_command) . map_err ( |error| {
290
316
:: capnp:: Error :: failed ( format ! (
291
- "Error while trying to execute `capnp compile`: {error}. \
292
- Please verify that version 0.5.2 or higher of the capnp executable \
293
- is installed on your system. See https://capnproto.org/install.html"
317
+ "Error while trying to execute `capnp compile`: {error}."
294
318
) )
295
319
} )
296
320
}
0 commit comments