use 'capnp_executable()' fluent method instead of 'run_with()'
@@ -90,6 +90,7 @@ pub struct CompilerCommand {
src_prefixes: Vec<PathBuf>,
import_paths: Vec<PathBuf>,
no_standard_import: bool,
+ executable_path: Option<PathBuf>,
output_path: Option<PathBuf>,
}
@@ -101,6 +102,7 @@ impl CompilerCommand {
src_prefixes: Vec::new(),
import_paths: Vec::new(),
no_standard_import: false,
+ executable_path: None,
output_path: None,
}
}
@@ -137,6 +139,8 @@ impl CompilerCommand {
/// Adds the --no-standard-import flag, indicating that the default import paths of
/// /usr/include and /usr/local/include should not bet included.
pub fn no_standard_import(&mut self) -> &mut CompilerCommand {
+ assert!(!self.no_standard_import, "no_standard_import() must only be called once");
+
self.no_standard_import = true;
self
}
@@ -146,23 +150,33 @@ impl CompilerCommand {
where
P: AsRef<Path>,
{
+ assert!(self.executable_path.is_none(), "output_path() must only be called once");
+
self.output_path = Some(path.as_ref().to_path_buf());
self
}
- /// Runs the command, assuming a 'capnp' executable is accessible from current working directory (e.g. locally or in PATH environment variable).
- /// Returns an error if `OUT_DIR` or a custom output directory was not set or if `capnp compile` fails.
- pub fn run(&mut self) -> ::capnp::Result<()> {
- self.run_with("capnp")
- }
-
- /// Runs the command, using a custom capnp `executable` path (not a directory).
- /// Returns an error if `OUT_DIR` or a custom output directory was not set or if `<executable> compile` fails.
- pub fn run_with<P>(&mut self, executable: P) -> ::capnp::Result<()>
+ /// Specify the executable which is used for the 'capnp' tool. When this method is not called, the command looks for a name 'capnp'
+ /// on the system (e.g. in working directory or in PATH environment variable).
+ pub fn capnp_executable<P>(&mut self, path: P) -> &mut CompilerCommand
where
P: AsRef<Path>
{
- let mut command = ::std::process::Command::new(executable.as_ref());
+ assert!(self.executable_path.is_none(), "capnp_executable() must only be called once");
+
+ self.executable_path = Some(path.as_ref().to_path_buf());
+ self
+ }
+
+ /// Runs the command.
+ /// Returns an error if `OUT_DIR` or a custom output directory was not set, or if `capnp compile` fails.
+ pub fn run(&mut self) -> ::capnp::Result<()> {
+ let mut command = if let Some(executable) = &self.executable_path {
+ ::std::process::Command::new(executable)
+ } else {
+ ::std::process::Command::new("capnp")
+ };
+
command.arg("compile").arg("-o").arg("-");
if self.no_standard_import {
