diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2022-08-30 18:25:16 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-30 18:25:16 -0400 |
commit | 14808b3a2ec8d1d69f319b5e7a10d074fee615b3 (patch) | |
tree | de2682e781ad5a64302d4fafc362a74fc2592881 /build.rs | |
parent | 28b50957708855c94e8fa72cf0a6bce604cdf00c (diff) |
ci: completion/manpage generation script spring cleaning (#795)
* ci: spring cleaning of completions autogen
This commit changes a few things/cleans up stuff:
- Completion and manpage generation now drops the files off in
`./target/tmp/bottom` rather than arbitrarily in the build directory.
This was originally done because I was lazy and just needed it to work
in CI, but it's kinda gross if you want to build the manpages in your
own directory.
- CI was updated to handle this.
- Only run if the `BTM_GENERATE` env var is actually non-empty.
* docs: update for manpage/completion gen
* ci: auto delete autogen comp/manpage dir
* ci: fix incorrect mv for autogen
The mv was too late, should be earlier in the workflow.
* ci: specify shell in autogen delete
* docs: more updates to manpage/comp docs
* ci: unify env vars
* ci: skip autogen on build-msi
Diffstat (limited to 'build.rs')
-rw-r--r-- | build.rs | 51 |
1 files changed, 29 insertions, 22 deletions
@@ -23,32 +23,39 @@ fn create_dir(dir: &Path) -> Result<()> { } fn main() -> Result<()> { - if env::var_os("BTM_GENERATE").is_some() { - // OUT_DIR is where extra build files are written to for Cargo. - let completion_out_dir = PathBuf::from("completion"); - let manpage_out_dir = PathBuf::from("manpage"); - - create_dir(&completion_out_dir)?; - create_dir(&manpage_out_dir)?; - - // Generate completions - let mut app = build_app(); - generate_to(Shell::Bash, &mut app, "btm", &completion_out_dir)?; - generate_to(Shell::Zsh, &mut app, "btm", &completion_out_dir)?; - generate_to(Shell::Fish, &mut app, "btm", &completion_out_dir)?; - generate_to(Shell::PowerShell, &mut app, "btm", &completion_out_dir)?; - generate_to(Shell::Elvish, &mut app, "btm", &completion_out_dir)?; - - // Generate manpage - let app = app.name("btm"); - let man = clap_mangen::Man::new(app); - let mut buffer: Vec<u8> = Default::default(); - man.render(&mut buffer)?; - std::fs::write(manpage_out_dir.join("btm.1"), buffer)?; + const COMPLETION_DIR: &str = "target/tmp/bottom/completion"; + const MANPAGE_DIR: &str = "target/tmp/bottom/manpage"; + + match env::var_os("BTM_GENERATE") { + Some(var) if !var.is_empty() => { + let completion_out_dir = PathBuf::from(COMPLETION_DIR); + let manpage_out_dir = PathBuf::from(MANPAGE_DIR); + + create_dir(&completion_out_dir)?; + create_dir(&manpage_out_dir)?; + + // Generate completions + let mut app = build_app(); + generate_to(Shell::Bash, &mut app, "btm", &completion_out_dir)?; + generate_to(Shell::Zsh, &mut app, "btm", &completion_out_dir)?; + generate_to(Shell::Fish, &mut app, "btm", &completion_out_dir)?; + generate_to(Shell::PowerShell, &mut app, "btm", &completion_out_dir)?; + generate_to(Shell::Elvish, &mut app, "btm", &completion_out_dir)?; + + // Generate manpage + let app = app.name("btm"); + let man = clap_mangen::Man::new(app); + let mut buffer: Vec<u8> = Default::default(); + man.render(&mut buffer)?; + std::fs::write(manpage_out_dir.join("btm.1"), buffer)?; + } + _ => {} } println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=./src/clap.rs"); + println!("cargo:rerun-if-changed=.{}", COMPLETION_DIR); + println!("cargo:rerun-if-changed=.{}", MANPAGE_DIR); println!("cargo:rerun-if-env-changed=BTM_GENERATE"); Ok(()) |