Skip to content

Commit 8a8bdc6

Browse files
authored
Allow user to specify a custom binary name (#349)
* Allow user to specify a custom app name
1 parent a8dd129 commit 8a8bdc6

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

docs/src/apps.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ multiplication, `rand(3,3) * rand(3,3)` requires both the standard libraries
168168
Nevertheless, the option is there to use. Just make sure to properly test the
169169
app with the resulting sysimage.
170170

171+
### Custom binary name
172+
173+
By default, the binary in the `bin` directory take the name of the project,
174+
as defined in `Project.toml`. If you want to change the name, you can pass
175+
`app_name="some_app_name"` to `create_app`.
171176

172177
### Artifacts
173178

@@ -252,4 +257,3 @@ CodeInfo(
252257
│ value@_3
253258
│ %11 = MyApp.DEPOT_PATH
254259
```
255-

src/PackageCompiler.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,9 @@ compiler.
549549
550550
### Keyword arguments:
551551
552+
- `app_name::String`: an alternative name for the compiled app. If not provided,
553+
the name of the package (as specified in Project.toml) is used.
554+
552555
- `precompile_execution_file::Union{String, Vector{String}}`: A file or list of
553556
files that contain code which precompilation statements should be recorded from.
554557
@@ -573,6 +576,7 @@ compiler.
573576
"""
574577
function create_app(package_dir::String,
575578
app_dir::String;
579+
app_name=nothing,
576580
precompile_execution_file::Union{String, Vector{String}}=String[],
577581
precompile_statements_file::Union{String, Vector{String}}=String[],
578582
incremental=false,
@@ -590,7 +594,10 @@ function create_app(package_dir::String,
590594
if ctx.env.pkg === nothing
591595
error("expected package to have a `name`-entry")
592596
end
593-
app_name = ctx.env.pkg.name
597+
sysimg_name = ctx.env.pkg.name
598+
if app_name === nothing
599+
app_name = sysimg_name
600+
end
594601
sysimg_file = app_name * "." * Libdl.dlext
595602
if isdir(app_dir)
596603
if !force
@@ -621,15 +628,15 @@ function create_app(package_dir::String,
621628
incremental=false, filter_stdlibs=filter_stdlibs,
622629
cpu_target=cpu_target)
623630

624-
create_sysimage(Symbol(app_name); sysimage_path=sysimg_file, project=package_dir,
631+
create_sysimage(Symbol(sysimg_name); sysimage_path=sysimg_file, project=package_dir,
625632
incremental=true,
626633
precompile_execution_file=precompile_execution_file,
627634
precompile_statements_file=precompile_statements_file,
628635
cpu_target=cpu_target,
629636
base_sysimage=tmp_base_sysimage,
630637
isapp=true)
631638
else
632-
create_sysimage(Symbol(app_name); sysimage_path=sysimg_file, project=package_dir,
639+
create_sysimage(Symbol(sysimg_name); sysimage_path=sysimg_file, project=package_dir,
633640
incremental=incremental, filter_stdlibs=filter_stdlibs,
634641
precompile_execution_file=precompile_execution_file,
635642
precompile_statements_file=precompile_statements_file,

test/runtests.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,22 @@ end
5050
for incremental in (is_slow_ci ? (false,) : (true, false))
5151
if incremental == false
5252
filter_stdlibs = (is_slow_ci ? (true, ) : (true, false))
53+
binary_name_args = ("CustomName", nothing)
5354
else
5455
filter_stdlibs = (false,)
56+
binary_name_args = (nothing,)
5557
end
56-
for filter in filter_stdlibs
58+
for (filter, name) in zip(filter_stdlibs, binary_name_args)
5759
tmp_app_source_dir = joinpath(tmp, "MyApp")
5860
cp(app_source_dir, tmp_app_source_dir)
5961
create_app(tmp_app_source_dir, app_compiled_dir; incremental=incremental, force=true, filter_stdlibs=filter,
60-
precompile_execution_file=joinpath(app_source_dir, "precompile_app.jl"))
62+
precompile_execution_file=joinpath(app_source_dir, "precompile_app.jl"), app_name=name)
6163
rm(tmp_app_source_dir; recursive=true)
6264
# Get rid of some local state
6365
rm(joinpath(new_depot, "packages"); recursive=true)
6466
rm(joinpath(new_depot, "compiled"); recursive=true)
65-
app_path = abspath(app_compiled_dir, "bin", "MyApp" * (Sys.iswindows() ? ".exe" : ""))
67+
app_name = name !== nothing ? name : "MyApp"
68+
app_path = abspath(app_compiled_dir, "bin", app_name * (Sys.iswindows() ? ".exe" : ""))
6669
app_output = read(`$app_path`, String)
6770

6871
# Check stdlib filtering

0 commit comments

Comments
 (0)