From 83e37bb040815fcd2f3a8db8fb6131a16635354b Mon Sep 17 00:00:00 2001 From: Ruiyang Wang Date: Sat, 3 Jan 2026 13:54:07 -0800 Subject: [PATCH] uudoc: move tldr.zip warning to build.rs Move the tldr.zip missing warning from runtime (uudoc.rs) to compile time (build.rs). This ensures the warning is printed only once during the build, instead of 100+ times when make calls uudoc separately for each utility. Fixes #9940 --- build.rs | 14 +++++++++++++- src/bin/uudoc.rs | 19 ------------------- tests/uudoc/mod.rs | 18 ++++++++++++------ 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/build.rs b/build.rs index 9b35eac5eb4..aabd968329b 100644 --- a/build.rs +++ b/build.rs @@ -3,7 +3,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -// spell-checker:ignore (vars) krate mangen +// spell-checker:ignore (vars) krate mangen tldr use std::env; use std::fs::File; @@ -19,6 +19,18 @@ pub fn main() { // See println!("cargo:rerun-if-changed=build.rs"); + // Check for tldr.zip when building uudoc to warn users once at build time + // instead of repeatedly at runtime for each utility + if env::var("CARGO_FEATURE_UUDOC").is_ok() && !Path::new("docs/tldr.zip").exists() { + println!( + "cargo:warning=No tldr archive found, so the documentation will not include examples." + ); + println!("cargo:warning=To include examples, download the tldr archive:"); + println!( + "cargo:warning= curl -L https://github.com/tldr-pages/tldr/releases/latest/download/tldr.zip -o docs/tldr.zip" + ); + } + if let Ok(profile) = env::var("PROFILE") { println!("cargo:rustc-cfg=build={profile:?}"); } diff --git a/src/bin/uudoc.rs b/src/bin/uudoc.rs index 392375f9edb..fe536b8e07b 100644 --- a/src/bin/uudoc.rs +++ b/src/bin/uudoc.rs @@ -133,19 +133,6 @@ fn gen_completions(args: impl Iterator, util_map: &Uti process::exit(0); } -/// print tldr error -fn print_tldr_error() { - eprintln!("Warning: No tldr archive found, so the documentation will not include examples."); - eprintln!( - "To include examples in the documentation, download the tldr archive and put it in the docs/ folder." - ); - eprintln!(); - eprintln!( - " curl -L https://github.com/tldr-pages/tldr/releases/latest/download/tldr.zip -o docs/tldr.zip" - ); - eprintln!(); -} - /// # Errors /// Returns an error if the writer fails. #[allow(clippy::too_many_lines)] @@ -162,9 +149,6 @@ fn main() -> io::Result<()> { match command { "manpage" => { let args_iter = args.into_iter().skip(2); - if tldr_zip.is_none() { - print_tldr_error(); - } gen_manpage( &mut tldr_zip, args_iter, @@ -186,9 +170,6 @@ fn main() -> io::Result<()> { } } } - if tldr_zip.is_none() { - print_tldr_error(); - } let utils = util_map::>>(); match std::fs::create_dir("docs/src/utils/") { Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => Ok(()), diff --git a/tests/uudoc/mod.rs b/tests/uudoc/mod.rs index 455d3984f0e..010d6cda363 100644 --- a/tests/uudoc/mod.rs +++ b/tests/uudoc/mod.rs @@ -28,9 +28,11 @@ fn test_manpage_generation() { "Command failed with status: {}", output.status ); + // Note: tldr warning is now printed at build time (in build.rs), not at runtime assert!( - String::from_utf8_lossy(&output.stderr).contains("Warning: No tldr archive found"), - "stderr should contains tldr alert", + output.stderr.is_empty(), + "stderr should be empty but got: {}", + String::from_utf8_lossy(&output.stderr) ); let output_str = String::from_utf8_lossy(&output.stdout); @@ -52,9 +54,11 @@ fn test_manpage_coreutils() { "Command failed with status: {}", output.status ); + // Note: tldr warning is now printed at build time (in build.rs), not at runtime assert!( - String::from_utf8_lossy(&output.stderr).contains("Warning: No tldr archive found"), - "stderr should contains tldr alert", + output.stderr.is_empty(), + "stderr should be empty but got: {}", + String::from_utf8_lossy(&output.stderr) ); let output_str = String::from_utf8_lossy(&output.stdout); @@ -123,9 +127,11 @@ fn test_manpage_base64() { "Command failed with status: {}", output.status ); + // Note: tldr warning is now printed at build time (in build.rs), not at runtime assert!( - String::from_utf8_lossy(&output.stderr).contains("Warning: No tldr archive found"), - "stderr should contains tldr alert", + output.stderr.is_empty(), + "stderr should be empty but got: {}", + String::from_utf8_lossy(&output.stderr) ); let output_str = String::from_utf8_lossy(&output.stdout);