Skip to content

Commit

Permalink
Merge pull request #224 from JuliaDocs/mp/non-toplevel-rewrite
Browse files Browse the repository at this point in the history
Rewrite `makedocs` also if it's not on top-level
  • Loading branch information
mortenpi authored Aug 13, 2024
2 parents c75e6ee + cca8d6c commit bf9643d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ jobs:
fail-fast: false
matrix:
version:
- '1.9'
- '1.8'
- '1.9'
- '1.10'
os:
- ubuntu-latest
arch:
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "DocumentationGenerator"
uuid = "8f0d3306-d70b-5309-b898-24bb6ab47850"
authors = ["Sebastian Pfitzner <[email protected]>", "Simon Danisch <[email protected]>", "Venkatesh Dayananda <[email protected]>"]
repo = "https://github.com/JuliaDocs/DocumentationGenerator.jl.git"
version = "0.7.8"
version = "0.7.9"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
8 changes: 6 additions & 2 deletions src/builders.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,12 @@ function build_documenter(packagespec, docdir)
```

try
run(cmd)

# We'll remove the JULIA_LOAD_PATH, since that can affect how the sub-process
# loads dependencies and therefore affect how the make.jl script gets executed.
#
# This is in particular necessary when we run a build as part of the test suite,
# which sets it.
run(addenv(cmd, "JULIA_LOAD_PATH" => nothing))
return builddir
catch err
@error("Failed to evaluate specified make.jl-file.", exception=err)
Expand Down
43 changes: 36 additions & 7 deletions src/utils/rewrite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ function fix_makefile(makefile, documenter_version = v"0.24")
ast = parseall(read(makefile, String))
make_expr = Expr(:block)

for elem in ast.args
# skip deploydocs
Meta.isexpr(elem, :call) && (elem.args[1] == :deploydocs || elem.args[1] == :(Documenter.deploydocs)) && continue
if Meta.isexpr(elem, :call) && (elem.args[1] == :makedocs || elem.args[1] == :(Documenter.makedocs))
should_break = true
for top_level_elem in ast.args
# skip deploydocs, if it appears on the top level
if Meta.isexpr(top_level_elem, :call) && (top_level_elem.args[1] == :deploydocs || top_level_elem.args[1] == :(Documenter.deploydocs))
continue
end

# Update the makedocs() call, if we find it.
should_break, new_elem = rewrite_makedocs_call(top_level_elem) do elem
# rewrite makedoc call to respect our requirements
new_args = []

Expand All @@ -48,6 +50,7 @@ function fix_makefile(makefile, documenter_version = v"0.24")
has_root = false
has_remotes = false
has_repo = false
has_warnonly = false
html = documenter_version < v"0.21" ? QuoteNode(:html) : :(Documenter.HTML())

fixkwarg = argument -> begin
Expand Down Expand Up @@ -94,6 +97,10 @@ function fix_makefile(makefile, documenter_version = v"0.24")
has_doctest = true
argument.args[2] = false
end
if name == :warnonly
has_warnonly = true
argument.args[2] = true
end
end
end

Expand Down Expand Up @@ -134,11 +141,14 @@ function fix_makefile(makefile, documenter_version = v"0.24")
if !has_repo
push!(new_args, Expr(:kw, :repo, ""))
end
if !has_warnonly
push!(new_args, Expr(:kw, :warnonly, true))
end

elem = Expr(:call, new_args...)
return Expr(:call, new_args...)
end

push!(make_expr.args, elem)
push!(make_expr.args, new_elem)

# ignore everything after `makedocs` call
should_break && break
Expand All @@ -161,3 +171,22 @@ function fix_lnns(expr, filepath)
end
end
end

function rewrite_makedocs_call(f!, ast)
if ast isa Expr
if Meta.isexpr(ast, :call) && (ast.args[1] == :makedocs || ast.args[1] == :(Documenter.makedocs))
return true, f!(ast)
else
should_break = false
for i in eachindex(ast.args)
if isa(ast.args[i], Expr)
should_break_i, elem = rewrite_makedocs_call(f!, ast.args[i])
ast.args[i] = elem
should_break |= should_break_i
end
end
return should_break, ast
end
end
return false, ast
end
12 changes: 12 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,18 @@ end
)
end
end,
(
name="JuliaHub",
url="https://github.com/JuliaComputing/JuliaHub.jl.git",
uuid="bc7fa6ce-b75e-4d60-89ad-56c957190b6e",
versions=[v"0.1.11"],
server_type="github",
api_url="",
installs = [true],
success = [true],
doctype = ["documenter"],
using_failed = [false],
)
]

basepath = @__DIR__
Expand Down

0 comments on commit bf9643d

Please sign in to comment.