Skip to content

Commit

Permalink
Merge pull request #21832 from Gollor/remoteinclude
Browse files Browse the repository at this point in the history
Fix relative path `include` on remote machines
  • Loading branch information
vtjnash authored Jun 27, 2017
2 parents 9f6ec29 + 1ce1d75 commit f31e163
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
13 changes: 10 additions & 3 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,17 @@ const _require_dependencies = Any[] # a list of (path, mtime) tuples that are th
const _track_dependencies = Ref(false) # set this to true to track the list of file dependencies
function _include_dependency(_path::AbstractString)
prev = source_path(nothing)
path = (prev === nothing) ? abspath(_path) : joinpath(dirname(prev), _path)
if prev === nothing
if myid() == 1
path = abspath(_path)
else
path = joinpath(remotecall_fetch(abspath, 1, "."), _path)
end
else
path = joinpath(dirname(prev), _path)
end
if myid() == 1 && _track_dependencies[]
apath = abspath(path)
push!(_require_dependencies, (apath, mtime(apath)))
push!(_require_dependencies, (path, mtime(path)))
end
return path, prev
end
Expand Down
41 changes: 41 additions & 0 deletions test/distributed_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,47 @@ catch ex
@test ex.captured.ex.exceptions[2].ex == UndefVarError(:DontExistOn1)
end

@test let
# creates a new worker in the same folder and tries to include file
tmp_file, temp_file_stream = mktemp()
close(temp_file_stream)
tmp_file = relpath(tmp_file)
try
proc = addprocs_with_testenv(1)
include(tmp_file)
remotecall_fetch(include, proc[1], tmp_file)
rmprocs(proc)
rm(tmp_file)
return true
catch e
println(e)
rm(tmp_file, force=true)
return false
end
end == true

@test let
# creates a new worker in the different folder and tries to include file
tmp_file, temp_file_stream = mktemp()
close(temp_file_stream)
tmp_file = relpath(tmp_file)
tmp_dir = relpath(mktempdir())
try
proc = addprocs_with_testenv(1, dir=tmp_dir)
include(tmp_file)
remotecall_fetch(include, proc[1], tmp_file)
rmprocs(proc)
rm(tmp_dir)
rm(tmp_file)
return true
catch e
println(e)
rm(tmp_dir, force=true)
rm(tmp_file, force=true)
return false
end
end == true

# Run topology tests last after removing all workers, since a given
# cluster at any time only supports a single topology.
rmprocs(workers())
Expand Down

0 comments on commit f31e163

Please sign in to comment.