2021-11-27 15:19:45 +00:00
|
|
|
import Lake
|
2022-07-24 00:07:30 +00:00
|
|
|
open System Lake DSL
|
2021-11-27 15:19:45 +00:00
|
|
|
|
2022-06-19 14:41:59 +00:00
|
|
|
package «doc-gen4»
|
|
|
|
|
|
|
|
lean_lib DocGen4
|
|
|
|
|
2022-10-20 17:51:26 +00:00
|
|
|
@[default_target]
|
2022-06-19 14:41:59 +00:00
|
|
|
lean_exe «doc-gen4» {
|
|
|
|
root := `Main
|
2021-11-27 15:19:45 +00:00
|
|
|
supportInterpreter := true
|
|
|
|
}
|
2022-06-19 14:41:59 +00:00
|
|
|
|
|
|
|
require CMark from git
|
2022-07-20 14:18:57 +00:00
|
|
|
"https://github.com/xubaiw/CMark.lean" @ "main"
|
2022-06-19 14:41:59 +00:00
|
|
|
|
2023-08-06 14:07:24 +00:00
|
|
|
require «lean4-unicode-basic» from git
|
2023-03-14 11:32:32 +00:00
|
|
|
"https://github.com/fgdorais/lean4-unicode-basic" @ "main"
|
2022-06-19 14:41:59 +00:00
|
|
|
|
|
|
|
require Cli from git
|
2022-07-20 14:18:57 +00:00
|
|
|
"https://github.com/mhuisi/lean4-cli" @ "nightly"
|
2022-06-19 14:41:59 +00:00
|
|
|
|
|
|
|
require leanInk from git
|
2022-06-19 22:31:09 +00:00
|
|
|
"https://github.com/hargonix/LeanInk" @ "doc-gen"
|
2022-08-11 19:37:10 +00:00
|
|
|
|
2023-10-09 07:30:16 +00:00
|
|
|
|
|
|
|
/--
|
|
|
|
Turns a Github git remote URL into an HTTPS Github URL.
|
|
|
|
Three link types from git supported:
|
|
|
|
- https://github.com/org/repo
|
|
|
|
- https://github.com/org/repo.git
|
|
|
|
- git@github.com:org/repo.git
|
|
|
|
|
|
|
|
TODO: This function is quite brittle and very Github specific, we can
|
|
|
|
probably do better.
|
|
|
|
-/
|
|
|
|
def getGithubBaseUrl (gitUrl : String) : String := Id.run do
|
|
|
|
let mut url := gitUrl
|
|
|
|
if url.startsWith "git@" then
|
|
|
|
url := url.drop 15
|
|
|
|
url := url.dropRight 4
|
|
|
|
return s!"https://github.com/{url}"
|
|
|
|
else if url.endsWith ".git" then
|
|
|
|
return url.dropRight 4
|
|
|
|
else
|
|
|
|
return url
|
|
|
|
|
|
|
|
/--
|
|
|
|
Obtain the Github URL of a project by parsing the origin remote.
|
|
|
|
-/
|
|
|
|
def getProjectGithubUrl (directory : System.FilePath := "." ) : IO String := do
|
|
|
|
let out ← IO.Process.output {
|
|
|
|
cmd := "git",
|
|
|
|
args := #["remote", "get-url", "origin"],
|
|
|
|
cwd := directory
|
|
|
|
}
|
|
|
|
if out.exitCode != 0 then
|
|
|
|
throw <| IO.userError <| s!"git exited with code {out.exitCode} while looking for the git remote in {directory}"
|
|
|
|
return out.stdout.trimRight
|
|
|
|
|
|
|
|
/--
|
|
|
|
Obtain the git commit hash of the project that is currently getting analyzed.
|
|
|
|
-/
|
|
|
|
def getProjectCommit (directory : System.FilePath := "." ) : IO String := do
|
|
|
|
let out ← IO.Process.output {
|
|
|
|
cmd := "git",
|
|
|
|
args := #["rev-parse", "HEAD"]
|
|
|
|
cwd := directory
|
|
|
|
}
|
|
|
|
if out.exitCode != 0 then
|
|
|
|
throw <| IO.userError <| s!"git exited with code {out.exitCode} while looking for the current commit in {directory}"
|
|
|
|
return out.stdout.trimRight
|
|
|
|
|
|
|
|
def getGitUrl (pkg : Package) (lib : LeanLibConfig) (mod : Module) : IO String := do
|
|
|
|
let baseUrl := getGithubBaseUrl (← getProjectGithubUrl pkg.dir)
|
|
|
|
let commit ← getProjectCommit pkg.dir
|
|
|
|
|
|
|
|
let parts := mod.name.components.map toString
|
|
|
|
let path := String.intercalate "/" parts
|
|
|
|
let libPath := pkg.config.srcDir / lib.srcDir
|
|
|
|
let basePath := String.intercalate "/" (libPath.components.filter (· != "."))
|
|
|
|
let url := s!"{baseUrl}/blob/{commit}/{basePath}/{path}.lean"
|
|
|
|
return url
|
|
|
|
|
2022-08-11 19:37:10 +00:00
|
|
|
module_facet docs (mod) : FilePath := do
|
|
|
|
let some docGen4 ← findLeanExe? `«doc-gen4»
|
|
|
|
| error "no doc-gen4 executable configuration found in workspace"
|
|
|
|
let exeJob ← docGen4.exe.fetch
|
2023-09-18 20:03:27 +00:00
|
|
|
let modJob ← mod.leanArts.fetch
|
2023-10-09 07:30:16 +00:00
|
|
|
let ws ← getWorkspace
|
|
|
|
let pkg ← ws.packages.find? (·.isLocalModule mod.name)
|
|
|
|
let libConfig ← pkg.leanLibConfigs.toArray.find? (·.isLocalModule mod.name)
|
2023-10-07 19:07:55 +00:00
|
|
|
-- Build all documentation imported modules
|
|
|
|
let imports ← mod.imports.fetch
|
2023-10-08 09:30:11 +00:00
|
|
|
let depDocJobs ← BuildJob.mixArray <| ← imports.mapM fun mod => fetch <| mod.facet `docs
|
2023-10-09 07:30:16 +00:00
|
|
|
let gitUrl ← getGitUrl pkg libConfig mod
|
|
|
|
let buildDir := ws.root.buildDir
|
2022-08-11 19:37:10 +00:00
|
|
|
let docFile := mod.filePath (buildDir / "doc") "html"
|
2023-10-08 09:30:11 +00:00
|
|
|
depDocJobs.bindAsync fun _ depDocTrace => do
|
2022-08-11 19:37:10 +00:00
|
|
|
exeJob.bindAsync fun exeFile exeTrace => do
|
|
|
|
modJob.bindSync fun _ modTrace => do
|
2023-10-08 09:30:11 +00:00
|
|
|
let depTrace := mixTraceArray #[exeTrace, modTrace, depDocTrace]
|
2022-08-11 19:37:10 +00:00
|
|
|
let trace ← buildFileUnlessUpToDate docFile depTrace do
|
2023-09-10 09:47:36 +00:00
|
|
|
logStep s!"Documenting module: {mod.name}"
|
2022-08-11 19:37:10 +00:00
|
|
|
proc {
|
|
|
|
cmd := exeFile.toString
|
2023-10-09 07:30:16 +00:00
|
|
|
args := #["single", mod.name.toString, gitUrl]
|
|
|
|
env := ← getAugmentedEnv
|
2022-08-11 19:37:10 +00:00
|
|
|
}
|
|
|
|
return (docFile, trace)
|
|
|
|
|
|
|
|
-- TODO: technically speaking this facet does not show all file dependencies
|
|
|
|
target coreDocs : FilePath := do
|
|
|
|
let some docGen4 ← findLeanExe? `«doc-gen4»
|
|
|
|
| error "no doc-gen4 executable configuration found in workspace"
|
|
|
|
let exeJob ← docGen4.exe.fetch
|
|
|
|
let basePath := (←getWorkspace).root.buildDir / "doc"
|
|
|
|
let dataFile := basePath / "declarations" / "declaration-data-Lean.bmp"
|
|
|
|
exeJob.bindSync fun exeFile exeTrace => do
|
|
|
|
let trace ← buildFileUnlessUpToDate dataFile exeTrace do
|
2023-09-10 09:47:36 +00:00
|
|
|
logStep "Documenting Lean core: Init and Lean"
|
2022-08-11 19:37:10 +00:00
|
|
|
proc {
|
|
|
|
cmd := exeFile.toString
|
|
|
|
args := #["genCore"]
|
2023-10-09 07:30:16 +00:00
|
|
|
env := ← getAugmentedEnv
|
2022-08-11 19:37:10 +00:00
|
|
|
}
|
|
|
|
return (dataFile, trace)
|
|
|
|
|
|
|
|
library_facet docs (lib) : FilePath := do
|
2022-12-03 16:43:12 +00:00
|
|
|
let mods ← lib.modules.fetch
|
|
|
|
let moduleJobs ← BuildJob.mixArray <| ← mods.mapM (fetch <| ·.facet `docs)
|
2023-07-30 18:40:24 +00:00
|
|
|
let coreJob : BuildJob FilePath ← coreDocs.fetch
|
|
|
|
let exeJob ← «doc-gen4».fetch
|
2022-08-11 19:37:10 +00:00
|
|
|
-- Shared with DocGen4.Output
|
|
|
|
let basePath := (←getWorkspace).root.buildDir / "doc"
|
|
|
|
let dataFile := basePath / "declarations" / "declaration-data.bmp"
|
|
|
|
let staticFiles := #[
|
|
|
|
basePath / "style.css",
|
|
|
|
basePath / "declaration-data.js",
|
2023-06-08 05:52:51 +00:00
|
|
|
basePath / "color-scheme.js",
|
2022-08-11 19:37:10 +00:00
|
|
|
basePath / "nav.js",
|
2023-09-21 09:27:33 +00:00
|
|
|
basePath / "jump-src.js",
|
2023-09-18 21:03:40 +00:00
|
|
|
basePath / "expand-nav.js",
|
2022-08-11 19:37:10 +00:00
|
|
|
basePath / "how-about.js",
|
|
|
|
basePath / "search.js",
|
|
|
|
basePath / "mathjax-config.js",
|
|
|
|
basePath / "instances.js",
|
|
|
|
basePath / "importedBy.js",
|
|
|
|
basePath / "index.html",
|
|
|
|
basePath / "404.html",
|
|
|
|
basePath / "navbar.html",
|
2023-01-25 22:57:10 +00:00
|
|
|
basePath / "search.html",
|
2022-08-11 19:37:10 +00:00
|
|
|
basePath / "find" / "index.html",
|
|
|
|
basePath / "find" / "find.js",
|
|
|
|
basePath / "src" / "alectryon.css",
|
|
|
|
basePath / "src" / "alectryon.js",
|
|
|
|
basePath / "src" / "docutils_basic.css",
|
|
|
|
basePath / "src" / "pygments.css"
|
|
|
|
]
|
|
|
|
coreJob.bindAsync fun _ coreInputTrace => do
|
|
|
|
exeJob.bindAsync fun exeFile exeTrace => do
|
|
|
|
moduleJobs.bindSync fun _ inputTrace => do
|
|
|
|
let depTrace := mixTraceArray #[inputTrace, exeTrace, coreInputTrace]
|
|
|
|
let trace ← buildFileUnlessUpToDate dataFile depTrace do
|
|
|
|
logInfo "Documentation indexing"
|
|
|
|
proc {
|
|
|
|
cmd := exeFile.toString
|
|
|
|
args := #["index"]
|
|
|
|
}
|
|
|
|
let traces ← staticFiles.mapM computeTrace
|
|
|
|
let indexTrace := mixTraceArray traces
|
|
|
|
|
2022-08-12 21:04:36 +00:00
|
|
|
return (dataFile, trace.mix indexTrace)
|