Skip to content

Commit c242124

Browse files
committed
[BuildSystem] Scdoc generation with build.rs
Signed-off-by: Shinyzenith <aakashsensharma@gmail.com>
1 parent 6bac416 commit c242124

File tree

7 files changed

+52
-31
lines changed

7 files changed

+52
-31
lines changed

INSTALL.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
We have packaged `swhkd-git`. `swhkd-bin` has been packaged separately by a user of swhkd.
44

5-
# Install
5+
# Building:
66

77
`swhkd` and `swhks` install to `/usr/local/bin/` by default. You can change this behaviour by editing the [Makefile](../Makefile) variable, `TARGET_DIR`.
88

@@ -17,7 +17,7 @@ We have packaged `swhkd-git`. `swhkd-bin` has been packaged separately by a user
1717
**Compile time:**
1818

1919
- git
20-
- scdoc
20+
- scdoc (If present, man-pages will be generated)
2121
- make
2222
- rustup
2323

Makefile

+5-12
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,13 @@ build:
1515
@cargo build $(BUILDFLAGS)
1616

1717
install:
18-
@scdoc < ./docs/$(DAEMON_BINARY).1.scd > ./docs/$(DAEMON_BINARY).1.gz
19-
@scdoc < ./docs/$(SERVER_BINARY).1.scd > ./docs/$(SERVER_BINARY).1.gz
20-
@scdoc < ./docs/$(DAEMON_BINARY).5.scd > ./docs/$(DAEMON_BINARY).5.gz
21-
@scdoc < ./docs/$(DAEMON_BINARY)-keys.5.scd > ./docs/$(DAEMON_BINARY)-keys.5.gz
2218
@mkdir -p $(MAN1_DIR)
2319
@mkdir -p $(MAN5_DIR)
2420
@mkdir -p $(POLKIT_DIR)
2521
@mkdir -p $(TARGET_DIR)
2622
@mkdir -p /etc/$(DAEMON_BINARY)
27-
@mv ./docs/$(DAEMON_BINARY).1.gz $(MAN1_DIR)
28-
@mv ./docs/$(SERVER_BINARY).1.gz $(MAN1_DIR)
29-
@mv ./docs/$(DAEMON_BINARY).5.gz $(MAN5_DIR)
30-
@mv ./docs/$(DAEMON_BINARY)-keys.5.gz $(MAN5_DIR)
23+
@find ./docs -type f -iname "*.1.gz" -exec cp {} $(MAN1_DIR) \;
24+
@find ./docs -type f -iname "*.7.gz" -exec cp {} $(MAN7_DIR) \;
3125
@touch /etc/$(DAEMON_BINARY)/$(DAEMON_BINARY)rc
3226
@cp ./target/release/$(DAEMON_BINARY) $(TARGET_DIR)
3327
@cp ./target/release/$(SERVER_BINARY) $(TARGET_DIR)
@@ -36,10 +30,8 @@ install:
3630
@chmod +x $(TARGET_DIR)/$(SERVER_BINARY)
3731

3832
uninstall:
39-
@rm -f $(MAN1_DIR)/$(DAEMON_BINARY).1.gz
40-
@rm -f $(MAN1_DIR)/$(SERVER_BINARY).1.gz
41-
@rm -f $(MAN5_DIR)/$(DAEMON_BINARY).5.gz
42-
@rm -f $(MAN5_DIR)/$(DAEMON_BINARY)-keys.5.gz
33+
@rm -f /usr/share/man/**/swhkd.*
34+
@rm -f /usr/share/man/**/swhks.*
4335
@rm $(TARGET_DIR)/$(SERVER_BINARY)
4436
@rm $(TARGET_DIR)/$(DAEMON_BINARY)
4537
@rm $(POLKIT_DIR)/$(POLKIT_POLICY_FILE)
@@ -59,6 +51,7 @@ test:
5951

