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

Commit

Permalink
use old code if Librsvg_jll is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
jwahlstrand committed Jan 15, 2022
1 parent 679a53b commit b90e7c1
Showing 1 changed file with 37 additions and 24 deletions.
61 changes: 37 additions & 24 deletions src/Gtk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,46 @@ function __init__()
# 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_dir_name = "gdk-pixbuf-loaders-dir"
loaders_dir_hash = artifact_hash(loaders_dir_name, mutable_artifacts_toml)
loaders_cache_name = "gdk-pixbuf-loaders-cache"
loaders_cache_hash = artifact_hash(loaders_cache_name, mutable_artifacts_toml)
if loaders_cache_hash === nothing
# Copy loaders into a directory
loaders_dir_hash = create_artifact() do art_dir
loaders_dir = mkdir(joinpath(art_dir,"loaders_dir"))
pixbuf_loaders = joinpath.(gdk_pixbuf_loaders_dir, readdir(gdk_pixbuf_loaders_dir))
Librsvg_jll.is_available() && push!(pixbuf_loaders, Librsvg_jll.libpixbufloader_svg)
cp.(pixbuf_loaders, joinpath.(loaders_dir, basename.(pixbuf_loaders)))
end
if Librsvg_jll.is_available()
loaders_dir_name = "gdk-pixbuf-loaders-dir"
loaders_dir_hash = artifact_hash(loaders_dir_name, mutable_artifacts_toml)

# Copy loaders into a directory
loaders_dir_hash = create_artifact() do art_dir
loaders_dir = mkdir(joinpath(art_dir,"loaders_dir"))
pixbuf_loaders = joinpath.(gdk_pixbuf_loaders_dir, readdir(gdk_pixbuf_loaders_dir))
push!(pixbuf_loaders, Librsvg_jll.libpixbufloader_svg)
cp.(pixbuf_loaders, joinpath.(loaders_dir, basename.(pixbuf_loaders)))
end

loaders_dir = joinpath(artifact_path(loaders_dir_hash), "loaders_dir")
# Pkg removes "execute" permissions on Windows
Sys.iswindows() && chmod(artifact_path(loaders_dir_hash), 0o755; recursive=true)
# Run gdk-pixbuf-query-loaders, capture output,
loader_cache_contents = gdk_pixbuf_query_loaders() do gpql
libpath = Librsvg_jll.is_available() ? Librsvg_jll.LIBPATH[] : ""
withenv("GDK_PIXBUF_MODULEDIR"=>loaders_dir, JLLWrappers.LIBPATH_env=>libpath) do
return String(readchomp(`$gpql`))
loaders_dir = joinpath(artifact_path(loaders_dir_hash), "loaders_dir")
# Pkg removes "execute" permissions on Windows
Sys.iswindows() && chmod(artifact_path(loaders_dir_hash), 0o755; recursive=true)
# Run gdk-pixbuf-query-loaders, capture output,
loader_cache_contents = gdk_pixbuf_query_loaders() do gpql
withenv("GDK_PIXBUF_MODULEDIR"=>loaders_dir, JLLWrappers.LIBPATH_env=>Librsvg_jll.LIBPATH[]) do
return String(readchomp(`$gpql`))
end
end

bind_artifact!(mutable_artifacts_toml,
loaders_dir_name,
loaders_dir_hash;
force=true
)
else # just use the gdk_pixbuf directory
# 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
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
Expand All @@ -124,16 +140,13 @@ function __init__()
loaders_cache_hash;
force=true
)
bind_artifact!(mutable_artifacts_toml,
loaders_dir_name,
loaders_dir_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"] = joinpath(artifact_path(loaders_dir_hash), "loaders_dir")
ENV["GDK_PIXBUF_MODULEDIR"] = Librsvg_jll.is_available() ?
joinpath(artifact_path(loaders_dir_hash), "loaders_dir") :
gdk_pixbuf_loaders_dir

if Sys.islinux() || Sys.isfreebsd()
# Needed by xkbcommon:
Expand Down

0 comments on commit b90e7c1

Please sign in to comment.