Skip to content

Commit

Permalink
[build.rs] Fix scdoc parent stdio inheritance
Browse files Browse the repository at this point in the history
Signed-off-by: Shinyzenith <[email protected]>
  • Loading branch information
Shinyzenith committed Sep 6, 2022
1 parent 3dd7d40 commit 51bef36
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ use std::{
fs::{read_dir, File, OpenOptions},
io::ErrorKind,
path::Path,
process::exit,
process::{Command, Stdio},
process::{exit, Command, Stdio},
};

fn main() {
// Check if scdoc command exists
match Command::new("scdoc").spawn() {
Err(e) => {
if let ErrorKind::NotFound = e.kind() {
exit(0);
}
if let Err(e) = Command::new("scdoc")
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
{
if let ErrorKind::NotFound = e.kind() {
exit(0);
}
_ => {}
}

let mut man_pages: Vec<(String, String)> = Vec::new();
Expand All @@ -25,17 +25,18 @@ fn main() {
}

if let Some(file_name) = path.path().to_str() {
if path.path().extension().unwrap().to_str().unwrap() == "gz" {
continue;
}

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 {
let output = OpenOptions::new()
.write(true)
.create(true)
.open(Path::new(&man_page.1))
.unwrap();
let output =
OpenOptions::new().write(true).create(true).open(Path::new(&man_page.1)).unwrap();
_ = Command::new("scdoc")
.stdin(Stdio::from(File::open(man_page.0).unwrap()))
.stdout(output)
Expand Down

0 comments on commit 51bef36

Please sign in to comment.