Skip to content

Commit

Permalink
Install PackageCompiler outside julia-py
Browse files Browse the repository at this point in the history
...to reduce method re-definition warnings
  • Loading branch information
tkf committed Apr 12, 2019
1 parent f84f73b commit 3b939df
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 37 deletions.
30 changes: 1 addition & 29 deletions src/julia/compile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,7 @@ end

using Pkg

function cat_build_log(pkg)
modpath = Base.locate_package(pkg)
if modpath !== nothing
logfile = joinpath(dirname(modpath), "..", "deps", "build.log")
if isfile(logfile)
print(stderr, read(logfile, String))
return
end
end
@error "build.log for $pkg not found"
end

if isempty(compiler_env)
compiler_env = abspath("compiler_env")
Pkg.activate(compiler_env)
@info "Installing PackageCompiler..."
Pkg.add([
PackageSpec(
name = "PackageCompiler",
uuid = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d",
version = "0.6",
)
])
cat_build_log(Base.PkgId(
Base.UUID("9b87118b-4619-50d2-8e1e-99f35a4d4d9d"),
"PackageCompiler"))
else
Pkg.activate(compiler_env)
end
Pkg.activate(compiler_env)
@info "Loading PackageCompiler..."
using PackageCompiler

Expand Down
38 changes: 38 additions & 0 deletions src/julia/install-packagecompiler.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
compiler_env, = ARGS

if VERSION < v"0.7-"
error("Unsupported Julia version $VERSION")
end

using Pkg

function cat_build_log(pkg)
modpath = Base.locate_package(pkg)
if modpath !== nothing
logfile = joinpath(dirname(modpath), "..", "deps", "build.log")
if isfile(logfile)
print(stderr, read(logfile, String))
return
end
end
@error "build.log for $pkg not found"
end

Pkg.activate(compiler_env)
@info "Installing PackageCompiler..."

Pkg.add([
PackageSpec(
name = "PackageCompiler",
uuid = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d",
version = "0.6",
)
])
cat_build_log(Base.PkgId(
Base.UUID("9b87118b-4619-50d2-8e1e-99f35a4d4d9d"),
"PackageCompiler"))

@info "Loading PackageCompiler..."
using PackageCompiler

@info "PackageCompiler is successfully installed at $compiler_env"
32 changes: 24 additions & 8 deletions src/julia/sysimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ def script_path(name):
return os.path.join(os.path.dirname(os.path.realpath(__file__)), name)


def install_packagecompiler_cmd(julia, compiler_env):
cmd = [julia]
if sys.stdout.isatty():
cmd.append("--color=yes")
cmd.append(script_path("install-packagecompiler.jl"))
cmd.append(compiler_env)
return cmd


def build_sysimage_cmd(julia_py, julia, compile_args):
cmd = [julia_py, "--julia", julia]
if sys.stdout.isatty():
Expand Down Expand Up @@ -73,15 +82,22 @@ def build_sysimage(

julia_py = julia_py_executable()

# Arguments to ./compile.jl script:
compile_args = [
compiler_env,
# script -- ./precompile.jl by default
os.path.realpath(script),
# output -- path to sys.o file
os.path.realpath(output),
]
with temporarydirectory(prefix="tmp.pyjulia.sysimage.") as path:
if not compiler_env:
compiler_env = os.path.join(path, "compiler_env")
# Not using julia-py to install PackageCompiler to reduce
# method re-definition warnings:
check_call(install_packagecompiler_cmd(julia, compiler_env), cwd=path)

# Arguments to ./compile.jl script:
compile_args = [
compiler_env,
# script -- ./precompile.jl by default
os.path.realpath(script),
# output -- path to sys.o file
os.path.realpath(output),
]

check_call(build_sysimage_cmd(julia_py, julia, compile_args), cwd=path)


Expand Down

0 comments on commit 3b939df

Please sign in to comment.