Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Cow import no longer needed if you simplify to &Path

Drop this import once you replace Cow<Path> with &Path as suggested below.

- use std::borrow::Cow;

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/runner.rs around line 11, the use std::borrow::Cow import is unnecessary
once you replace Cow<Path> with &Path; update function signatures and local
variables that currently use Cow<Path> to accept &Path instead, adjust any call
sites to pass a reference (and replace Cow-specific methods with &Path
equivalents like as_ref()/to_path_buf() or direct &), then remove the `use
std::borrow::Cow;` line; ensure lifetimes and mutable/ownership expectations are
satisfied by borrowing or cloning where required.

use std::fs;
use std::io::{self, BufRead, BufReader, Write};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -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<NamedTempFile>) = if let Some(path) = &args.emit {
// duration of the Ninja invocation. Borrow the emitted path when provided
// to avoid unnecessary allocation.
Comment on lines +118 to +120
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Correct the comment: path canonicalization happens in run_ninja, not here

Avoid misleading readers about where normalisation occurs; keep the focus on lifetimes and borrowing.

-    // 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.
+    // Keep the temporary build file alive for the duration of the Ninja
+    // invocation. Borrow the emitted path when provided to avoid unnecessary
+    // allocation; run_ninja canonicalizes the path.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// 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.
// Keep the temporary build file alive for the duration of the Ninja
// invocation. Borrow the emitted path when provided to avoid unnecessary
// allocation; run_ninja canonicalizes the path.
🤖 Prompt for AI Agents
In src/runner.rs around lines 118 to 120, the comment incorrectly states that
path canonicalization/normalization happens here; update the comment to remove
that claim and instead describe only keeping the temporary file alive for the
duration of the Ninja invocation and borrowing the emitted path to avoid
allocation, focusing on lifetimes/borrowing rather than normalization location.

let (build_path, _tmp): (Cow<Path>, Option<NamedTempFile>) = 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)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Pass build_path directly after the simplification

If you adopt the &Path refactor above, remove the .as_ref() call here.

-    run_ninja(program.as_path(), cli, build_path.as_ref(), &targets)?;
+    run_ninja(program.as_path(), cli, build_path, &targets)?;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
run_ninja(program.as_path(), cli, build_path.as_ref(), &targets)?;
run_ninja(program.as_path(), cli, build_path, &targets)?;
🤖 Prompt for AI Agents
In src/runner.rs around line 138, the call currently uses build_path.as_ref();
remove the unnecessary .as_ref() and pass build_path directly (or as a borrowed
reference if needed, e.g. &build_path) so the argument matches the simplified
&Path type expected by run_ninja.

Ok(())
}

Expand Down
Loading