fontconfig/test/run-test-map.sh

108 lines
3.1 KiB
Bash
Raw Normal View History

Replace UUID file mechanism with per-directory 'map' attribute [v2] The UUID files would be placed in each font directory to provide the unique cache name, independent of path, for that directory. The UUID files are undesireable for a couple of reasons: 1) They must be placed in the font directories to be useful. This requires modifying the font directories themselves, introducing potential visible timestamp changes when running multiple applications, and makes the cache processing inconsistent between applications with permission to write to the font directories and applications without such permission. 2) The UUID contents were generated randomly, which makes the font cache not reproducible across multiple runs. One proposed fix for 2) is to make the UUID dependent on the font directory path, but once we do that, we can simply use the font directory path itself as the key as the original MD5-based font cache naming mechanism did. The goal of the UUID file mechanism was to fix startup time of flatpaks; as the font path names inside the flatpak did not match the font path names in the base system, the font cache would need to be reconstructed the first time the flatpak was launched. The new mechanism for doing this is to allow each '<dir>' element in the configuration include a 'map' attribute. When looking for a cache file for a particular directory, if the directory name starts with the contents of the <dir> element, that portion of the name will be replaced with the value of the 'map' attribute. Outside of the flatpak, nothing need change -- fontconfig will build cache files using real directory names. Inside the flatpak, the custom fonts.conf file will now include mappings such as this: <dir map="/usr/share/fonts">/run/host/fonts</dir> When scanning the directory /run/host/fonts/ttf, fontconfig will use the name /usr/share/fonts/ttf as the source for building the cache file name. The existing FC_FILE replacement code used for the UUID-based implementation continues to correctly adapt font path names seen by applications. v2: Leave FcDirCacheCreateUUID stub around to avoid removing public API function. Document 'map' attribute of <dir> element in fontconfig-user.sgml Suggested-by: Akira TAGOH <akira@tagoh.org> Signed-off-by: Keith Packard <keithp@keithp.com>
2018-10-30 00:39:05 +01:00
#!/bin/bash
# fontconfig/test/run-test-cache-map.sh
#
# Copyright © 2018 Keith Packard
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that copyright
# notice and this permission notice appear in supporting documentation, and
# that the name of the copyright holders not be used in advertising or
# publicity pertaining to distribution of the software without specific,
# written prior permission. The copyright holders make no representations
# about the suitability of this software for any purpose. It is provided "as
# is" without express or implied warranty.
#
# THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
# EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
# OF THIS SOFTWARE.
#
case "$OSTYPE" in
msys ) MyPWD=`pwd -W` ;; # On Msys/MinGW, returns a MS Windows style path.
* ) MyPWD=`pwd` ;; # On any other platforms, returns a Unix style path.
esac
TESTDIR=${srcdir-"$MyPWD"}
BUILDTESTDIR=${builddir-"$MyPWD"}
FONTDIRA="$MyPWD"/fontsa
FONTDIRB="$MyPWD"/fontsb
CACHEDIR="$MyPWD"/cache.dir
EXPECTEDIN=${EXPECTEDIN-"out-map.expected.in"}
EXPECTEDA="out-map-a.expected"
EXPECTEDB="out-map-b.expected"
EXPECTED="out-map.expected"
FCLIST=../fc-list/fc-list$EXEEXT
FCCACHE=../fc-cache/fc-cache$EXEEXT
which bwrap > /dev/null 2>&1
if [ $? -eq 0 ]; then
BWRAP=`which bwrap`
fi
FONT1=$TESTDIR/4x6.pcf
FONT2=$TESTDIR/8x16.pcf
check () {
$FCLIST - file family pixelsize | sort > out
echo "=" >> out
$FCLIST - file family pixelsize | sort >> out
echo "=" >> out
$FCLIST - file family pixelsize | sort >> out
tr -d '\015' <out >out.tmp; mv out.tmp out
if cmp out $BUILDTESTDIR/$EXPECTED > /dev/null ; then : ; else
echo "*** Test failed: $TEST"
echo "*** output is in 'out', expected output in '$EXPECTED'"
exit 1
fi
rm -f out
}
prep() {
rm -rf $CACHEDIR
rm -rf $FONTDIRA $FONTDIRB
mkdir $FONTDIRA
mkdir $CACHEDIR
}
dotest () {
TEST=$1
test x$VERBOSE = x || echo Running: $TEST
}
sed "s!@FONTDIR@!$FONTDIRA!
s!@MAP@!!
s!@CACHEDIR@!$CACHEDIR!" < $TESTDIR/fonts.conf.in > fonts-a.conf
sed "s!@FONTDIR@!$FONTDIRB!
s!@MAP@!map="'"'"$FONTDIRA"'"'"!
s!@CACHEDIR@!$CACHEDIR!" < $TESTDIR/fonts.conf.in > fonts-b.conf
sed "s!@FONTDIR@!$FONTDIRA!" < $EXPECTEDIN > $EXPECTEDA
sed "s!@FONTDIR@!$FONTDIRB!" < $EXPECTEDIN > $EXPECTEDB
FONTCONFIG_FILE="$MyPWD"/fonts-a.conf
export FONTCONFIG_FILE
dotest "Basic check"
prep
cp $FONT1 $FONT2 $FONTDIRA
cp $EXPECTEDA $EXPECTED
$FCCACHE $FONTDIRA
check
dotest "mapped check"
prep
cp $FONT1 $FONT2 $FONTDIRA
cp $EXPECTEDB $EXPECTED
$FCCACHE $FONTDIRA
mv $FONTDIRA $FONTDIRB
export FONTCONFIG_FILE="$MyPWD"/fonts-b.conf
check