From 1406c0f8914347d45dbbe99b21a92606991c36ac Mon Sep 17 00:00:00 2001 From: Andrew Mackenzie Date: Wed, 18 May 2022 14:54:23 +0200 Subject: [PATCH] Fix compiling when in package subdir via use of FLOW_CONTEXT_DIR env var --- flowsamples/build.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/flowsamples/build.rs b/flowsamples/build.rs index be2c7d7b6f..be2f53e553 100644 --- a/flowsamples/build.rs +++ b/flowsamples/build.rs @@ -1,6 +1,6 @@ //! Build script to compile the flow flowsamples in the crate use std::{fs, io}; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::process::Command; fn main() -> io::Result<()> { @@ -29,9 +29,14 @@ fn main() -> io::Result<()> { } fn get_context_root() -> Result { - let samples_dir = Path::new(env!("CARGO_MANIFEST_DIR")).parent() - .ok_or("Could not get parent dir")?; - let context_root = samples_dir.join("flowr/src/context"); + let context_root = match std::env::var("FLOW_CONTEXT_ROOT") { + Ok(var) => PathBuf::from(&var), + Err(_) => { + let samples_dir = Path::new(env!("CARGO_MANIFEST_DIR")).parent() + .ok_or("Could not get parent dir")?; + samples_dir.join("flowr/src/context") + } + }; assert!(context_root.exists(), "Context root directory '{}' does not exist", context_root.display()); Ok(context_root.to_str()