mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-12-20 14:23:53 +08:00
Build man pages into installable fish
This calls sphinx-build from build.rs to include the man pages in the binary. We don't abort if sphinx doesn't exist, but we do if it failed.
This commit is contained in:
parent
2343a6b1f1
commit
1599293796
53
build.rs
53
build.rs
|
@ -36,6 +36,12 @@ fn main() {
|
||||||
|
|
||||||
std::env::set_var("FISH_BUILD_VERSION", version);
|
std::env::set_var("FISH_BUILD_VERSION", version);
|
||||||
|
|
||||||
|
#[cfg(feature = "installable")]
|
||||||
|
{
|
||||||
|
let cman = std::fs::canonicalize(env!("CARGO_MANIFEST_DIR")).unwrap();
|
||||||
|
let targetman = cman.as_path().join("target").join("man");
|
||||||
|
build_man(&targetman);
|
||||||
|
}
|
||||||
rsconf::rebuild_if_path_changed("src/libc.c");
|
rsconf::rebuild_if_path_changed("src/libc.c");
|
||||||
cc::Build::new()
|
cc::Build::new()
|
||||||
.file("src/libc.c")
|
.file("src/libc.c")
|
||||||
|
@ -307,3 +313,50 @@ fn get_version(src_dir: &Path) -> String {
|
||||||
|
|
||||||
panic!("Could not get a version. Either set $FISH_BUILD_VERSION or install git.");
|
panic!("Could not get a version. Either set $FISH_BUILD_VERSION or install git.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "installable")]
|
||||||
|
fn build_man(build_dir: &Path) {
|
||||||
|
use std::process::Command;
|
||||||
|
let mandir = build_dir;
|
||||||
|
let sec1dir = mandir.join("man1");
|
||||||
|
let docsrc_path = std::fs::canonicalize(env!("CARGO_MANIFEST_DIR"))
|
||||||
|
.unwrap()
|
||||||
|
.as_path()
|
||||||
|
.join("doc_src");
|
||||||
|
let docsrc = docsrc_path.to_str().unwrap();
|
||||||
|
let args = &[
|
||||||
|
"-j",
|
||||||
|
"auto",
|
||||||
|
"-q",
|
||||||
|
"-b",
|
||||||
|
"man",
|
||||||
|
"-c",
|
||||||
|
docsrc,
|
||||||
|
// doctree path - put this *above* the man1 dir to exclude it.
|
||||||
|
// this is ~6M
|
||||||
|
"-d",
|
||||||
|
mandir.to_str().unwrap(),
|
||||||
|
docsrc,
|
||||||
|
sec1dir.to_str().unwrap(),
|
||||||
|
];
|
||||||
|
let _ = std::fs::create_dir_all(sec1dir.to_str().unwrap());
|
||||||
|
|
||||||
|
match Command::new("sphinx-build").args(args).output() {
|
||||||
|
Err(x) => {
|
||||||
|
println!("cargo:warning=Could not build man pages: {:?}", x);
|
||||||
|
}
|
||||||
|
Ok(x) => {
|
||||||
|
if !x.status.success() {
|
||||||
|
println!(
|
||||||
|
"cargo:warning=Could not build man pages: {:?}",
|
||||||
|
std::str::from_utf8(&x.stdout).unwrap()
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
"cargo:warning=Could not build man pages: {:?}",
|
||||||
|
std::str::from_utf8(&x.stderr).unwrap()
|
||||||
|
);
|
||||||
|
panic!("Building docs failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -85,6 +85,11 @@ fn install(confirm: bool) {
|
||||||
#[folder = "share/"]
|
#[folder = "share/"]
|
||||||
struct Asset;
|
struct Asset;
|
||||||
|
|
||||||
|
#[derive(RustEmbed)]
|
||||||
|
#[folder = "target/man/man1"]
|
||||||
|
#[prefix = "man/man1/"]
|
||||||
|
struct Docs;
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
@ -132,6 +137,8 @@ fn install(confirm: bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: These are duplicated, no idea how to extract
|
||||||
|
// them into a function
|
||||||
for file in Asset::iter() {
|
for file in Asset::iter() {
|
||||||
let path = dir.join(file.as_ref());
|
let path = dir.join(file.as_ref());
|
||||||
let Ok(_) = fs::create_dir_all(path.parent().unwrap()) else {
|
let Ok(_) = fs::create_dir_all(path.parent().unwrap()) else {
|
||||||
|
@ -153,6 +160,29 @@ fn install(confirm: bool) {
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for file in Docs::iter() {
|
||||||
|
let path = dir.join(file.as_ref());
|
||||||
|
let Ok(_) = fs::create_dir_all(path.parent().unwrap()) else {
|
||||||
|
eprintln!(
|
||||||
|
"Creating directory '{}' failed",
|
||||||
|
path.parent().unwrap().display()
|
||||||
|
);
|
||||||
|
std::process::exit(1);
|
||||||
|
};
|
||||||
|
let res = File::create(&path);
|
||||||
|
let Ok(mut f) = res else {
|
||||||
|
eprintln!("Creating file '{}' failed", path.display());
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
// This should be impossible.
|
||||||
|
let d = Docs::get(&file).expect("File was somehow not included???");
|
||||||
|
if let Err(error) = f.write_all(&d.data) {
|
||||||
|
eprintln!("error: {error}");
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let verfile = dir.join("fish-install-version");
|
let verfile = dir.join("fish-install-version");
|
||||||
let res = File::create(&verfile);
|
let res = File::create(&verfile);
|
||||||
if let Ok(mut f) = res {
|
if let Ok(mut f) = res {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user