Skip to content

Commit 3902ee2

Browse files
JanisErdmanisJanis Erdmanis
andauthored
Integration of system image generation, JuliaC and refactor (#25)
* refactor package retrieval * sysimg integration work * fixing sysimg building bugs * AppEnv refactor * add remove_sources flag * refactoring stage module * renaming examples * renaming PkgImage -> JuliaAppBundle * juliac implementation * AppEnv config refactor; selective assets --------- Co-authored-by: Janis Erdmanis <janiserdmanis@protonmail.ch>
1 parent 51a2d8a commit 3902ee2

74 files changed

Lines changed: 2015 additions & 881 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AppEnv/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "AppEnv"
22
uuid = "9f11263e-cf0d-4932-bae6-807953dbea74"
33
authors = ["Janis Erdmanis <janiserdmanis@protonmail.ch>"]
4-
version = "0.1.0"
4+
version = "0.2.0"
55

66
[compat]
77
julia = "1"

AppEnv/src/AppEnv.jl

Lines changed: 101 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,38 @@ import Base: PkgId, PkgOrigin, UUID
55
const RUNTIME_MODE_OPTIONS = ["MIN", "INTERACTIVE", "COMPILATION", "SANDBOX"]
66

77
# Compilation can be done in one mode
8-
const DEFAULT_RUNTIME_MODE = get(ENV, "DEFAULT_RUNTIME_MODE", get(ENV, "RUNTIME_MODE", "INTERACTIVE"))
8+
#const DEFAULT_RUNTIME_MODE = get(ENV, "DEFAULT_RUNTIME_MODE", get(ENV, "RUNTIME_MODE", "INTERACTIVE"))
99

1010
#get(ENV, "JULIA_RUNTIME_MODE", "INTERACTIVE") # We set it at compilation
1111

12-
const DEFAULT_MODULE_NAME = get(ENV, "MODULE_NAME", "MainEnv")
13-
const DEFAULT_APP_NAME = get(ENV, "APP_NAME", "")
14-
const DEFAULT_BUNDLE_IDENTIFIER = get(ENV, "BUNDLE_IDENTIFIER", "")
12+
#const DEFAULT_MODULE_NAME = get(ENV, "MODULE_NAME", "MainEnv")
13+
#const DEFAULT_APP_NAME = get(ENV, "APP_NAME", "")
14+
#const DEFAULT_BUNDLE_IDENTIFIER = get(ENV, "BUNDLE_IDENTIFIER", "")
1515

16-
const DEFAULT_STDLIB = get(ENV, "STDLIB", relpath(Sys.STDLIB, dirname(Sys.BINDIR)))
16+
#const DEFAULT_STDLIB = get(ENV, "STDLIB", relpath(Sys.STDLIB, dirname(Sys.BINDIR)))
1717

18-
println("Compilation is about to happen with the following parameters:")
19-
println("\tDEFAULT_RUNTIME_MODE=" * DEFAULT_RUNTIME_MODE)
20-
println("\tDEFAULT_MODULE_NAME=" * DEFAULT_MODULE_NAME)
21-
println("\tDEFAULT_APP_NAME=" * DEFAULT_APP_NAME)
22-
println("\tDEFAULT_BUNDLE_IDENTIFIER=" * DEFAULT_BUNDLE_IDENTIFIER)
18+
# println("Compilation is about to happen with the following parameters:")
19+
# println("\tDEFAULT_RUNTIME_MODE=" * DEFAULT_RUNTIME_MODE)
20+
# println("\tDEFAULT_MODULE_NAME=" * DEFAULT_MODULE_NAME)
21+
# println("\tDEFAULT_APP_NAME=" * DEFAULT_APP_NAME)
22+
# println("\tDEFAULT_BUNDLE_IDENTIFIER=" * DEFAULT_BUNDLE_IDENTIFIER)
2323

2424
global USER_DATA::String # This is set by the startup macro itself
2525

2626

2727
# Theese constants must be present at compilation time as otherwise it does not make sense
2828

29-
function save_pkgorigins(path, pkgorigins::Dict{PkgId, PkgOrigin}; stdlib_dir = Sys.STDLIB)
29+
function save_pkgorigins(index_path, pkgorigins::Dict{PkgId, PkgOrigin}; root_dir = nothing)
3030

31-
file = open(path, "w")
31+
file = open(index_path, "w")
3232

3333
try
3434
for (pkgid, pkgorigin) in pkgorigins
3535

3636
(; name, uuid) = pkgid
3737
(; path, version) = pkgorigin
3838

39-
rpath = relpath(path, stdlib_dir)
39+
rpath = isnothing(root_dir) ? path : relpath(path, root_dir)
4040

4141
println(file, "$uuid\t$name\t$version\t$rpath")
4242

@@ -70,7 +70,7 @@ function parse_version(version_str::AbstractString)
7070
return VersionNumber(major, minor, patch)
7171
end
7272

73-
function load_pkgorigins!(pkgorigins, path; stdlib_dir = Sys.STDLIB)
73+
function load_pkgorigins!(pkgorigins, path; root_dir = dirname(path))
7474
#pkgorigins = Dict{PkgId, PkgOrigin}()
7575

7676
file = open(path, "r")
@@ -99,11 +99,11 @@ function load_pkgorigins!(pkgorigins, path; stdlib_dir = Sys.STDLIB)
9999
end
100100

101101
# Reconstruct absolute path
102-
abspath = joinpath(stdlib_dir, rpath)
102+
_abspath = abspath(joinpath(root_dir, rpath))
103103

104104
# Create PkgId and PkgOrigin
105105
pkg_id = PkgId(uuid, name)
106-
pkg_origin = PkgOrigin(abspath, nothing, version)
106+
pkg_origin = PkgOrigin(_abspath, nothing, version)
107107

108108
# Add to dictionary
109109
pkgorigins[pkg_id] = pkg_origin
@@ -116,17 +116,17 @@ function load_pkgorigins!(pkgorigins, path; stdlib_dir = Sys.STDLIB)
116116
end
117117

118118

119-
function collect_pkgorigins!(pkgorigins::Dict{PkgId, PkgOrigin}; stdlib_dir = Sys.STDLIB)
119+
function collect_pkgorigins!(pkgorigins::Dict{PkgId, PkgOrigin}; root_dir = Sys.STDLIB)
120120

121121
uuid_regex = r"^uuid\s*=\s*\"([a-f0-9\-]+)\""mi
122122
version_regex = r"^version\s*=\s*\"([^\"]+)\""mi
123123

124-
if !isdir(stdlib_dir)
124+
if !isdir(root_dir)
125125
return pkgorigins
126126
end
127127

128-
for name in readdir(stdlib_dir)
129-
pkg_path = joinpath(stdlib_dir, name)
128+
for name in readdir(root_dir)
129+
pkg_path = joinpath(root_dir, name)
130130

131131
# Skip if not a directory
132132
isdir(pkg_path) || continue
@@ -174,18 +174,18 @@ function collect_pkgorigins!(pkgorigins::Dict{PkgId, PkgOrigin}; stdlib_dir = Sy
174174
return pkgorigins
175175
end
176176

177-
collect_pkgorigins(; stdlib_dir = Sys.STDLIB) = collect_pkgorigins!(Dict{PkgId, PkgOrigin}(); stdlib_dir)
177+
collect_pkgorigins(; root_dir = Sys.STDLIB) = collect_pkgorigins!(Dict{PkgId, PkgOrigin}(); root_dir)
178178

179179

180-
function set_load_path!(LOAD_PATH; module_name="")
180+
function set_load_path!(LOAD_PATH; stdlib_project_name)
181181

182182
empty!(LOAD_PATH)
183183
push!(LOAD_PATH, "@", "@stdlib")
184-
push!(LOAD_PATH, joinpath(Sys.STDLIB, module_name))
184+
push!(LOAD_PATH, joinpath(Sys.STDLIB, stdlib_project_name))
185185

186186
end
187187

188-
function set_depot_path!(DEPOT_PATH; bundle_identifier, app_name, runtime_mode)
188+
function set_depot_path!(DEPOT_PATH; bundle_identifier = "", app_name = "", runtime_mode = "MIN")
189189

190190
if runtime_mode == "SANDBOX"
191191

@@ -194,24 +194,15 @@ function set_depot_path!(DEPOT_PATH; bundle_identifier, app_name, runtime_mode)
194194
elseif Sys.isapple()
195195
set_depot_path_macos!(DEPOT_PATH; app_name)
196196
elseif Sys.islinux()
197-
set_depot_path_snap!(DEPOT_PATH; app_name)
197+
set_depot_path_snap!(DEPOT_PATH)
198198
else
199199
error("Sandbox runtime mode is only supported for windows, macos and linux")
200200
end
201201

202-
elseif runtime_mode == "COMPILATION"
203-
204-
set_depot_path_min!(DEPOT_PATH)
205-
popfirst!(DEPOT_PATH)
206-
207202
elseif runtime_mode == "MIN"
208203

209204
set_depot_path_min!(DEPOT_PATH)
210205

211-
elseif runtime_mode == "INTERACTIVE"
212-
213-
global USER_DATA = get(ENV, "USER_DATA", mktempdir())
214-
215206
else
216207
error("Sandbox mode RUNTIME_MODE=$runtime_mode not supported")
217208
end
@@ -247,7 +238,7 @@ function set_depot_path_macos!(DEPOT_PATH::Vector{String}; app_name)
247238
return
248239
end
249240

250-
function set_depot_path_snap!(DEPOT_PATH::Vector{String})
241+
function set_depot_path_snap!(DEPOT_PATH)
251242

252243
empty!(DEPOT_PATH)
253244

@@ -272,7 +263,7 @@ function set_depot_path_snap!(DEPOT_PATH::Vector{String})
272263

273264
end
274265

275-
push!(DEPOT_PATH, dirname(dirname(Sys.STDLIB)))
266+
push!(DEPOT_PATH, joinpath(dirname(Sys.BINDIR), "share/julia"))
276267

277268
return
278269
end
@@ -326,29 +317,24 @@ function set_depot_path_msix!(DEPOT_PATH; bundle_identifier)
326317
return
327318
end
328319

329-
330-
function init(;
331-
runtime_mode::String = get(ENV, "RUNTIME_MODE", DEFAULT_RUNTIME_MODE),
332-
module_name::String = get(ENV, "MODULE_NAME", DEFAULT_MODULE_NAME),
333-
app_name::String = get(ENV, "APP_NAME", DEFAULT_APP_NAME),
334-
bundle_identifier::String = get(ENV, "BUNDLE_IDENTIFIER", DEFAULT_BUNDLE_IDENTIFIER)
335-
)
336-
337-
338-
@assert runtime_mode in RUNTIME_MODE_OPTIONS "runtime_mode=$runtime_mode not recognized. Available options are $(join(RUNTIME_MODE_OPTIONS, '|'))"
339-
340-
if runtime_mode == "INTERACTIVE"
341-
global USER_DATA = get(ENV, "USER_DATA", mktempdir())
342-
return
320+
function load_config(config_path)
321+
config_dict = Dict{String, String}()
322+
323+
for line in eachline(config_path)
324+
# Skip empty lines
325+
isempty(strip(line)) && continue
326+
327+
# Split on the first '=' character
328+
key, value = split(line, '=', limit=2)
329+
config_dict[strip(key)] = strip(value)
343330
end
344331

345-
Sys.STDLIB = joinpath(dirname(Sys.BINDIR), DEFAULT_STDLIB)
332+
runtime_mode = config_dict["RUNTIME_MODE"]
333+
stdlib_project_name = config_dict["STDLIB_PROJECT_NAME"]
334+
app_name = get(config_dict, "APP_NAME", "")
335+
bundle_identifier = get(config_dict, "BUNDLE_IDENTIFIER", "")
346336

347-
# This is a bit of a hack
348-
if isempty(module_name)
349-
#error("MODULE_NAME not set")
350-
module_name = get(ENV, "MODULE_NAME", DEFAULT_MODULE_NAME)
351-
end
337+
@assert runtime_mode in RUNTIME_MODE_OPTIONS
352338

353339
if runtime_mode == "SANDBOX"
354340

@@ -361,37 +347,77 @@ function init(;
361347
end
362348
end
363349

364-
set_load_path!(Base.LOAD_PATH; module_name)
365-
set_depot_path!(Base.DEPOT_PATH; app_name, bundle_identifier, runtime_mode)
350+
return (; runtime_mode, stdlib_project_name, app_name, bundle_identifier)
351+
end
366352

367-
if runtime_mode == "COMPILATION"
368-
popfirst!(Base.LOAD_PATH)
369-
else
370353

371-
index_path = joinpath(Sys.STDLIB, "index")
372-
if isfile(index_path)
373-
load_pkgorigins!(Base.pkgorigins, index_path)
374-
else
375-
collect_pkgorigins!(Base.pkgorigins)
376-
end
354+
function save_config(config_path; stdlib_project_name, app_name = "", bundle_identifier = "", runtime_mode = "MIN")
377355

378-
end
356+
@assert runtime_mode in RUNTIME_MODE_OPTIONS
357+
358+
config = """
359+
RUNTIME_MODE=$runtime_mode
360+
STDLIB_PROJECT_NAME=$stdlib_project_name
361+
APP_NAME=$app_name
362+
BUNDLE_IDENTIFIER=$bundle_identifier
363+
"""
364+
365+
rm(config_path; force=true)
366+
write(config_path, config)
379367

380368
return
381369
end
382370

383371

384-
function reset_cache()
372+
# function init(;
373+
# runtime_mode::String = get(ENV, "RUNTIME_MODE", DEFAULT_RUNTIME_MODE),
374+
# module_name::String = get(ENV, "MODULE_NAME", DEFAULT_MODULE_NAME),
375+
# app_name::String = get(ENV, "APP_NAME", DEFAULT_APP_NAME),
376+
# bundle_identifier::String = get(ENV, "BUNDLE_IDENTIFIER", DEFAULT_BUNDLE_IDENTIFIER)
377+
# )
378+
385379

386-
pkg = Base.PkgId(Base.UUID("9f11263e-cf0d-4932-bae6-807953dbea74"), "AppEnv")
387-
cache_dir = Base.compilecache_path(pkg)
380+
function init(; config_path = joinpath(dirname(Sys.BINDIR), "config"),
381+
index_path = joinpath(dirname(Sys.BINDIR), "index"))
388382

389-
if !isnothing(cache_dir)
390-
@info "Removing the cache"
391-
rm(cache_dir; recursive=true)
383+
# Prevents reinitialization
384+
if isdefined(@__MODULE__, :USER_DATA)
385+
return
392386
end
393-
387+
388+
# If config file is not present we assume it is an interactive mode
389+
if !isfile(config_path)
390+
global USER_DATA = get(ENV, "USER_DATA", mktempdir())
391+
return
392+
end
393+
394+
(; runtime_mode, stdlib_project_name, app_name, bundle_identifier) = load_config(config_path)
395+
396+
set_load_path!(Base.LOAD_PATH; stdlib_project_name)
397+
set_depot_path!(Base.DEPOT_PATH; app_name, bundle_identifier, runtime_mode)
398+
399+
if isfile(index_path)
400+
load_pkgorigins!(Base.pkgorigins, index_path)
401+
else
402+
@warn "Can't find pkgorigin index at $index_path"
403+
#collect_pkgorigins!(Base.pkgorigins)
404+
end
405+
406+
return
394407
end
395408

396409

410+
# function reset_cache()
411+
412+
# pkg = Base.PkgId(Base.UUID("9f11263e-cf0d-4932-bae6-807953dbea74"), "AppEnv")
413+
# cache_dir = Base.compilecache_path(pkg)
414+
415+
# if !isnothing(cache_dir)
416+
# @info "Removing the cache"
417+
# rm(cache_dir; recursive=true)
418+
# end
419+
420+
# end
421+
422+
397423
end # module AppEnv

AppEnv/test/runtests.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,22 @@ import Base: PkgId, PkgOrigin
2424

2525
end
2626

27+
28+
@testset "config" begin
29+
30+
runtime_mode = "SANDBOX"
31+
stdlib_project_name = "MyApp"
32+
bundle_identifier = "org.appbundler.myapp"
33+
app_name = "MyApp"
34+
35+
config_path = tempname()
36+
37+
AppEnv.save_config(config_path; runtime_mode, stdlib_project_name, bundle_identifier, app_name)
38+
loaded = AppEnv.load_config(config_path)
39+
40+
@test loaded.runtime_mode == runtime_mode
41+
@test loaded.stdlib_project_name == stdlib_project_name
42+
@test loaded.bundle_identifier == bundle_identifier
43+
@test loaded.app_name == app_name
44+
45+
end

Project.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
name = "AppBundler"
22
uuid = "40eb83ae-c93a-480c-8f39-f018b568f472"
33
authors = ["Janis Erdmanis <janiserdmanis@protonmail.ch>"]
4-
version = "0.5.1"
4+
version = "0.6.0"
55

66
[deps]
77
AppBundlerUtils_jll = "20612f45-4fe6-500a-af5c-19078bfe0d65"
8+
AppEnv = "9f11263e-cf0d-4932-bae6-807953dbea74"
89
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
910
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
1011
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
@@ -14,10 +15,12 @@ FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
1415
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
1516
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
1617
ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795"
18+
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
1719
Makemsix_jll = "92e7c7cf-2c17-5ab8-9563-5ab5b2fcee8a"
1820
Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70"
1921
OpenSSL_jll = "458c3c95-2e84-50aa-8efc-19380b2a3a95"
2022
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
23+
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
2124
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
2225
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2326
Scratch = "6c6a2e73-6563-6170-7368-637461726353"
@@ -30,6 +33,9 @@ osslsigncode_jll = "5a7615ae-274c-51d1-b5a8-ff30401c2c7e"
3033
rcodesign_jll = "81561df1-22b2-57e5-9f67-03318e1fa9d9"
3134
squashfs_tools_jll = "eed32e3e-a7c5-5bf9-9121-5cf3ab653887"
3235

36+
[sources]
37+
AppEnv = {path = "AppEnv"}
38+
3339
[compat]
3440
AppBundlerUtils_jll = "=0.4.0"
3541
Base64 = "1.11.0"
@@ -40,10 +46,12 @@ FileIO = "1.17.0"
4046
ImageCore = "0.10.5"
4147
ImageIO = "0.6.9"
4248
ImageTransformations = "0.10.2"
49+
Libdl = "1.11.0"
4350
Makemsix_jll = "1.7.241"
4451
Mustache = "1"
4552
OpenSSL_jll = "3.5"
4653
Pkg = "1.9"
54+
Printf = "1.11.0"
4755
PyCall = "1.96.4"
4856
Random = "1.11.0"
4957
Scratch = "1.2"
@@ -64,3 +72,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
6472

6573
[targets]
6674
test = ["Test", "SafeTestsets", "SHA"]
75+

0 commit comments

Comments
 (0)