From c24212406e47af2648a9e7d78c85aad263c001c7 Mon Sep 17 00:00:00 2001 From: Shinyzenith Date: Sat, 30 Jul 2022 04:13:36 +0530 Subject: [PATCH] [BuildSystem] Scdoc generation with build.rs Signed-off-by: Shinyzenith --- INSTALL.md | 4 ++-- Makefile | 17 +++++------------ README.md | 4 ++-- build.rs | 33 +++++++++++++++++++++++++++++++++ contrib/PKGBUILD | 13 ++++++------- swhkd/src/daemon.rs | 10 +++------- swhkd/src/tests.rs | 2 +- 7 files changed, 52 insertions(+), 31 deletions(-) create mode 100644 build.rs diff --git a/INSTALL.md b/INSTALL.md index 5348104..8abe656 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -2,7 +2,7 @@ We have packaged `swhkd-git`. `swhkd-bin` has been packaged separately by a user of swhkd. -# Install +# Building: `swhkd` and `swhks` install to `/usr/local/bin/` by default. You can change this behaviour by editing the [Makefile](../Makefile) variable, `TARGET_DIR`. @@ -17,7 +17,7 @@ We have packaged `swhkd-git`. `swhkd-bin` has been packaged separately by a user **Compile time:** - git -- scdoc +- scdoc (If present, man-pages will be generated) - make - rustup diff --git a/Makefile b/Makefile index e10ee7b..ead90e8 100644 --- a/Makefile +++ b/Makefile @@ -15,19 +15,13 @@ build: @cargo build $(BUILDFLAGS) install: - @scdoc < ./docs/$(DAEMON_BINARY).1.scd > ./docs/$(DAEMON_BINARY).1.gz - @scdoc < ./docs/$(SERVER_BINARY).1.scd > ./docs/$(SERVER_BINARY).1.gz - @scdoc < ./docs/$(DAEMON_BINARY).5.scd > ./docs/$(DAEMON_BINARY).5.gz - @scdoc < ./docs/$(DAEMON_BINARY)-keys.5.scd > ./docs/$(DAEMON_BINARY)-keys.5.gz @mkdir -p $(MAN1_DIR) @mkdir -p $(MAN5_DIR) @mkdir -p $(POLKIT_DIR) @mkdir -p $(TARGET_DIR) @mkdir -p /etc/$(DAEMON_BINARY) - @mv ./docs/$(DAEMON_BINARY).1.gz $(MAN1_DIR) - @mv ./docs/$(SERVER_BINARY).1.gz $(MAN1_DIR) - @mv ./docs/$(DAEMON_BINARY).5.gz $(MAN5_DIR) - @mv ./docs/$(DAEMON_BINARY)-keys.5.gz $(MAN5_DIR) + @find ./docs -type f -iname "*.1.gz" -exec cp {} $(MAN1_DIR) \; + @find ./docs -type f -iname "*.7.gz" -exec cp {} $(MAN7_DIR) \; @touch /etc/$(DAEMON_BINARY)/$(DAEMON_BINARY)rc @cp ./target/release/$(DAEMON_BINARY) $(TARGET_DIR) @cp ./target/release/$(SERVER_BINARY) $(TARGET_DIR) @@ -36,10 +30,8 @@ install: @chmod +x $(TARGET_DIR)/$(SERVER_BINARY) uninstall: - @rm -f $(MAN1_DIR)/$(DAEMON_BINARY).1.gz - @rm -f $(MAN1_DIR)/$(SERVER_BINARY).1.gz - @rm -f $(MAN5_DIR)/$(DAEMON_BINARY).5.gz - @rm -f $(MAN5_DIR)/$(DAEMON_BINARY)-keys.5.gz + @rm -f /usr/share/man/**/swhkd.* + @rm -f /usr/share/man/**/swhks.* @rm $(TARGET_DIR)/$(SERVER_BINARY) @rm $(TARGET_DIR)/$(DAEMON_BINARY) @rm $(POLKIT_DIR)/$(POLKIT_POLICY_FILE) @@ -59,6 +51,7 @@ test: clean: @cargo clean + @rm ./docs/*.gz setup: @rustup install stable diff --git a/README.md b/README.md index f5f3707..28cb18e 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,9 @@ It also attempts to be a drop-in replacement for sxhkd, meaning your sxhkd confi Because swhkd can be used anywhere, the same swhkd config can be used across Xorg or Wayland desktops, and you can even use swhkd in a tty. -## Installation: +## Installation and Building: -[Installation instructions can be found here.](./INSTALL.md) +[Installation and building instructions can be found here.](./INSTALL.md) ## Running: diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..b58765b --- /dev/null +++ b/build.rs @@ -0,0 +1,33 @@ +use std::{fs::read_dir, io::ErrorKind, process::exit, process::Command}; + +fn main() { + // Check if scdoc command exists + match Command::new("scdoc").spawn() { + Err(e) => { + if let ErrorKind::NotFound = e.kind() { + exit(0); + } + } + _ => {} + } + + let mut man_pages: Vec<(String, String)> = Vec::new(); + for path in read_dir("./docs").unwrap() { + let path = path.unwrap(); + if path.file_type().unwrap().is_dir() { + continue; + } + + if let Some(file_name) = path.path().to_str() { + let man_page_name = file_name.replace(".scd", ".gz"); + man_pages.push((file_name.to_string(), man_page_name)); + } + } + + for man_page in man_pages { + _ = Command::new("sh") + .arg("-c") + .arg(format!("scdoc <{}>{}", man_page.0, man_page.1)) + .spawn(); + } +} diff --git a/contrib/PKGBUILD b/contrib/PKGBUILD index bcebfc5..2553c99 100644 --- a/contrib/PKGBUILD +++ b/contrib/PKGBUILD @@ -5,7 +5,7 @@ _pkgname="swhkd" pkgname="${_pkgname}-git" pkgver=.543.gf6ea9d6 -pkgrel=1 +pkgrel=2 arch=("x86_64") url="https://github.com/waycrate/swhkd" pkgdesc="A display server independent hotkey daemon inspired by sxhkd." @@ -18,10 +18,6 @@ sha256sums=("SKIP") build(){ cd "$_pkgname" - scdoc < ./docs/swhkd.1.scd > ./docs/swhkd.1.gz - scdoc < ./docs/swhks.1.scd > ./docs/swhks.1.gz - scdoc < ./docs/swhkd.5.scd > ./docs/swhkd.5.gz - scdoc < ./docs/swhkd-keys.5.scd > ./docs/swhkd-keys.5.gz make setup make } @@ -32,8 +28,11 @@ package() { install -Dm 755 ./target/release/swhks "$pkgdir/usr/bin/swhks" install -Dm 644 -o root ./com.github.swhkd.pkexec.policy -t "$pkgdir/usr/share/polkit-1/actions" - install -Dm 644 ./docs/*.1.gz -t "$pkgdir/usr/share/man/man1/" - install -Dm 644 ./docs/*.5.gz -t "$pkgdir/usr/share/man/man5/" + + install -Dm 644 ./docs/swhkd.1.gz -t "$pkgdir/usr/share/man/man1/swhkd.1.gz" + install -Dm 644 ./docs/swhkd.5.gz -t "$pkgdir/usr/share/man/man5/swhkd.5.gz" + install -Dm 644 ./docs/swhks.1.gz -t "$pkgdir/usr/share/man/man1/swhks.1.gz" + install -Dm 644 ./docs/swhkd-keys.5.gz -t "$pkgdir/usr/share/man/man5/swhkd-keys.5.gz" } pkgver() { diff --git a/swhkd/src/daemon.rs b/swhkd/src/daemon.rs index 21f52c1..1f94659 100644 --- a/swhkd/src/daemon.rs +++ b/swhkd/src/daemon.rs @@ -89,10 +89,6 @@ async fn main() -> Result<(), Box> { Ok(out) => out, }; - // for hotkey in &hotkeys { - // log::debug!("hotkey: {:#?}", hotkey); - // } - modes }; @@ -216,7 +212,7 @@ async fn main() -> Result<(), Box> { let hotkey_repeat_timer = sleep(Duration::from_millis(0)); tokio::pin!(hotkey_repeat_timer); - // The socket that we're sending the commands to. + // The socket we're sending the commands to. let socket_file_path = fetch_xdg_runtime_socket_path(); loop { select! { @@ -363,13 +359,13 @@ async fn main() -> Result<(), Box> { } } -fn socket_write(command: &str, socket_path: PathBuf) -> std::io::Result<()> { +fn socket_write(command: &str, socket_path: PathBuf) -> Result<(), Box> { let mut stream = UnixStream::connect(socket_path)?; stream.write_all(command.as_bytes())?; Ok(()) } -pub fn check_input_group() -> Result<(), Box> { +pub fn check_input_group() -> Result<(), Box> { if !Uid::current().is_root() { let groups = nix::unistd::getgroups(); for (_, groups) in groups.iter().enumerate() { diff --git a/swhkd/src/tests.rs b/swhkd/src/tests.rs index 49a5916..b0785d9 100644 --- a/swhkd/src/tests.rs +++ b/swhkd/src/tests.rs @@ -680,7 +680,7 @@ super + shift + a st shift + suPer + A ts -b +b st B ts