From 57c62d236b7bf62e0bc4efcb82d02248927b687e Mon Sep 17 00:00:00 2001 From: Leynos Date: Sat, 9 Aug 2025 00:16:22 +0100 Subject: [PATCH 1/3] Use Cow for build path --- src/runner.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/runner.rs b/src/runner.rs index ff170246..eba33db4 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -8,6 +8,7 @@ use crate::cli::{BuildArgs, Cli, Commands}; use crate::{ir::BuildGraph, manifest, ninja_gen}; use anyhow::{Context, Result}; use serde_json; +use std::borrow::Cow; use std::fs; use std::io::{self, BufRead, BufReader, Write}; use std::path::{Path, PathBuf}; @@ -115,17 +116,18 @@ fn handle_build(cli: &Cli, args: &BuildArgs) -> Result<()> { let targets = BuildTargets::new(&args.targets); // Normalise the build file path and keep the temporary file alive for the - // duration of the Ninja invocation. - let (build_path, _tmp): (PathBuf, Option) = if let Some(path) = &args.emit { + // duration of the Ninja invocation. Borrow the emitted path when provided + // to avoid unnecessary allocation. + let (build_path, _tmp): (Cow, Option) = if let Some(path) = &args.emit { write_ninja_file(path, &ninja)?; - (path.clone(), None) + (Cow::Borrowed(path.as_path()), None) } else { let tmp = create_temp_ninja_file(&ninja)?; - (tmp.path().to_path_buf(), Some(tmp)) + (Cow::Owned(tmp.path().to_path_buf()), Some(tmp)) }; let program = resolve_ninja_program(); - run_ninja(program.as_path(), cli, &build_path, &targets)?; + run_ninja(program.as_path(), cli, build_path.as_ref(), &targets)?; Ok(()) } From cef1c15b234a68f1dac3169cde191e8256821ea1 Mon Sep 17 00:00:00 2001 From: Leynos Date: Sun, 10 Aug 2025 12:50:38 +0100 Subject: [PATCH 2/3] Borrow temporary build file path --- src/runner.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/runner.rs b/src/runner.rs index eba33db4..9d04df0b 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -118,16 +118,25 @@ fn handle_build(cli: &Cli, args: &BuildArgs) -> Result<()> { // Normalise the build file path and keep the temporary file alive for the // duration of the Ninja invocation. Borrow the emitted path when provided // to avoid unnecessary allocation. - let (build_path, _tmp): (Cow, Option) = if let Some(path) = &args.emit { + let build_path: Cow; + let mut tmp_file: Option = None; + if let Some(path) = &args.emit { write_ninja_file(path, &ninja)?; - (Cow::Borrowed(path.as_path()), None) + build_path = Cow::Borrowed(path.as_path()); } else { let tmp = create_temp_ninja_file(&ninja)?; - (Cow::Owned(tmp.path().to_path_buf()), Some(tmp)) - }; + tmp_file = Some(tmp); + build_path = Cow::Borrowed( + tmp_file + .as_ref() + .expect("temporary Ninja file should exist") + .path(), + ); + } let program = resolve_ninja_program(); run_ninja(program.as_path(), cli, build_path.as_ref(), &targets)?; + drop(tmp_file); Ok(()) } From 05f97ca8d845394b7d170c689472a246fbba6347 Mon Sep 17 00:00:00 2001 From: Leynos Date: Mon, 11 Aug 2025 12:30:57 +0100 Subject: [PATCH 3/3] Use en-GB-oxendict --- src/runner.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runner.rs b/src/runner.rs index 9d04df0b..7ce47d48 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -115,7 +115,7 @@ fn handle_build(cli: &Cli, args: &BuildArgs) -> Result<()> { let ninja = generate_ninja(cli)?; let targets = BuildTargets::new(&args.targets); - // Normalise the build file path and keep the temporary file alive for the + // Normalize the build file path and keep the temporary file alive for the // duration of the Ninja invocation. Borrow the emitted path when provided // to avoid unnecessary allocation. let build_path: Cow;