diff --git a/Cargo.lock b/Cargo.lock index cfde9f19..b4606d1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3218,7 +3218,7 @@ dependencies = [ [[package]] name = "rattler-build" -version = "0.35.3" +version = "0.35.4" dependencies = [ "ansi-to-tui", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index fc9bdadc..0ff36e49 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = ["rust-tests"] [package] name = "rattler-build" -version = "0.35.3" +version = "0.35.4" authors = ["rattler-build contributors "] repository = "https://github.com/prefix-dev/rattler-build" edition = "2021" diff --git a/py-rattler-build/Cargo.lock b/py-rattler-build/Cargo.lock index b483d6b2..793e3d2b 100644 --- a/py-rattler-build/Cargo.lock +++ b/py-rattler-build/Cargo.lock @@ -2915,7 +2915,7 @@ dependencies = [ [[package]] name = "py-rattler-build" -version = "0.35.3" +version = "0.35.4" dependencies = [ "pyo3", "pyo3-build-config", @@ -3137,7 +3137,7 @@ dependencies = [ [[package]] name = "rattler-build" -version = "0.35.3" +version = "0.35.4" dependencies = [ "anyhow", "async-once-cell", diff --git a/py-rattler-build/Cargo.toml b/py-rattler-build/Cargo.toml index bbbf3c7a..e1ffb7f4 100644 --- a/py-rattler-build/Cargo.toml +++ b/py-rattler-build/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "py-rattler-build" -version = "0.35.3" +version = "0.35.4" edition = "2021" license = "BSD-3-Clause" publish = false diff --git a/src/main.rs b/src/main.rs index 13138622..4f4fb177 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ use rattler_build::{ opt::{App, BuildData, ShellCompletion, SubCommands}, rebuild_from_args, run_test_from_args, upload_from_args, }; -use tempfile::tempdir; +use tempfile::{tempdir, TempDir}; fn main() -> miette::Result<()> { // Initialize sandbox in sync/single-threaded context before tokio runtime @@ -73,7 +73,9 @@ async fn async_main() -> miette::Result<()> { let recipes = build_args.recipe.clone(); let recipe_dir = build_args.recipe_dir.clone(); let build_data = BuildData::from(build_args); - let recipe_paths = recipe_paths(recipes, recipe_dir)?; + + // Get all recipe paths and keep tempdir alive until end of the function + let (recipe_paths, _temp_dir) = recipe_paths(recipes, recipe_dir)?; if recipe_paths.is_empty() { miette::bail!("Couldn't detect any recipes.") @@ -124,13 +126,15 @@ async fn async_main() -> miette::Result<()> { fn recipe_paths( recipes: Vec, recipe_dir: Option, -) -> Result, miette::Error> { +) -> Result<(Vec, Option), miette::Error> { let mut recipe_paths = Vec::new(); - let temp_dir = tempdir().into_diagnostic()?; + let mut temp_dir_opt = None; if !std::io::stdin().is_terminal() && recipes.len() == 1 && get_recipe_path(&recipes[0]).is_err() { + let temp_dir = tempdir().into_diagnostic()?; + let recipe_path = temp_dir.path().join("recipe.yaml"); io::copy( &mut io::stdin(), @@ -138,6 +142,7 @@ fn recipe_paths( ) .into_diagnostic()?; recipe_paths.push(get_recipe_path(&recipe_path)?); + temp_dir_opt = Some(temp_dir); } else { for recipe_path in &recipes { recipe_paths.push(get_recipe_path(recipe_path)?); @@ -153,5 +158,6 @@ fn recipe_paths( } } } - Ok(recipe_paths) + + Ok((recipe_paths, temp_dir_opt)) } diff --git a/test/end-to-end/helpers.py b/test/end-to-end/helpers.py index d01785b3..2d7ca682 100644 --- a/test/end-to-end/helpers.py +++ b/test/end-to-end/helpers.py @@ -11,7 +11,10 @@ def __init__(self, path): def __call__(self, *args: Any, **kwds: Any) -> Any: try: - return check_output([str(self.path), *args], **kwds).decode("utf-8") + output = check_output([str(self.path), *args], **kwds) + if "text" not in kwds: + return output.decode("utf-8") + return output except CalledProcessError as e: if kwds.get("stderr") is None: print(e.output) diff --git a/test/end-to-end/test_simple.py b/test/end-to-end/test_simple.py index 1c28b78a..3a38a1cc 100644 --- a/test/end-to-end/test_simple.py +++ b/test/end-to-end/test_simple.py @@ -1227,3 +1227,15 @@ def test_abi3(rattler_build: RattlerBuild, recipes: Path, tmp_path: Path): assert index["noarch"] == "python" assert index["subdir"] == host_subdir() assert index["platform"] == host_subdir().split("-")[0] + + +# This is how cf-scripts is using rattler-build - rendering recipes from stdin +def test_rendering_from_stdin( + rattler_build: RattlerBuild, recipes: Path, tmp_path: Path +): + text = (recipes / "abi3" / "recipe.yaml").read_text() + # variants = recipes / "abi3" / "variants.yaml" "-m", variants + rendered = rattler_build("build", "--render-only", input=text, text=True) + loaded = json.loads(rendered) + + assert loaded[0]["recipe"]["package"]["name"] == "python-abi3-package-sample"