Skip to content

Commit

Permalink
Merge e364464 into c7c6150
Browse files Browse the repository at this point in the history
  • Loading branch information
NHDaly committed Jul 22, 2018
2 parents c7c6150 + e364464 commit 06f79b7
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 4 deletions.
13 changes: 13 additions & 0 deletions examples/commandline_hello.jl
@@ -0,0 +1,13 @@
# A super-simple command line program that just prints hello.
# Build this with the `commandline_app=true` flag in `BuildApp.build_app_bundle`.

Base.@ccallable function julia_main(ARGS::Vector{String})::Cint
println("Hi what's your name?")
name = readline()
println("Oh hi, $name\! It's a pleasure to meet you.")
println("By the way, here's the current working directory:\n'$(pwd())'")

println("\nGoodbye! (Press enter to exit)")
readline()
return 0
end
2 changes: 1 addition & 1 deletion src/ApplicationBuilder.jl
Expand Up @@ -51,7 +51,7 @@ end
@static if is_linux() || is_windows()

function change_dir_if_bundle()
binary_path = split(string(Base.julia_cmd()), ' ')[1][2:end]
binary_path = PROGRAM_FILE # PROGRAM_FILE is set manually in program.c
newpath = dirname(dirname(binary_path))
cd(newpath)
println("New pwd = $(pwd())")
Expand Down
9 changes: 8 additions & 1 deletion src/BuildApp.jl
Expand Up @@ -7,12 +7,14 @@ export build_app_bundle
@static if is_apple()

include("sign_mac_app.jl")
include("mac_commandline_app.jl")

function build_app_bundle(juliaprog_main;
appname=splitext(basename(juliaprog_main))[1], builddir = "builddir",
resources = String[], libraries = String[], verbose = false,
bundle_identifier = nothing, app_version = "0.1", icns_file = nothing,
certificate = nothing, entitlements_file = nothing,
commandline_app = false,
)

builddir = abspath(builddir)
Expand All @@ -38,6 +40,11 @@ function build_app_bundle(juliaprog_main;
resourcesDir="$appDir/Resources"
libsDir="$appDir/Libraries"

if commandline_app
# Redefine launcherDir to put the binary where applet expects it.
launcherDir = build_commandline_app_bundle(builddir, binary_name, appname)
end

mkpath(launcherDir)

function has_files(files)
Expand Down Expand Up @@ -157,7 +164,7 @@ function build_app_bundle(juliaprog_main;
<key>CFBundleDisplayName</key>
<string>$appname</string>
<key>CFBundleExecutable</key>
<string>$binary_name</string>
<string>$(commandline_app ? "applet" : binary_name)</string>
<key>CFBundleIconFile</key>
<string>$appname.icns</string>
<key>CFBundleIdentifier</key>
Expand Down
7 changes: 5 additions & 2 deletions src/bundle.jl
@@ -1,8 +1,11 @@
function build_app_bundle(script::String;
if is_windows()
include("installer.jl")
end
function build_app_bundle(script::String;
resources = String[],
libraries = String[],
builddir = "builddir",
appname = "nothing",
appname = "nothing",
create_installer = false)


Expand Down
21 changes: 21 additions & 0 deletions src/mac_commandline_app.jl
@@ -0,0 +1,21 @@
function get_commandline_applescript(exe_dir, executable_path)
"""
set RootPath to POSIX path of (path to me)
tell application id "com.apple.terminal"
do script ("exec '" & RootPath & "$exe_dir/$executable_path'")
activate
end tell
"""
end

function build_commandline_app_bundle(builddir, binary_name, appname)

applescript_file = "$builddir/build_$appname.applescript"
exe_dir = "Contents/app"
write(applescript_file, get_commandline_applescript(exe_dir, binary_name))

app_path = "$builddir/$appname.app"
run(`osacompile -o $app_path $applescript_file`)

return joinpath(app_path,exe_dir)
end
5 changes: 5 additions & 0 deletions test/BuildApp.jl
Expand Up @@ -21,6 +21,11 @@ builddir = mktempdir()
end
end

@testset "commandline_app" begin
@test 0 == include("build_examples/commandline_hello.jl")
@test success(`open $builddir/hello.app`)
end


function testRunAndKillProgramSucceeds(cmd)
out, _, p = readandwrite(cmd) # Make sure it runs correctly
Expand Down
9 changes: 9 additions & 0 deletions test/build_examples/commandline_hello.jl
@@ -0,0 +1,9 @@
using ApplicationBuilder; using BuildApp

# Allow this file to be called either as a standalone file to build the above
# example, or from runtests.jl using a provided builddir.
isdefined(:builddir) || (builddir=nothing) # nothing == default builddir.

build_app_bundle(joinpath(@__DIR__,"..","..","examples","commandline_hello.jl"),
appname="hello",
commandline_app=true, builddir=builddir)

0 comments on commit 06f79b7

Please sign in to comment.