6052
clean:
6153
@cargo clean
54+
@rm ./docs/*.gz
6255

6356
setup:
6457
@rustup install stable

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ It also attempts to be a drop-in replacement for sxhkd, meaning your sxhkd confi
2222

2323
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.
2424

25-
## Installation:
25+
## Installation and Building:
2626

27-
[Installation instructions can be found here.](./INSTALL.md)
27+
[Installation and building instructions can be found here.](./INSTALL.md)
2828

2929
## Running:
3030

build.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use std::{fs::read_dir, io::ErrorKind, process::exit, process::Command};
2+
3+
fn main() {
4+
// Check if scdoc command exists
5+
match Command::new("scdoc").spawn() {
6+
Err(e) => {
7+
if let ErrorKind::NotFound = e.kind() {
8+
exit(0);
9+
}
10+
}
11+
_ => {}
12+
}
13+
14+
let mut man_pages: Vec<(String, String)> = Vec::new();
15+
for path in read_dir("./docs").unwrap() {
16+
let path = path.unwrap();
17+
if path.file_type().unwrap().is_dir() {
18+
continue;
19+
}
20+
21+
if let Some(file_name) = path.path().to_str() {
22+
let man_page_name = file_name.replace(".scd", ".gz");
23+
man_pages.push((file_name.to_string(), man_page_name));
24+
}
25+
}
26+
27+
for man_page in man_pages {
28+
_ = Command::new("sh")
29+
.arg("-c")
30+
.arg(format!("scdoc <{}>{}", man_page.0, man_page.1))
31+
.spawn();
32+
}
33+
}

contrib/PKGBUILD

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
_pkgname="swhkd"
66
pkgname="${_pkgname}-git"
77
pkgver=.543.gf6ea9d6
8-
pkgrel=1
8+
pkgrel=2
99
arch=("x86_64")
1010
url="https://github.com/waycrate/swhkd"
1111
pkgdesc="A display server independent hotkey daemon inspired by sxhkd."
@@ -18,10 +18,6 @@ sha256sums=("SKIP")
1818

1919
build(){
2020
cd "$_pkgname"
21-
scdoc < ./docs/swhkd.1.scd > ./docs/swhkd.1.gz
22-
scdoc < ./docs/swhks.1.scd > ./docs/swhks.1.gz
23-
scdoc < ./docs/swhkd.5.scd > ./docs/swhkd.5.gz
24-
scdoc < ./docs/swhkd-keys.5.scd > ./docs/swhkd-keys.5.gz
2521
make setup
2622
make
2723
}
@@ -32,8 +28,11 @@ package() {
3228
install -Dm 755 ./target/release/swhks "$pkgdir/usr/bin/swhks"
3329

3430
install -Dm 644 -o root ./com.github.swhkd.pkexec.policy -t "$pkgdir/usr/share/polkit-1/actions"
35-
install -Dm 644 ./docs/*.1.gz -t "$pkgdir/usr/share/man/man1/"
36-
install -Dm 644 ./docs/*.5.gz -t "$pkgdir/usr/share/man/man5/"
31+
32+
install -Dm 644 ./docs/swhkd.1.gz -t "$pkgdir/usr/share/man/man1/swhkd.1.gz"
33+
install -Dm 644 ./docs/swhkd.5.gz -t "$pkgdir/usr/share/man/man5/swhkd.5.gz"
34+
install -Dm 644 ./docs/swhks.1.gz -t "$pkgdir/usr/share/man/man1/swhks.1.gz"
35+
install -Dm 644 ./docs/swhkd-keys.5.gz -t "$pkgdir/usr/share/man/man5/swhkd-keys.5.gz"
3736
}
3837

3938
pkgver() {

swhkd/src/daemon.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
8989
Ok(out) => out,
9090
};
9191

92-
// for hotkey in &hotkeys {
93-
// log::debug!("hotkey: {:#?}", hotkey);
94-
// }
95-
9692
modes
9793
};
9894

@@ -216,7 +212,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
216212
let hotkey_repeat_timer = sleep(Duration::from_millis(0));
217213
tokio::pin!(hotkey_repeat_timer);
218214

219-
// The socket that we're sending the commands to.
215+
// The socket we're sending the commands to.
220216
let socket_file_path = fetch_xdg_runtime_socket_path();
221217
loop {
222218
select! {
@@ -363,13 +359,13 @@ async fn main() -> Result<(), Box<dyn Error>> {
363359
}
364360
}
365361

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

372-
pub fn check_input_group() -> Result<(), Box<dyn std::error::Error>> {
368+
pub fn check_input_group() -> Result<(), Box<dyn Error>> {
373369
if !Uid::current().is_root() {
374370
let groups = nix::unistd::getgroups();
375371
for (_, groups) in groups.iter().enumerate() {

swhkd/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ super + shift + a
680680
st
681681
shift + suPer + A
682682
ts
683-
b
683+
b
684684
st
685685
B
686686
ts

0 commit comments

Comments
 (0)