Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
On-demand calculation of gdk-pixbuf loader cache, proper setting of `…
Browse files Browse the repository at this point in the history
…XDG_DATA_DIRS` and more~
  • Loading branch information
staticfloat committed Oct 17, 2019
1 parent 0513a7d commit 0b7a864
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ deps/deps.jl
docs/build
.DS_Store
Manifest.toml
MutableArtifacts.toml
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ GTK3_jll = "77ec8976-b24b-556a-a1bf-49a033a670a6"
Glib_jll = "7746bdde-850d-59dc-9ae8-88ece973131d"
Graphics = "a2bd30eb-e257-5431-a919-1863eab51364"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
adwaita_icon_theme_jll = "b437f822-2cd6-5e08-a15c-8bac984d38ee"
gdk_pixbuf_jll = "da03df04-f53b-5353-a52f-6a8b0620ced0"

[compat]
Expand Down
47 changes: 37 additions & 10 deletions src/Gtk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
module Gtk

# Import binary definitions
using GTK3_jll
using Glib_jll
using gdk_pixbuf_jll
using GTK3_jll, Glib_jll, gdk_pixbuf_jll, adwaita_icon_theme_jll, gdk_pixbuf_jll
using Pkg.Artifacts
const libgdk = libgdk3
const libgtk = libgtk3

Expand Down Expand Up @@ -72,16 +71,44 @@ include("gio.jl")
include("application.jl")

function __init__()
# Set up environment variables so that gdk-pixbuf can find its loaders
if get(ENV, "GDK_PIXBUF_MODULEDIR", "") == ""
ENV["GDK_PIXBUF_MODULEDIR"] = joinpath(
dirname(gdk_pixbuf_jll.libgdkpixbuf_path),
"gdk-pixbuf-2.0",
"2.10.0",
"loaders",
# Set XDG_DATA_DIRS so that Gtk can find its icons and schemas
ENV["XDG_DATA_DIRS"] = join(filter(x -> x != nothing, [
dirname(adwaita_icon_theme_jll.icons_dir),
joinpath(dirname(GTK3_jll.libgdk3_path), "..", "share"),
get(ENV, "XDG_DATA_DIRS", nothing),
]), ":")

# Next, ensure that gdk-pixbuf has its loaders.cache file; we generate a
# MutableArtifacts.toml file that maps in a loaders.cache we dynamically
# generate by running `gdk-pixbuf-query-loaders:`
mutable_artifacts_toml = joinpath(dirname(@__DIR__), "MutableArtifacts.toml")
loaders_cache_name = "gdk-pixbuf-loaders-cache"
loaders_cache_hash = artifact_hash(loaders_cache_name, mutable_artifacts_toml)
if loaders_cache_hash === nothing
# Run gdk-pixbuf-query-loaders, capture output,
loader_cache_contents = gdk_pixbuf_query_loaders() do gpql
withenv("GDK_PIXBUF_MODULEDIR" => gdk_pixbuf_loaders_dir) do
return String(read(`$gpql`))
end
end

# Write cache out to file in new artifact
loaders_cache_hash = create_artifact() do art_dir
open(joinpath(art_dir, "loaders.cache"), "w") do io
write(io, loader_cache_contents)
end
end
bind_artifact!(mutable_artifacts_toml,
loaders_cache_name,
loaders_cache_hash;
force=true
)
end

# Point gdk to our cached loaders
ENV["GDK_PIXBUF_MODULE_FILE"] = joinpath(artifact_path(loaders_cache_hash), "loaders.cache")
ENV["GDK_PIXBUF_MODULEDIR"] = gdk_pixbuf_loaders_dir

GError() do error_check
ccall((:gtk_init_with_args, libgtk), Bool,
(Ptr{Nothing}, Ptr{Nothing}, Ptr{UInt8}, Ptr{Nothing}, Ptr{UInt8}, Ptr{GError}),
Expand Down

0 comments on commit 0b7a864

Please sign in to comment.