diff --git a/docs/running-calyx/fud2/index.md b/docs/running-calyx/fud2/index.md index 6ae9088bf..5d7771d72 100644 --- a/docs/running-calyx/fud2/index.md +++ b/docs/running-calyx/fud2/index.md @@ -79,6 +79,7 @@ Here are some options you might need: * `emit`: Just print the Ninja build file to stdout. The `gen` mode is therefore approximately `fud2 -m emit > .fud2/build.ninja`. * `plan`: Print a brief description of the plan, i.e., the sequence of operations that the build would run. * `dot`: Print a [GraphViz][] depiction of the plan. Try `fud2 -m dot | dot -Tpdf > graph.pdf` and take a look. + * `cmds`: Print the commands Ninja would run when executing the plan, but do not execute them. There are also some subcommands for doing things other than building stuff: diff --git a/fud2/fud-core/src/cli.rs b/fud2/fud-core/src/cli.rs index 7e9635a04..2b5c978e7 100644 --- a/fud2/fud-core/src/cli.rs +++ b/fud2/fud-core/src/cli.rs @@ -13,6 +13,7 @@ enum Mode { ShowDot, Generate, Run, + Cmds, } impl FromStr for Mode { @@ -25,6 +26,7 @@ impl FromStr for Mode { "gen" => Ok(Mode::Generate), "run" => Ok(Mode::Run), "dot" => Ok(Mode::ShowDot), + "cmds" => Ok(Mode::Cmds), _ => Err("unknown mode".to_string()), } } @@ -38,6 +40,7 @@ impl Display for Mode { Mode::Generate => write!(f, "gen"), Mode::Run => write!(f, "run"), Mode::ShowDot => write!(f, "dot"), + Mode::Cmds => write!(f, "cmds"), } } } @@ -380,7 +383,8 @@ pub fn cli(driver: &Driver, config: &figment::Figment) -> anyhow::Result<()> { Mode::ShowDot => run.show_dot(), Mode::EmitNinja => run.emit_to_stdout()?, Mode::Generate => run.emit_to_dir(&workdir)?.keep(), - Mode::Run => run.emit_and_run(&workdir)?, + Mode::Run => run.emit_and_run(&workdir, false)?, + Mode::Cmds => run.emit_and_run(&workdir, true)?, } Ok(()) diff --git a/fud2/fud-core/src/run.rs b/fud2/fud-core/src/run.rs index 0f55d3eae..c61993e80 100644 --- a/fud2/fud-core/src/run.rs +++ b/fud2/fud-core/src/run.rs @@ -336,8 +336,10 @@ impl<'a> Run<'a> { Ok(dir) } - /// Emit `build.ninja` to a temporary directory and then actually execute ninja. - pub fn emit_and_run(&self, dir: &Utf8Path) -> EmitResult { + /// Emit `build.ninja` to a temporary directory and then actually execute Ninja. + /// + /// If `print_cmds` is true, Ninja will print commands it is to run instead of executing them. + pub fn emit_and_run(&self, dir: &Utf8Path, print_cmds: bool) -> EmitResult { // Emit the Ninja file. let dir = self.emit_to_dir(dir)?; @@ -369,6 +371,10 @@ impl<'a> Run<'a> { cmd.arg("--verbose"); } + if print_cmds { + cmd.arg("-tcommands"); + } + cmd.stdout(std::io::stderr()); // Send Ninja's stdout to our stderr. let status = cmd.status().map_err(ninja_cmd_io_error)?;