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

Add commandline_app flag for Apps without a GUI. On Mac, this will create an App bundle which simply opens a Terminal and runs your code. I *believe* that on Windows, there's nothing special to be done; I think it will Just Work like this by default. #17

Merged
merged 3 commits into from
Jul 22, 2018
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
13 changes: 13 additions & 0 deletions examples/commandline_hello.jl
Original file line number Diff line number Diff line change
@@ -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
9 changes: 8 additions & 1 deletion src/BuildApp.jl
Original file line number Diff line number Diff line change
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
21 changes: 21 additions & 0 deletions src/mac_commandline_app.jl
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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)