xtask: Add doc task

Mirror the task in CI
This commit is contained in:
Kévin Commaille 2022-03-18 11:27:07 +01:00 committed by Kévin Commaille
parent 9a401cefae
commit 1f23e8abcb
2 changed files with 46 additions and 0 deletions

41
xtask/src/doc.rs Normal file
View File

@ -0,0 +1,41 @@
use clap::Args;
use crate::{cmd, Result};
#[derive(Args)]
pub struct DocTask {
/// Open the browser when the docs are built.
#[clap(long)]
pub open: bool,
/// Fail on warnings.
#[clap(long)]
pub deny_warnings: bool,
}
impl DocTask {
pub(crate) fn run(self) -> Result<()> {
let mut rustdocflags = "--enable-index-page -Zunstable-options --cfg docsrs".to_owned();
if self.deny_warnings {
rustdocflags += " -Dwarnings";
}
// Keep in sync with .github/workflows/docs.yml
let mut cmd = cmd!(
"
rustup run nightly cargo doc --no-deps --workspace
--exclude ruma-macros --exclude ruma-identifiers-validation --exclude xtask
--all-features -Zrustdoc-map
"
)
.env("RUSTDOCFLAGS", rustdocflags);
if self.open {
cmd = cmd.arg("--open");
}
cmd.run()?;
Ok(())
}
}

View File

@ -14,12 +14,14 @@ use serde_json::from_str as from_json_str;
#[cfg(feature = "default")] #[cfg(feature = "default")]
mod cargo; mod cargo;
mod ci; mod ci;
mod doc;
#[cfg(feature = "default")] #[cfg(feature = "default")]
mod release; mod release;
#[cfg(feature = "default")] #[cfg(feature = "default")]
mod util; mod util;
use ci::{CiArgs, CiTask}; use ci::{CiArgs, CiTask};
use doc::DocTask;
#[cfg(feature = "default")] #[cfg(feature = "default")]
use release::{ReleaseArgs, ReleaseTask}; use release::{ReleaseArgs, ReleaseTask};
@ -35,6 +37,8 @@ struct Xtask {
enum Command { enum Command {
/// Run continuous integration checks /// Run continuous integration checks
Ci(CiArgs), Ci(CiArgs),
/// Build the docs
Doc(DocTask),
/// Publish a new version of a crate on crates.io, `publish` can be used as an alias /// Publish a new version of a crate on crates.io, `publish` can be used as an alias
#[cfg(feature = "default")] #[cfg(feature = "default")]
#[clap(alias = "publish")] #[clap(alias = "publish")]
@ -47,6 +51,7 @@ fn main() -> Result<()> {
let ci = CiTask::new(args.cmd)?; let ci = CiTask::new(args.cmd)?;
ci.run() ci.run()
} }
Command::Doc(doc) => doc.run(),
#[cfg(feature = "default")] #[cfg(feature = "default")]
Command::Release(args) => { Command::Release(args) => {
let mut task = ReleaseTask::new(args.package, args.version)?; let mut task = ReleaseTask::new(args.package, args.version)?;