Skip to content

Commit

Permalink
Run worker project in isolated environment (#215)
Browse files Browse the repository at this point in the history
* run worker project in isolated environment

* minor fix

* fix
  • Loading branch information
vdayanand authored Dec 11, 2023
1 parent 429e6b4 commit 05d12b5
Showing 1 changed file with 48 additions and 34 deletions.
82 changes: 48 additions & 34 deletions src/DocumentationGenerator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,18 @@ function generate_dependency_list(packages;
end
end

function with_juliaenv(func, temp_path=tempname())
current_project = Base.active_project()
Pkg.activate(temp_path)
try
func()
catch ex
rethrow()
finally
Pkg.activate(current_project)
end
end

function start_builder(package, version;
basepath = error("`basepath` is a required argument."),
juliacmd = error("`juliacmd` is a required argument."),
Expand Down Expand Up @@ -276,39 +288,41 @@ function start_builder(package, version;
isdir(builddir) || mkpath(builddir)

logfile = joinpath(builddir, "..", "$(version).log")

thisproject = Base.active_project()

## api_url needs to be set to "-", since empty string should not be passed as CLI argument
pkgimagesopt = VERSION >= v"1.9" ? "--pkgimages=no" : ""

cmd = ```
$(juliacmd)
--project="$(thisproject)"
--color=no
--compiled-modules=no
$(isempty(pkgimagesopt) ? [] : pkgimagesopt)
-O0
$workerfile
$uuid
$name
$url
$version
$builddir
$registry_path
$deployment_url
$src_prefix
$href_prefix
$(server_type)
$(isempty(api_url) ? "-" : api_url)
$(update_only ? "update" : "build")
```
process, task = run_with_timeout(cmd,
log=logfile,
name = string("docs build for ", name, "@", version, " (", uuid, ")"),
timeout = timeout,
max_timeout = max_timeout,
kill_timeout = kill_timeout)
return process
docgen_path = dirname(dirname(Base.find_package("DocumentationGenerator")))
with_juliaenv() do
Pkg.develop(path=docgen_path)
Pkg.add("Pkg")
## api_url needs to be set to "-", since empty string should not be passed as CLI argument
pkgimagesopt = VERSION >= v"1.9" ? "--pkgimages=no" : ""
cmd = ```
$(juliacmd)
--project=$(Base.active_project())
--color=no
--compiled-modules=no
$(isempty(pkgimagesopt) ? [] : pkgimagesopt)
-O0
$workerfile
$uuid
$name
$url
$version
$builddir
$registry_path
$deployment_url
$src_prefix
$href_prefix
$(server_type)
$(isempty(api_url) ? "-" : api_url)
$(update_only ? "update" : "build")
```
process, task = run_with_timeout(cmd,
log=logfile,
name = string("docs build for ", name, "@", version, " (", uuid, ")"),
timeout = timeout,
max_timeout = max_timeout,
kill_timeout = kill_timeout)
return process
end
end
end

0 comments on commit 05d12b5

Please sign in to comment.