mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-02 06:41:14 +00:00
Make C++ documentation generation an xtask
Tear it out of the CMakeLists.txt and instead run it via cargo xtask cppdocs This allows the build_and_test step in the CI to only run cmake for the library/header related bits and the docs_and_demos step to only generate docs and not require a full host build of the library (as cargo xtask cmake would otherwise do).
This commit is contained in:
parent
704644c752
commit
65ff715fbc
6 changed files with 152 additions and 46 deletions
107
xtask/src/cppdocs.rs
Normal file
107
xtask/src/cppdocs.rs
Normal file
|
@ -0,0 +1,107 @@
|
|||
/* LICENSE BEGIN
|
||||
This file is part of the SixtyFPS Project -- https://sixtyfps.io
|
||||
Copyright (c) 2020 Olivier Goffart <olivier.goffart@sixtyfps.io>
|
||||
Copyright (c) 2020 Simon Hausmann <simon.hausmann@sixtyfps.io>
|
||||
|
||||
SPDX-License-Identifier: GPL-3.0-only
|
||||
This file is also available under commercial licensing terms.
|
||||
Please contact info@sixtyfps.io for more information.
|
||||
LICENSE END */
|
||||
use anyhow::{Context, Result};
|
||||
use std::ffi::OsString;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> Result<()> {
|
||||
if dst.as_ref().exists() {
|
||||
std::fs::remove_file(dst.as_ref()).context("Error removing old symlink")?;
|
||||
}
|
||||
#[cfg(target_os = "windows")]
|
||||
return std::os::windows::fs::symlink_file(&src, &dst).context("Error creating symlink");
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
return std::os::unix::fs::symlink(&src, &dst).context(format!(
|
||||
"Error creating symlink from {} to {}",
|
||||
src.as_ref().display(),
|
||||
dst.as_ref().display()
|
||||
));
|
||||
}
|
||||
|
||||
fn symlink_dir<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> Result<()> {
|
||||
if dst.as_ref().exists() {
|
||||
std::fs::remove_file(dst.as_ref()).context("Error removing old symlink")?;
|
||||
}
|
||||
#[cfg(target_os = "windows")]
|
||||
return std::os::windows::fs::symlink_dir(&src, &dst).context("Error creating symlink");
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
return std::os::unix::fs::symlink(&src, &dst).context(format!(
|
||||
"Error creating symlink from {} to {}",
|
||||
src.as_ref().display(),
|
||||
dst.as_ref().display()
|
||||
));
|
||||
}
|
||||
|
||||
fn symlink_files_in_dir<S: AsRef<Path>, T: AsRef<Path>, TS: AsRef<Path>>(
|
||||
src: S,
|
||||
target: T,
|
||||
target_to_source: TS,
|
||||
) -> Result<()> {
|
||||
for entry in std::fs::read_dir(src.as_ref()).context("Error reading docs source directory")? {
|
||||
let entry = entry.context("Error reading directory entry")?;
|
||||
let path = entry.path();
|
||||
if path.is_file() {
|
||||
let file_name = path.file_name().unwrap();
|
||||
let symlink_source = target_to_source.as_ref().to_path_buf().join(&file_name);
|
||||
let symlink_target = target.as_ref().to_path_buf().join(path.file_name().unwrap());
|
||||
symlink_file(symlink_source, symlink_target)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn generate() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let root = super::root_dir()?;
|
||||
|
||||
let docs_source_dir = root.join("api/sixtyfps-cpp");
|
||||
let docs_build_dir = root.join("target/cppdocs");
|
||||
|
||||
std::fs::create_dir_all(docs_build_dir.as_path()).context("Error creating docs build dir")?;
|
||||
|
||||
symlink_files_in_dir(
|
||||
docs_source_dir.join("docs"),
|
||||
&docs_build_dir,
|
||||
["..", "..", "api", "sixtyfps-cpp", "docs"].iter().collect::<PathBuf>(),
|
||||
)
|
||||
.context("Error symlinking files from docs source to docs build dir")?;
|
||||
|
||||
symlink_dir(["..", "..", "docs"].iter().collect::<PathBuf>(), docs_build_dir.join("markdown"))?;
|
||||
|
||||
symlink_file(
|
||||
["..", "..", "api", "sixtyfps-cpp", "README.md"].iter().collect::<PathBuf>(),
|
||||
docs_build_dir.join("README.md"),
|
||||
)?;
|
||||
|
||||
let pip_env =
|
||||
vec![(OsString::from("PIPENV_PIPFILE"), docs_source_dir.join("docs/Pipfile").to_owned())];
|
||||
|
||||
println!("Running pipenv install");
|
||||
|
||||
super::run_command("pipenv", &["install"], pip_env.clone())
|
||||
.context("Error running pipenv install")?;
|
||||
|
||||
println!("Running sphinx-build");
|
||||
|
||||
let output = super::run_command(
|
||||
"pipenv",
|
||||
&[
|
||||
"run",
|
||||
"sphinx-build",
|
||||
docs_build_dir.to_str().unwrap(),
|
||||
docs_build_dir.join("html").to_str().unwrap(),
|
||||
],
|
||||
pip_env.clone(),
|
||||
)
|
||||
.context("Error running pipenv install")?;
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&output));
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue