Skip to content

Commit

Permalink
[BuildSystem] Scdoc generation with build.rs
Browse files Browse the repository at this point in the history
Signed-off-by: Shinyzenith <[email protected]>
  • Loading branch information
Shinyzenith committed Jul 29, 2022
1 parent 6bac416 commit c242124
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 31 deletions.
4 changes: 2 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand All @@ -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

Expand Down
17 changes: 5 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -59,6 +51,7 @@ test:

clean:
@cargo clean
@rm ./docs/*.gz

setup:
@rustup install stable
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
33 changes: 33 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -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();
}
}
13 changes: 6 additions & 7 deletions contrib/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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
}
Expand All @@ -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() {
Expand Down
10 changes: 3 additions & 7 deletions swhkd/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
Ok(out) => out,
};

// for hotkey in &hotkeys {
// log::debug!("hotkey: {:#?}", hotkey);
// }

modes
};

Expand Down Expand Up @@ -216,7 +212,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
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! {
Expand Down Expand Up @@ -363,13 +359,13 @@ async fn main() -> Result<(), Box<dyn Error>> {
}
}

fn socket_write(command: &str, socket_path: PathBuf) -> std::io::Result<()> {
fn socket_write(command: &str, socket_path: PathBuf) -> Result<(), Box<dyn Error>> {
let mut stream = UnixStream::connect(socket_path)?;
stream.write_all(command.as_bytes())?;
Ok(())
}

pub fn check_input_group() -> Result<(), Box<dyn std::error::Error>> {
pub fn check_input_group() -> Result<(), Box<dyn Error>> {
if !Uid::current().is_root() {
let groups = nix::unistd::getgroups();
for (_, groups) in groups.iter().enumerate() {
Expand Down
2 changes: 1 addition & 1 deletion swhkd/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ super + shift + a
st
shift + suPer + A
ts
b
b
st
B
ts
Expand Down

0 comments on commit c242124

Please sign in to comment.