diff --git a/glean-core/build/src/lib.rs b/glean-core/build/src/lib.rs index 451ce1a9ea..dab1a7dde0 100644 --- a/glean-core/build/src/lib.rs +++ b/glean-core/build/src/lib.rs @@ -45,6 +45,8 @@ const GLEAN_PARSER_VERSION: &str = "19.0.0"; pub struct Builder { files: Vec, out_dir: String, + env_dir: Option, + format: String, } impl Default for Builder { @@ -57,6 +59,8 @@ impl Default for Builder { Self { files: vec![], out_dir, + env_dir: None, + format: String::from("rust"), } } } @@ -70,6 +74,8 @@ impl Builder { Self { files: vec![], out_dir: out_dir.into(), + env_dir: None, + format: String::from("rust"), } } @@ -81,6 +87,12 @@ impl Builder { self } + /// Change output format. Defaults to `rust`. + pub fn format>(&mut self, format: S) -> &mut Self { + self.format = format.into(); + self + } + /// Add multiple definition files, e.g. `metrics.yaml` or `pings.yaml`. pub fn files

(&mut self, files: P) -> &mut Self where @@ -93,6 +105,15 @@ impl Builder { self } + /// Set environment path to use. + pub fn env_dir

(&mut self, path: P) -> &mut Self + where + P: Into, + { + self.env_dir = Some(path.into()); + self + } + /// Generate the Rust bindings. /// /// The consumer must include the generated `glean_metrics.rs` file, e.g.: @@ -111,6 +132,8 @@ impl Builder { eprintln!("got env dir: {env_dir}"); let env_path = PathBuf::from(env_dir); VirtualEnv::with_path(&sh, &env_path)? + } else if let Some(env_dir) = &self.env_dir { + VirtualEnv::with_path(&sh, env_dir)? } else { let venv = VirtualEnv::new(&sh, "py3-glean_parser")?; @@ -125,7 +148,8 @@ impl Builder { println!("cargo:rerun-if-changed={file}"); } - let mut args = vec!["translate", "--format", "rust", "--output", out_dir]; + let mut args = vec!["translate", "--output", out_dir]; + args.extend(["--format", &self.format]); args.extend(self.files.iter().map(|s| s.as_str())); venv.run_module("glean_parser", &args)?;