From 34b1a1ab33394ae8660b52ea21c381480a8d0c58 Mon Sep 17 00:00:00 2001 From: Jared Wahlstrand Date: Mon, 17 Jan 2022 03:44:04 -0500 Subject: [PATCH] use Librsvg_jll pixbuf loader (fixes #604) (#605) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * use Librsvg_jll pixbuf loader * don't use join in readdir() for Julia 1.3 * use withenv() instead of addenv() to avoid error for Windows * set permissions on loaders_dir, add pause on Windows * remove the pause just added and try to help Windows find the SVG pixbuf loader * check if libpixbufloader_svg exists, for Windows x86 * Update src/Gtk.jl Use is_available() to check for Librsvg_jll Co-authored-by: Mosè Giordano * attempt to get Windows x86 working * use old code if Librsvg_jll is not available * handle case when MutableArtifacts.toml doesn't have loader_dir_hash * remove a redundant comment, mainly to check if CI fails again Co-authored-by: Mosè Giordano --- Project.toml | 2 ++ src/Gtk.jl | 43 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index 8cb77b42..8dad715d 100644 --- a/Project.toml +++ b/Project.toml @@ -9,7 +9,9 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" GTK3_jll = "77ec8976-b24b-556a-a1bf-49a033a670a6" Glib_jll = "7746bdde-850d-59dc-9ae8-88ece973131d" Graphics = "a2bd30eb-e257-5431-a919-1863eab51364" +JLLWrappers = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" +Librsvg_jll = "925c91fb-5dd6-59dd-8e8c-345e74382d89" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" diff --git a/src/Gtk.jl b/src/Gtk.jl index ad83b5c6..a0cfa205 100644 --- a/src/Gtk.jl +++ b/src/Gtk.jl @@ -7,6 +7,8 @@ end # Import binary definitions using GTK3_jll, Glib_jll, Xorg_xkeyboard_config_jll, gdk_pixbuf_jll, adwaita_icon_theme_jll, hicolor_icon_theme_jll +using Librsvg_jll +using JLLWrappers using Pkg.Artifacts const libgdk = libgdk3 const libgtk = libgtk3 @@ -89,14 +91,41 @@ function __init__() 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) + loaders_dir_name = "gdk-pixbuf-loaders-dir" + loaders_dir_hash = artifact_hash(loaders_dir_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`)) + if Librsvg_jll.is_available() + # 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 + withenv("GDK_PIXBUF_MODULEDIR"=>loaders_dir, JLLWrappers.LIBPATH_env=>Librsvg_jll.LIBPATH[]) do + return String(readchomp(`$gpql`)) + end end - end + bind_artifact!(mutable_artifacts_toml, + loaders_dir_name, + loaders_dir_hash; + force=true + ) + else # just use the gdk_pixbuf directory + 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 # 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 @@ -112,7 +141,9 @@ function __init__() # 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 + ENV["GDK_PIXBUF_MODULEDIR"] = Librsvg_jll.is_available() && loaders_dir_hash !== nothing ? + joinpath(artifact_path(loaders_dir_hash), "loaders_dir") : + gdk_pixbuf_loaders_dir if Sys.islinux() || Sys.isfreebsd() # Needed by xkbcommon: