Skip to content

Instantly share code, notes, and snippets.

@alexlarsson
Last active April 3, 2019 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexlarsson/8912637dd6173591a8dec7c043cfa01d to your computer and use it in GitHub Desktop.
Save alexlarsson/8912637dd6173591a8dec7c043cfa01d to your computer and use it in GitHub Desktop.
fontconfig new cache test
#!/bin/sh
flatpak-builder --ccache --install-deps-from=flathub --user --repo=repo --keep-build-dirs --force-clean builddir org.fontconfig.Sdk.json
#!/bin/bash
# 49, so we run before 50-flatpak.conf
CONF_FILE=/etc/fonts/conf.d/49-flatpak-salted.conf
SALT=$(head -c 300 /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -1)
rm -f $CONF_FILE
cat > $CONF_FILE <<-EOF
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<!-- remove all default dirs, so we can re-add them with a salt. -->
<reset-dirs/>
<dir salt="$SALT">/usr/share/fonts</dir>
</fontconfig>
EOF
# Updating (or adding) the salt invalidates all old config files, so
# lest just remove them here. Otherwise caches for old salts tend to
# stick around as we can't know what path the checksums were against,
# and thus can't tell they should be invalidated.
# This is especially problematic for un-salted caches ones as any they
# can conflict with the host caches.
rm -rf /usr/cache/fontconfig/*
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<!-- This has to be first so it is written while building the runtime, when building apps this is read-only -->
<cachedir>/usr/cache/fontconfig</cachedir>
<!-- Then this is writable while building the app -->
<cachedir>/app/cache/fontconfig</cachedir>
<!-- Allow per-app config (for instance defining a per-app dir with per-app salt) -->
<include ignore_missing="yes">/app/etc/fonts/local.conf</include>
<!-- This defines the remap-dir for /run/host/[user-]fonts in flatpak 1.2.0 and later -->
<include ignore_missing="yes">/run/host/font-dirs.xml</include>
<!-- These are from the host, and expected to be non-salted -->
<dir>/run/host/fonts</dir>
<dir>/run/host/user-fonts</dir>
<!-- This per-user-and-app cache dir is duplicated from the global fonts.conf, because that
includes the conf.d snippets before setting it, and we want it to be ahead
of the /run/host/ cache dirs, to ensure we never accidentally write to these
because earlier versions of flatpak accidentally made /run/host/user-fonts-cache
writable, causing. That is bad because we don't want to write to the global
per-user cache dir, only the per-user-and-app one (each app gets its own xdg dirs). -->
<cachedir prefix="xdg">fontconfig</cachedir>
<cachedir>/run/host/fonts-cache</cachedir>
<cachedir>/run/host/user-fonts-cache</cachedir>
</fontconfig>
{
"build-runtime": true,
"id": "org.fontconfig.Sdk",
"id-platform": "org.fontconfig.Platform",
"default-branch": "test",
"runtime": "org.gnome.Platform",
"sdk": "org.gnome.Sdk",
"runtime-version": "3.30",
"sdk-extensions": ["org.gnome.Sdk.Debug", "org.gnome.Sdk.Locale", "org.gnome.Sdk.Docs"],
"platform-extensions": [ "org.gnome.Platform.Locale"],
"inherit-extensions": [
"org.freedesktop.Platform.GL",
"org.freedesktop.Platform.Timezones",
"org.freedesktop.Platform.GStreamer",
"org.freedesktop.Platform.Icontheme",
"org.gtk.Gtk3theme"
],
"finish-args": [
"--env=GI_TYPELIB_PATH=/app/lib/girepository-1.0",
"--env=GST_PLUGIN_SYSTEM_PATH=/app/lib/gstreamer-1.0:/usr/lib/extensions/gstreamer-1.0:/usr/lib/gstreamer-1.0",
"--env=XDG_DATA_DIRS=/app/share:/usr/share:/usr/share/runtime/share:/run/host/share",
"--sdk=org.fontconfig.Sdk//test",
"--runtime=org.fontconfig.Platform//test"
],
"cleanup": [ "*.la", "*.a"],
"cleanup-commands": [
"echo CLEANUP SDK",
"fc-regenerate-salt",
"fc-cache --force -rs -v"
],
"cleanup-platform-commands": [
"echo CLEANUP PLATFORM",
"fc-regenerate-salt",
"fc-cache --force -rs -v"
],
"modules": [
{
"name": "fontconfig",
"config-opts": [ "--disable-static"],
"post-install": [
"install -m 0644 -p -T fontconfig-flatpak.conf /etc/fonts/conf.d/50-flatpak.conf",
"install -m 0755 -p -T fc-regenerate-salt /usr/bin/fc-regenerate-salt"
],
"sources": [
{
"type": "git",
"url": "https://gitlab.freedesktop.org/tagoh/fontconfig.git",
"branch": "flatpak-rework"
},
{
"type": "file",
"path": "fontconfig-flatpak.conf"
},
{
"type": "file",
"path": "fc-regenerate-salt"
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment