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

Commit

Permalink
Use Scratch instead of MutableArtifacts.toml (#619)
Browse files Browse the repository at this point in the history
* Use `Scratch` instead of `MutableArtifacts.toml`

Significantly simplify `gdk-pixbuf` querying by using a scratch space to hold mutable state.
Also try to avoid needing to copy around the pixbuf loaders; instead
opting for a more dynamic approach where we invoke
`gdk-pixbuf-query-loaders` multiple times, concatenating the output
appropriately.

* Bump minimum required version to v1.6

* Update .github/workflows/ci.yml

Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com>

Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com>
  • Loading branch information
staticfloat and giordano committed Sep 24, 2022
1 parent 1924a81 commit 7cd80f7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 74 deletions.
3 changes: 1 addition & 2 deletions .drone.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ local Pipeline(os, arch, version) = {
};

[
# Pipeline("linux", "arm", "1.3"),
Pipeline("linux", "arm64", "1.3"),
# Pipeline("linux", "arm", "1.6"),
Pipeline("linux", "arm64", "1.6"),
]
20 changes: 0 additions & 20 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
---
kind: pipeline
name: linux - arm64 - Julia 1.3

platform:
os: linux
arch: arm64

steps:
- name: build
image: julia:1.3
commands:
- apt-get update
- apt-get install -y xvfb xauth
- "xvfb-run julia --project=. --check-bounds=yes --color=yes -e 'using InteractiveUtils; versioninfo(verbose=true); using Pkg; Pkg.build(); Pkg.test(coverage=true)'"

trigger:
branch:
- master

---
kind: pipeline
name: linux - arm64 - Julia 1.6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
julia-version:
- "1.3"
- "1.6"
- "1"
- "nightly"
os:
Expand Down
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ 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"
Scratch = "6c6a2e73-6563-6170-7368-637461726353"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Xorg_xkeyboard_config_jll = "33bec58e-1273-512f-9401-5d533626f822"
Expand All @@ -33,7 +34,7 @@ Xorg_xkeyboard_config_jll = "2.27.0"
adwaita_icon_theme_jll = "3.33.92"
gdk_pixbuf_jll = "2.38.2"
hicolor_icon_theme_jll = "0.17.0"
julia = "1.3"
julia = "1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
84 changes: 34 additions & 50 deletions src/Gtk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ end
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
using Pkg.Artifacts, Scratch
const libgdk = libgdk3
const libgtk = libgtk3
const libgdk_pixbuf = libgdkpixbuf
Expand Down Expand Up @@ -90,62 +90,46 @@ function __init__()
# 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)
loaders_dir_name = "gdk-pixbuf-loaders-dir"
loaders_dir_hash = artifact_hash(loaders_dir_name, mutable_artifacts_toml)

if loaders_cache_hash === nothing
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
cache_dir = @get_scratch!("gdk-pixbuf-cache")
treehash_cache_path = joinpath(cache_dir, "gdk_pixbuf_treehash.cache")
loaders_cache_path = joinpath(cache_dir, "loaders.cache")
gdk_pixbuf_treehash = basename(gdk_pixbuf_jll.artifact_dir)
if !isfile(treehash_cache_path) || read(treehash_cache_path) != gdk_pixbuf_treehash
function query_pixbuf_loaders(dir::String;
extra_env::Vector{Pair{String,String}} = Pair{String,String}[])
gpql = gdk_pixbuf_query_loaders()
return readchomp(addenv(gpql, "GDK_PIXBUF_MODULEDIR" => dir, extra_env...))
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
open(loaders_cache_path, write=true) do io
# Cache builtin gdx-pixbuf modules
write(io, query_pixbuf_loaders(gdk_pixbuf_loaders_dir))
println(io)

# If Librsvg_jll is available, cache that one too
if Librsvg_jll.is_available()
librsvg_module_dir = dirname(Librsvg_jll.libpixbufloader_svg)
write(io, query_pixbuf_loaders(librsvg_module_dir; extra_env = [
JLLWrappers.LIBPATH_env=>Librsvg_jll.LIBPATH[],
]))
println(io)
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

# TODO: I think this is unnecessary
#Sys.iswindows() && chmod(artifact_path(loaders_dir_hash), 0o755; recursive=true)

rm(treehash_cache_path; force=true)
open(treehash_cache_path, write=true) do io
write(io, gdk_pixbuf_treehash)
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"] = Librsvg_jll.is_available() && loaders_dir_hash !== nothing ?
joinpath(artifact_path(loaders_dir_hash), "loaders_dir") :
gdk_pixbuf_loaders_dir
ENV["GDK_PIXBUF_MODULE_FILE"] = loaders_cache_path

# TODO: I think this is unnecessary
#ENV["GDK_PIXBUF_MODULEDIR"] = gdk_pixbuf_loaders_dir

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

0 comments on commit 7cd80f7

Please sign in to comment.