Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use open do-block for code_loader writing #32

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/PackageBundler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ valid Julia files that return a `Function` accepting the required arguments as
listed below. The valid names for handlers are:

- `code_loader.jl`: A function that generates the `String` of code used to
load the serialized code. Takes `jls`, `xorshift`, `entry_point`, and
`context` as arguments.
load the serialized code. Takes `filename`, `jls`, `xorshift`,
`entry_point`, and `context` as arguments.
- `code_transformer.jl`: A function that transforms the parsed code before it
is serialized. Takes `filename`, `expr`, and `context` as arguments.
- `code_injector.jl`: A function that injects extra code into the bundled
Expand Down
35 changes: 17 additions & 18 deletions src/serializer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ function _stripcode(
code_injector = get(handlers, "code_injector") do
function (filename, context)
:(module $(gensym())
function __init__()
@debug "Loading serialized code."
end
function __init__()
@debug "Loading serialized code."
end
end)
end
end
Expand Down Expand Up @@ -83,25 +83,24 @@ function _stripcode(
# Create a shim file that will load the serialized code and evaluate it at
# precompilation time. Working directory is set to the directory of the shim
# file so that macros like `@__DIR__` and `@__FILE__` work as expected.
open(filename, "w") do io
code_loader = get(handlers, "code_loader") do
function (jls, xorshift, entry_point, context)
is_entry_point = !isnothing(entry_point)
"""
$(is_entry_point ? "module $entry_point" : "")
cd(@__DIR__) do
pkgid = Base.PkgId(Base.UUID("9e88b42a-f829-5b0c-bbe9-9e923198166b"), "Serialization")
buffer = seekstart(IOBuffer(xor.(read(\"$(basename(jls))\"), $(repr(xorshift)))))
for x in Base.require(pkgid).deserialize(buffer).args
Core.eval(@__MODULE__, x)
end
code_loader = get(handlers, "code_loader") do
function (filename, jls, xorshift, entry_point, context)
is_entry_point = !isnothing(entry_point)
"""
$(is_entry_point ? "module $entry_point" : "")
cd(@__DIR__) do
pkgid = Base.PkgId(Base.UUID("9e88b42a-f829-5b0c-bbe9-9e923198166b"), "Serialization")
buffer = seekstart(IOBuffer(xor.(read(\"$(basename(jls))\"), $(repr(xorshift)))))
for x in Base.require(pkgid).deserialize(buffer).args
Core.eval(@__MODULE__, x)
end
$(is_entry_point ? "end" : "")
"""
end
$(is_entry_point ? "end" : "")
"""
end
println(io, strip(code_loader(jls_unescaped, xorshift, entry_point, context)))
end
code = strip(code_loader(filename, jls_unescaped, xorshift, entry_point, context))
write(filename, code)

return nothing
end
Expand Down
Loading