From 33d2a8fbafe54abb3aee9f863b89f90efa02bbb3 Mon Sep 17 00:00:00 2001 From: Justus Adam Date: Wed, 21 Feb 2024 23:10:35 -0500 Subject: [PATCH] Docs via make (#124) ## What Changed? Simplifies the doc setup by performing the necessary steps via cargo-make ## Why Does It Need To? Describe the concern this change addresses. The program in `doc-src` is no longer necessary. ## Checklist - [x] Above description has been filled out so that upon quash merge we have a good record of what changed. - [x] New functions, methods, types are documented. Old documentation is updated if necessary - [x] Documentation in Notion has been updated - [x] Tests for new behaviors are provided - [x] New test suites (if any) ave been added to the CI tests (in `.github/workflows/rust.yml`) either as compiler test or integration test. *Or* justification for their omission from CI has been provided in this PR description. --- .github/workflows/docs.yml | 12 +++++++----- Makefile.toml | 14 +++++++++++++ doc-src/.gitignore | 1 - doc-src/Cargo.lock | 7 ------- doc-src/Cargo.toml | 13 ------------- doc-src/compose.rs | 40 -------------------------------------- 6 files changed, 21 insertions(+), 66 deletions(-) delete mode 100644 doc-src/.gitignore delete mode 100644 doc-src/Cargo.lock delete mode 100644 doc-src/Cargo.toml delete mode 100644 doc-src/compose.rs diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index e6a0bbf8c1..3b2164b7e0 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -21,17 +21,19 @@ jobs: run: | git config --local user.email "docmaster+github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" + - name: Install cargo-make + uses: actions-rs/cargo@v1 + with: + command: install + args: --debug cargo-make - name: Prepare run: | cargo doc --document-private-items mkdir docs cp -R target/doc docs/libs rm -R .github - - name: Copy Rustc Docs - run: cargo run - working-directory: doc-src - - name: Copy index page - run: cp doc-src/index.html docs/index.html + - name: Copy rustc docs and index page + run: cargo make populate-doc-dir - name: Commit Doc Generation run: | git add docs diff --git a/Makefile.toml b/Makefile.toml index 8c4225d369..301d886aad 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -203,3 +203,17 @@ end cd crates/paralegal-policy/tests/test-crate exec cargo %{FORMAT_ARGS} ''' + +[tasks.populate-doc-dir] +dependencies = ["get-rustc-docs"] +script_runner = "@duckscript" +script = ''' +source_path = concat ${RUSTUP_HOME} /toolchains/ ${RUSTUP_TOOLCHAIN} /share/doc/rust/html/rustc +mkdir docs +mv doc-src/index.html docs +mv ${source_path} docs/compiler +''' + +[tasks.get-rustc-docs] +command = "rustup" +args = ["component", "add", "rustc-docs"] diff --git a/doc-src/.gitignore b/doc-src/.gitignore deleted file mode 100644 index ea8c4bf7f3..0000000000 --- a/doc-src/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/target diff --git a/doc-src/Cargo.lock b/doc-src/Cargo.lock deleted file mode 100644 index 7a9d7e7a2b..0000000000 --- a/doc-src/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "compose" -version = "0.0.1" diff --git a/doc-src/Cargo.toml b/doc-src/Cargo.toml deleted file mode 100644 index 0aeac8b860..0000000000 --- a/doc-src/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "compose" -version = "0.0.1" -publish = false -description = "Get, find and move the rustc docs to our documentation directory" - - -[[bin]] -name = "compose" -path = "compose.rs" - -# Needed to separate this script from the worspace above -[workspace] \ No newline at end of file diff --git a/doc-src/compose.rs b/doc-src/compose.rs deleted file mode 100644 index eaf4d207b2..0000000000 --- a/doc-src/compose.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! The purpose of this application is to -//! -//! 1. make rustup download the rustc docs -//! 2. figure out where those docs were stored and move them into the -//! docs/compiler directory -//! -//! The reason this is a rust application is because then we can run it easily -//! with `cargo run` and it'll have access to the rustup toolchain and directory -//! information via environment variables. I (Justus) haven't yet been able to -//! query that information easily otherwise. - - -use std::path::{Path, PathBuf}; -use std::process::Command; - -fn main() { - assert!(Command::new("rustup") - .args(["component", "add", "rustc-docs"]) - .status() - .unwrap() - .success()); - let rustup_folder = std::env::var("RUSTUP_HOME").unwrap(); - let toolchain = std::env::var("RUSTUP_TOOLCHAIN").unwrap(); - - let mut src = PathBuf::new(); - for part in [ - rustup_folder.as_str(), - "toolchains", - toolchain.as_str(), - "share", - "doc", - "rust", - "html", - "rustc", - ] { - src.push(part); - } - let target = Path::new("../docs/compiler"); - std::fs::rename(src, target).unwrap() -}