From 91a55ec7714d4b96bdef530c25ebbd30239787d1 Mon Sep 17 00:00:00 2001 From: bendk Date: Tue, 21 Nov 2023 17:32:47 -0500 Subject: [PATCH] Install setuptools in Builder (#2671) Co-authored-by: Jan-Erik Rediger --- Cargo.lock | 1 + glean-core/build/Cargo.toml | 3 +++ glean-core/build/src/lib.rs | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 4826fba66d..6f70e0e1e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -340,6 +340,7 @@ dependencies = [ name = "glean-build" version = "10.0.0" dependencies = [ + "tempfile", "xshell-venv", ] diff --git a/glean-core/build/Cargo.toml b/glean-core/build/Cargo.toml index 09b7e728c1..77dc04c657 100644 --- a/glean-core/build/Cargo.toml +++ b/glean-core/build/Cargo.toml @@ -17,3 +17,6 @@ rust-version = "1.63" [dependencies] xshell-venv = "1.1.0" + +[dev-dependencies] +tempfile = "3.8.0" diff --git a/glean-core/build/src/lib.rs b/glean-core/build/src/lib.rs index 4f8844565c..eabcf408cf 100644 --- a/glean-core/build/src/lib.rs +++ b/glean-core/build/src/lib.rs @@ -110,6 +110,8 @@ impl Builder { let venv = VirtualEnv::new(&sh, "py3-glean_parser")?; let glean_parser = format!("glean_parser~={GLEAN_PARSER_VERSION}"); + // TODO: Remove after we switched glean_parser away from legacy setup.py + venv.pip_install("setuptools")?; venv.pip_install(&glean_parser)?; for file in &self.files { @@ -123,3 +125,33 @@ impl Builder { Ok(()) } } + +#[cfg(test)] +mod test { + use std::{env, fs, path::PathBuf}; + + use super::*; + + #[test] + fn test_builder() { + let package_root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + // clean out the previous venv, if it exists + let venv_dir = package_root.join("target").join("venv-py3-glean_parser"); + if venv_dir.exists() { + fs::remove_dir_all(venv_dir).unwrap(); + } + let metrics_yaml = package_root + .parent() + .unwrap() + .parent() + .unwrap() + .join("samples") + .join("rust") + .join("metrics.yaml"); + let out_dir = tempfile::tempdir().unwrap(); + Builder::with_output(out_dir.path().to_string_lossy()) + .file(metrics_yaml.to_string_lossy()) + .generate() + .expect("Error generating Glean bindings"); + } +}