Skip to content

Commit

Permalink
Merge 598c068 into 608de15
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Daly committed Apr 26, 2019
2 parents 608de15 + 598c068 commit 3bc454e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 22 deletions.
2 changes: 2 additions & 0 deletions examples/blink.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ function helloFromBlink()
end

Base.@ccallable function julia_main(args::Vector{String})::Cint
Main.ApplicationBuilderUtils.cd_to_bundle_resources()

# Apparently starting Electron too quickly means the OS doesn't get a
# chance to find the name of the application...
sleep(2)
Expand Down
2 changes: 2 additions & 0 deletions examples/hello.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Base.@ccallable function julia_main(ARGS::Vector{String})::Cint
println(io, "Hello, World!")
println(io, "<br> -- Love, $PROGRAM_FILE")
println(io, """<br><br>Current working directory: <a href="file://$(pwd())">$(pwd())</a>""")
Main.ApplicationBuilderUtils.cd_to_bundle_resources()
println(io, """<br><br>After cd to resources directory: <a href="file://$(pwd())">$(pwd())</a>""")
end
run(`open file://$filename`)
return 0
Expand Down
1 change: 1 addition & 0 deletions examples/libui.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ end


Base.@ccallable function julia_main(ARGS::Vector{String})::Cint
Main.ApplicationBuilderUtils.cd_to_bundle_resources()
global progressbar = uiNewProgressBar()
global spinbox = uiNewSpinbox(0, 100)
global slider = uiNewSlider(0, 100)
Expand Down
1 change: 1 addition & 0 deletions examples/sdl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function helloFromSDL()
end

Base.@ccallable function julia_main(args::Vector{String})::Cint
Main.ApplicationBuilderUtils.cd_to_bundle_resources()
helloFromSDL()
return 0
end
Expand Down
43 changes: 27 additions & 16 deletions src/ApplicationBuilder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,26 +141,37 @@ function build_app_bundle(juliaprog_main;
# the C driver program.
utils_injection_file = joinpath(launcher_dir, "applicationbuilderutils.jl")
write(utils_injection_file,
"""
Base.include(@__MODULE__, raw"$(abspath(juliaprog_main))")
"""*raw"""
Base.@ccallable function cd_to_bundle_resources()::Nothing
full_binary_name = PROGRAM_FILE # PROGRAM_FILE is set manually in program.c
@static if Sys.isapple()
m = match(r".app/Contents/MacOS/[^/]+$", full_binary_name)
if m != nothing
resources_dir = joinpath(dirname(dirname(full_binary_name)), "Resources")
cd(resources_dir)
raw"""
module ApplicationBuilderUtils
function get_bundle_resources_dir()
full_binary_name = PROGRAM_FILE # PROGRAM_FILE is set manually in program.c
@static if Sys.isapple()
m = match(r".app/Contents/MacOS/[^/]+$", full_binary_name)
if m != nothing
resources_dir = joinpath(dirname(dirname(full_binary_name)), "Resources")
return resources_dir
else
return pwd()
end
else
# TODO: Should we do similar verification on linux/windows? Maybe use splitpath()?
resources_dir = joinpath(dirname(dirname(full_binary_name)), "res")
return resources_dir
end
else
# TODO: Should we do similar verification on linux/windows? Maybe use splitpath()?
resources_dir = joinpath(dirname(dirname(full_binary_name)), "res")
end
function cd_to_bundle_resources()
resources_dir = get_bundle_resources_dir()
cd(resources_dir)
println("cd_to_bundle_resources(): Changed to new pwd: $(pwd())")
nothing
end
println("cd_to_bundle_resources(): Changed to new pwd: $(pwd())")
precompile(cd_to_bundle_resources, ()) # Compile it for the binary.
end
precompile(cd_to_bundle_resources, ()) # Compile it for the binary.
""")
""" * """
Base.include(@__MODULE__, raw"$(abspath(juliaprog_main))")
"""
)
custom_program_c = "$(@__DIR__)/program.c"
cc_flags = Sys.isapple() ? `-mmacosx-version-min=10.10 -headerpad_max_install_names` : nothing
# Provide an environment variable telling the code it's being compiled into a mac bundle.
Expand Down
6 changes: 0 additions & 6 deletions src/program.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
JULIA_DEFINE_FAST_TLS()
#endif

// `cd_to_bundle_resources` is injected by ApplicaionBuilder.jl
extern void cd_to_bundle_resources();

// Declare C prototype of a function defined in Julia
extern int julia_main(jl_array_t*);

Expand Down Expand Up @@ -48,9 +45,6 @@ int main(int argc, char *argv[])
jl_arrayset(ARGS, s, i - 1);
}

// Navigate to inside the Appication Bundle before running julia_main
cd_to_bundle_resources();

// call the work function, and get back a value
retcode = julia_main(ARGS);

Expand Down

0 comments on commit 3bc454e

Please sign in to comment.