Skip to content

Commit 0a970d8

Browse files
authored
Fix out-of-tree docs build (#58529)
The `doc` build had only limited out-of-tree support. In particular, it was relying on creating in-tree `stdlib` symbolic links (due to a missing feature in Documenter), as well as pointing external stdlibs to the in-tree references rather than the out-of-tree ones. Fix this by building up the reading of the buildroot and splitting `@__DIR__` references appropriately, depending on whether they refer to the source or the output. Fixes #53039.
1 parent 925d504 commit 0a970d8

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

doc/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ $(SRCCACHE)/UnicodeData-$(UNICODE_DATA_VERSION).txt:
3030
@mkdir -p "$(SRCCACHE)"
3131
$(JLDOWNLOAD) "$@" https://www.unicode.org/Public/$(UNICODE_DATA_VERSION)/ucd/UnicodeData.txt
3232

33+
# NEWS.md and stdlib are in-tree build artifacts - don't link them for oot builds.
34+
DOC_FILES=$(filter-out NEWS.md stdlib,$(notdir $(wildcard $(SRCDIR)/src/*)))
35+
src/%:
36+
@mkdir -p src
37+
ln -s $(SRCDIR)/src/$* $@
38+
src: $(addprefix src/,$(DOC_FILES))
39+
3340
deps: $(SRCCACHE)/UnicodeData-$(UNICODE_DATA_VERSION).txt
3441
$(JLCHECKSUM) "$<"
3542
cp "$<" UnicodeData.txt

doc/make.jl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
let r = r"buildroot=(.+)", i = findfirst(x -> occursin(r, x), ARGS)
2+
global const buildrootdoc = i === nothing ? (@__DIR__) : joinpath(first(match(r, ARGS[i]).captures), "doc")
3+
end
4+
15
# Install dependencies needed to build the documentation.
26
Base.ACTIVE_PROJECT[] = nothing
37
empty!(LOAD_PATH)
48
push!(LOAD_PATH, @__DIR__, "@stdlib")
59
empty!(DEPOT_PATH)
6-
push!(DEPOT_PATH, joinpath(@__DIR__, "deps"))
10+
push!(DEPOT_PATH, joinpath(buildrootdoc, "deps"))
711
push!(DEPOT_PATH, abspath(Sys.BINDIR, "..", "share", "julia"))
812
using Pkg
913
Pkg.instantiate()
@@ -26,7 +30,7 @@ cp_q(src, dest) = isfile(dest) || cp(src, dest)
2630
const STDLIB_DOCS = []
2731
const STDLIB_DIR = Sys.STDLIB
2832
const EXT_STDLIB_DOCS = ["Pkg"]
29-
cd(joinpath(@__DIR__, "src")) do
33+
cd(joinpath(buildrootdoc, "src")) do
3034
Base.rm("stdlib"; recursive=true, force=true)
3135
mkdir("stdlib")
3236
for dir in readdir(STDLIB_DIR)
@@ -70,7 +74,8 @@ function parse_stdlib_version_file(path)
7074
end
7175
# This generates the value that will be passed to the `remotes` argument of makedocs(),
7276
# by looking through all *.version files in stdlib/.
73-
documenter_stdlib_remotes = let stdlib_dir = realpath(joinpath(@__DIR__, "..", "stdlib"))
77+
documenter_stdlib_remotes = let stdlib_dir = realpath(joinpath(@__DIR__, "..", "stdlib")),
78+
stdlib_build_dir = joinpath(buildrootdoc, "..", "stdlib")
7479
# Get a list of all *.version files in stdlib/..
7580
version_files = filter(readdir(stdlib_dir)) do fname
7681
isfile(joinpath(stdlib_dir, fname)) && endswith(fname, ".version")
@@ -97,7 +102,7 @@ documenter_stdlib_remotes = let stdlib_dir = realpath(joinpath(@__DIR__, "..", "
97102
versionfile[sha_key]
98103
end
99104
# Construct the absolute (local) path to the stdlib package's root directory
100-
package_root_dir = joinpath(stdlib_dir, "$(package)-$(package_sha)")
105+
package_root_dir = joinpath(stdlib_build_dir, "$(package)-$(package_sha)")
101106
# Documenter needs package_root_dir to exist --- it's just a sanity check it does on the remotes= keyword.
102107
# In normal (local) builds, this will be the case, since the Makefiles will have unpacked the standard
103108
# libraries. However, on CI we do this thing where we actually build docs in a clean worktree, just
@@ -127,7 +132,7 @@ function generate_markdown(basename)
127132
@assert length(splitted) == 2
128133
replaced_links = replace(splitted[1], r"\[\#([0-9]*?)\]" => s"[#\g<1>](https://github.com/JuliaLang/julia/issues/\g<1>)")
129134
write(
130-
joinpath(@__DIR__, "src", "$basename.md"),
135+
joinpath(buildrootdoc, "src", "$basename.md"),
131136
"""
132137
```@meta
133138
EditURL = "https://github.com/JuliaLang/julia/blob/master/$basename.md"
@@ -281,7 +286,7 @@ end
281286

282287
const use_revise = "revise=true" in ARGS
283288
if use_revise
284-
let revise_env = joinpath(@__DIR__, "deps", "revise")
289+
let revise_env = joinpath(buildrootdoc, "deps", "revise")
285290
Pkg.activate(revise_env)
286291
Pkg.add("Revise"; preserve=Pkg.PRESERVE_NONE)
287292
Base.ACTIVE_PROJECT[] = nothing
@@ -351,10 +356,6 @@ DocMeta.setdocmeta!(
351356
recursive=true, warn=false,
352357
)
353358

354-
let r = r"buildroot=(.+)", i = findfirst(x -> occursin(r, x), ARGS)
355-
global const buildroot = i === nothing ? (@__DIR__) : first(match(r, ARGS[i]).captures)
356-
end
357-
358359
const format = if render_pdf
359360
Documenter.LaTeX(
360361
platform = "texplatform=docker" in ARGS ? "docker" : "native"
@@ -377,8 +378,9 @@ else
377378
)
378379
end
379380

380-
const output_path = joinpath(buildroot, "doc", "_build", (render_pdf ? "pdf" : "html"), "en")
381+
const output_path = joinpath(buildrootdoc, "_build", (render_pdf ? "pdf" : "html"), "en")
381382
makedocs(
383+
source = joinpath(buildrootdoc, "src"),
382384
build = output_path,
383385
modules = [Main, Base, Core, [Base.root_module(Base, stdlib.stdlib) for stdlib in STDLIB_DOCS]...],
384386
clean = true,
@@ -479,7 +481,7 @@ if "deploy" in ARGS
479481
deploydocs(
480482
repo = "github.com/JuliaLang/docs.julialang.org.git",
481483
deploy_config = BuildBotConfig(),
482-
target = joinpath(buildroot, "doc", "_build", "html", "en"),
484+
target = joinpath(buildrootdoc, "_build", "html", "en"),
483485
dirname = "en",
484486
devurl = devurl,
485487
versions = Versions(["v#.#", devurl => devurl]),

0 commit comments

Comments
 (0)