Skip to content

Commit 0b7a864

Browse files
committed
On-demand calculation of gdk-pixbuf loader cache, proper setting of XDG_DATA_DIRS and more~
1 parent 0513a7d commit 0b7a864

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ deps/deps.jl
33
docs/build
44
.DS_Store
55
Manifest.toml
6+
MutableArtifacts.toml

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ GTK3_jll = "77ec8976-b24b-556a-a1bf-49a033a670a6"
1010
Glib_jll = "7746bdde-850d-59dc-9ae8-88ece973131d"
1111
Graphics = "a2bd30eb-e257-5431-a919-1863eab51364"
1212
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
13+
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1314
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1415
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
1516
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
17+
adwaita_icon_theme_jll = "b437f822-2cd6-5e08-a15c-8bac984d38ee"
1618
gdk_pixbuf_jll = "da03df04-f53b-5353-a52f-6a8b0620ced0"
1719

1820
[compat]

src/Gtk.jl

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
module Gtk
33

44
# Import binary definitions
5-
using GTK3_jll
6-
using Glib_jll
7-
using gdk_pixbuf_jll
5+
using GTK3_jll, Glib_jll, gdk_pixbuf_jll, adwaita_icon_theme_jll, gdk_pixbuf_jll
6+
using Pkg.Artifacts
87
const libgdk = libgdk3
98
const libgtk = libgtk3
109

@@ -72,16 +71,44 @@ include("gio.jl")
7271
include("application.jl")
7372

7473
function __init__()
75-
# Set up environment variables so that gdk-pixbuf can find its loaders
76-
if get(ENV, "GDK_PIXBUF_MODULEDIR", "") == ""
77-
ENV["GDK_PIXBUF_MODULEDIR"] = joinpath(
78-
dirname(gdk_pixbuf_jll.libgdkpixbuf_path),
79-
"gdk-pixbuf-2.0",
80-
"2.10.0",
81-
"loaders",
74+
# Set XDG_DATA_DIRS so that Gtk can find its icons and schemas
75+
ENV["XDG_DATA_DIRS"] = join(filter(x -> x != nothing, [
76+
dirname(adwaita_icon_theme_jll.icons_dir),
77+
joinpath(dirname(GTK3_jll.libgdk3_path), "..", "share"),
78+
get(ENV, "XDG_DATA_DIRS", nothing),
79+
]), ":")
80+
81+
# Next, ensure that gdk-pixbuf has its loaders.cache file; we generate a
82+
# MutableArtifacts.toml file that maps in a loaders.cache we dynamically
83+
# generate by running `gdk-pixbuf-query-loaders:`
84+
mutable_artifacts_toml = joinpath(dirname(@__DIR__), "MutableArtifacts.toml")
85+
loaders_cache_name = "gdk-pixbuf-loaders-cache"
86+
loaders_cache_hash = artifact_hash(loaders_cache_name, mutable_artifacts_toml)
87+
if loaders_cache_hash === nothing
88+
# Run gdk-pixbuf-query-loaders, capture output,
89+
loader_cache_contents = gdk_pixbuf_query_loaders() do gpql
90+
withenv("GDK_PIXBUF_MODULEDIR" => gdk_pixbuf_loaders_dir) do
91+
return String(read(`$gpql`))
92+
end
93+
end
94+
95+
# Write cache out to file in new artifact
96+
loaders_cache_hash = create_artifact() do art_dir
97+
open(joinpath(art_dir, "loaders.cache"), "w") do io
98+
write(io, loader_cache_contents)
99+
end
100+
end
101+
bind_artifact!(mutable_artifacts_toml,
102+
loaders_cache_name,
103+
loaders_cache_hash;
104+
force=true
82105
)
83106
end
84107

108+
# Point gdk to our cached loaders
109+
ENV["GDK_PIXBUF_MODULE_FILE"] = joinpath(artifact_path(loaders_cache_hash), "loaders.cache")
110+
ENV["GDK_PIXBUF_MODULEDIR"] = gdk_pixbuf_loaders_dir
111+
85112
GError() do error_check
86113
ccall((:gtk_init_with_args, libgtk), Bool,
87114
(Ptr{Nothing}, Ptr{Nothing}, Ptr{UInt8}, Ptr{Nothing}, Ptr{UInt8}, Ptr{GError}),

0 commit comments

Comments
 (0)