Skip to content

Commit 05d12b5

Browse files
authored
Run worker project in isolated environment (#215)
* run worker project in isolated environment * minor fix * fix
1 parent 429e6b4 commit 05d12b5

File tree

1 file changed

+48
-34
lines changed

1 file changed

+48
-34
lines changed

src/DocumentationGenerator.jl

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,18 @@ function generate_dependency_list(packages;
244244
end
245245
end
246246

247+
function with_juliaenv(func, temp_path=tempname())
248+
current_project = Base.active_project()
249+
Pkg.activate(temp_path)
250+
try
251+
func()
252+
catch ex
253+
rethrow()
254+
finally
255+
Pkg.activate(current_project)
256+
end
257+
end
258+
247259
function start_builder(package, version;
248260
basepath = error("`basepath` is a required argument."),
249261
juliacmd = error("`juliacmd` is a required argument."),
@@ -276,39 +288,41 @@ function start_builder(package, version;
276288
isdir(builddir) || mkpath(builddir)
277289

278290
logfile = joinpath(builddir, "..", "$(version).log")
279-
280-
thisproject = Base.active_project()
281-
282-
## api_url needs to be set to "-", since empty string should not be passed as CLI argument
283-
pkgimagesopt = VERSION >= v"1.9" ? "--pkgimages=no" : ""
284-
285-
cmd = ```
286-
$(juliacmd)
287-
--project="$(thisproject)"
288-
--color=no
289-
--compiled-modules=no
290-
$(isempty(pkgimagesopt) ? [] : pkgimagesopt)
291-
-O0
292-
$workerfile
293-
$uuid
294-
$name
295-
$url
296-
$version
297-
$builddir
298-
$registry_path
299-
$deployment_url
300-
$src_prefix
301-
$href_prefix
302-
$(server_type)
303-
$(isempty(api_url) ? "-" : api_url)
304-
$(update_only ? "update" : "build")
305-
```
306-
process, task = run_with_timeout(cmd,
307-
log=logfile,
308-
name = string("docs build for ", name, "@", version, " (", uuid, ")"),
309-
timeout = timeout,
310-
max_timeout = max_timeout,
311-
kill_timeout = kill_timeout)
312-
return process
291+
docgen_path = dirname(dirname(Base.find_package("DocumentationGenerator")))
292+
with_juliaenv() do
293+
Pkg.develop(path=docgen_path)
294+
Pkg.add("Pkg")
295+
## api_url needs to be set to "-", since empty string should not be passed as CLI argument
296+
pkgimagesopt = VERSION >= v"1.9" ? "--pkgimages=no" : ""
297+
cmd = ```
298+
$(juliacmd)
299+
--project=$(Base.active_project())
300+
--color=no
301+
--compiled-modules=no
302+
$(isempty(pkgimagesopt) ? [] : pkgimagesopt)
303+
-O0
304+
$workerfile
305+
$uuid
306+
$name
307+
$url
308+
$version
309+
$builddir
310+
$registry_path
311+
$deployment_url
312+
$src_prefix
313+
$href_prefix
314+
$(server_type)
315+
$(isempty(api_url) ? "-" : api_url)
316+
$(update_only ? "update" : "build")
317+
318+
```
319+
process, task = run_with_timeout(cmd,
320+
log=logfile,
321+
name = string("docs build for ", name, "@", version, " (", uuid, ")"),
322+
timeout = timeout,
323+
max_timeout = max_timeout,
324+
kill_timeout = kill_timeout)
325+
return process
326+
end
313327
end
314328
end

0 commit comments

Comments
 (0)