diff --git a/doc/Makefile b/doc/Makefile index 3bf710c6a4a48..0929d33105599 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -19,10 +19,11 @@ help: @echo "To run linkcheck, use 'make linkcheck=true'" @echo "To run doctests, use 'make doctest=true'" @echo "To fix outdated doctests, use 'make doctest=fix'" + @echo "To run doctests using Revise, use 'make doctest=true revise=true'" DOCUMENTER_OPTIONS := linkcheck=$(linkcheck) doctest=$(doctest) buildroot=$(call cygpath_w,$(BUILDROOT)) \ - texplatform=$(texplatform) + texplatform=$(texplatform) revise=$(revise) UNICODE_DATA_VERSION=13.0.0 $(SRCCACHE)/UnicodeData-$(UNICODE_DATA_VERSION).txt: diff --git a/doc/make.jl b/doc/make.jl index f00e079529b5c..03431a3a2fa7e 100644 --- a/doc/make.jl +++ b/doc/make.jl @@ -178,18 +178,76 @@ const PAGES = [ ] end +const use_revise = "revise=true" in ARGS +if use_revise + let revise_env = joinpath(@__DIR__, "deps", "revise") + Pkg.activate(revise_env) + Pkg.add("Revise") + Base.ACTIVE_PROJECT[] = nothing + pushfirst!(LOAD_PATH, revise_env) + end +end +function maybe_revise(ex) + use_revise || return ex + STDLIB_DIR = Sys.STDLIB + STDLIBS = filter!(x -> isfile(joinpath(STDLIB_DIR, x, "src", "$(x).jl")), readdir(STDLIB_DIR)) + return quote + $ex + using Revise + const STDLIBS = $STDLIBS + Revise.track(Core.Compiler) + Revise.track(Base) + for (id, mod) in Base.loaded_modules + if id.name in STDLIBS + Revise.track(mod) + end + end + Revise.revise() + end +end + for stdlib in STDLIB_DOCS @eval using $(stdlib.stdlib) # All standard library modules get `using $STDLIB` as their global - DocMeta.setdocmeta!(Base.root_module(Base, stdlib.stdlib), :DocTestSetup, :(using $(stdlib.stdlib)), recursive=true) + DocMeta.setdocmeta!( + Base.root_module(Base, stdlib.stdlib), + :DocTestSetup, + maybe_revise(:(using $(stdlib.stdlib))); + recursive=true, + ) end # A few standard libraries need more than just the module itself in the DocTestSetup. # This overwrites the existing ones from above though, hence the warn=false. -DocMeta.setdocmeta!(SparseArrays, :DocTestSetup, :(using SparseArrays, LinearAlgebra), recursive=true, warn=false) -DocMeta.setdocmeta!(SuiteSparse, :DocTestSetup, :(using SparseArrays, LinearAlgebra, SuiteSparse), recursive=true, warn=false) -DocMeta.setdocmeta!(UUIDs, :DocTestSetup, :(using UUIDs, Random), recursive=true, warn=false) -DocMeta.setdocmeta!(Pkg, :DocTestSetup, :(using Pkg, Pkg.Artifacts), recursive=true, warn=false) -DocMeta.setdocmeta!(Base.BinaryPlatforms, :DocTestSetup, :(using Base.BinaryPlatforms), recursive=true, warn=false) +DocMeta.setdocmeta!( + SparseArrays, + :DocTestSetup, + maybe_revise(:(using SparseArrays, LinearAlgebra)); + recursive=true, warn=false, +) +DocMeta.setdocmeta!( + SuiteSparse, + :DocTestSetup, + maybe_revise(:(using SparseArrays, LinearAlgebra, SuiteSparse)); + recursive=true, warn=false, +) +DocMeta.setdocmeta!( + UUIDs, + :DocTestSetup, + maybe_revise(:(using UUIDs, Random)); + recursive=true, warn=false, +) +DocMeta.setdocmeta!( + Pkg, + :DocTestSetup, + maybe_revise(:(using Pkg, Pkg.Artifacts)); + recursive=true, warn=false, +) +DocMeta.setdocmeta!( + Base.BinaryPlatforms, + :DocTestSetup, + maybe_revise(:(using Base.BinaryPlatforms)); + recursive=true, warn=false, +) let r = r"buildroot=(.+)", i = findfirst(x -> occursin(r, x), ARGS) global const buildroot = i === nothing ? (@__DIR__) : first(match(r, ARGS[i]).captures)