From 0031717b2b3fb519c0a062ae0ae55efc58a68ff8 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Tue, 12 Nov 2024 12:33:05 +0100 Subject: [PATCH] glean-build: Allow overwrite of Python venv using `GLEAN_PYTHON_VENV_DIR` --- glean-core/build/src/lib.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/glean-core/build/src/lib.rs b/glean-core/build/src/lib.rs index e85913445b..a098e9b427 100644 --- a/glean-core/build/src/lib.rs +++ b/glean-core/build/src/lib.rs @@ -35,7 +35,7 @@ //! You can then access your metrics and pings directly by name within the `metrics` module. //! //! [`glean-parser`]: https://github.com/mozilla/glean_parser/ -use std::env; +use std::{env, path::PathBuf}; use xshell_venv::{Result, Shell, VirtualEnv}; @@ -107,12 +107,19 @@ impl Builder { } let sh = Shell::new()?; - 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)?; + let venv = if let Ok(env_dir) = env::var("GLEAN_PYTHON_VENV_DIR") { + eprintln!("got env dir: {env_dir}"); + let env_path = PathBuf::from(env_dir); + VirtualEnv::with_path(&sh, &env_path)? + } else { + 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)?; + venv + }; for file in &self.files { println!("cargo:rerun-if-changed={file}");