librsvg source for verification 2026-05-22

This commit is contained in:
2026-05-22 16:45:08 +08:00
commit 75af7ac721
2138 changed files with 161177 additions and 0 deletions

240
tools/docker/README.md Normal file
View File

@@ -0,0 +1,240 @@
# Librsvg Docker Tests
Run the librsvg test suite inside a docker container. The Librsvg CI runs on
opensuse, so this is a simpler way to run the test suite locally on the same
packages that are used by the Gitlab integration.
Docker requires root for nearly all of its commands so the script will ask for
root.
## Usage
```text
This tool lets you run Librsvg's test suite under a couple different docker containers for testing, it requires sudo privleges, which it will ask for in the terminal (this is by the docker commands, which require it)
Use -d [DIRECTORY] pointing at your librsvg Directory
Use -s [SYSTEM] to determine what docker container to use (Fedora, OpenSUSE, Debian)
Use -h to return this Help
Use -i to have it Interactively pause periodically to check output (the cleanup scripts is always interactive unless -y is passed)
Use -p to recoPy the librsvg library folder to the tmp directory, removing everything that is there, useful for cleaning the cargo cache
Use -r to Rebuild the build dependencies docker image forcefully
Use -t to specify a Temporary directory (default: /tmp/librsvg)
Use -y to answer Yes to any prompts (This currently only includes the cleanup scripts)
Use -c to Cleanup ALL related docker images (this will not run the test suite)
```
### Example
If the librsvg folder is in your home directory, run this from your home
directory:
```bash
~/librsvg/tools/docker/docker-test.sh -d ~/librsvg -s opensuse -i
```
This will run it pointing at `/home/Username/librsvg` (-d) with opensuse
tumbleweed docker image (-s), and interactive (-i), meaning it pauses and has
the user input a keystroke before continuing, useful for debugging or catching
typos.
The first run will take some time as Docker downloads and installs the system,
updates the packages, and installs the build requirements, but it's set up so
that it won't re-download the system image each time, which takes more disk
space but saves on bandwidth.
After the tests run, the links to rendered files in your terminal (in the case
that there are errors) will point to the `/tmp/librsvg` directory, so in some
terminals these links can be clicked on to view the files, otherwise the build
is found in that folder, and can be accessed from the host system.
What I use, from the librsvg directory:
```sh
./tools/docker/docker-test.sh -s opensuse
```
This passes through the current directory (in this case the librsvg folder, as
cloned from git) and runs the test suite in OpenSUSE
### Cleanup
To do a full cleanup of the docker images:
```sh
./docker-test.sh -c
```
This requires user input.
This asks if it should also clear out the tmp directory passed to it, or the
default one. It checks if `/` is passed to it, so it shouldn't delete your
system. If you answer "no" to clearing out the tmp directory, those files will
not be deleted.
Dangerous: pass -y if using this where user input cannot be provided, but it
will delete **all** docker images and the contents of `/tmp/librsvg` (if `-t` is
not passed, otherwise that directory) without warning. It will not touch the
actual librsvg library directory.
### Helpful Docker Commands
```sh
docker image prune
docker container prune
```
This removes any dangling (not attached to an tagged image) docker images and
containers. I would recommend running it once in a while, or you may end up with
100gb of docker containers like me, don't be like me. (disclaimer: I have also
been testing all of this so there's been a lot of mishaps and learning)
This tool should use ~3gb of disk space for running the tests with the opensuse
image alone. If all 3 systems are tested, the disk usage goes up to ~9gb
See your disk usage with:
```sh
docker system df
```
### I want to add more OS's to test, how do I do that?
To add a new OS clone one of the `tools/docker/librsvg-base` folders, renaming
it to the OS you wish to add, eg. If I wanted to test Alpine, I would rename the
folder to "alpine" all lower case, one word, to make things easy.
Then, go to
[Docker Hub](https://hub.docker.com/search?q=&type=image&category=os) and find
the OS you wish to add along with the version tag for it, for the alpine example
that's `alpine:latest` and put that in the `FROM` portion of the Dockerfile.
LABEL can remain how it is.
Finally `RUN` needs to be filled in with the package manager command to install
the dependencies to build Librsvg. See [COMPILING.md](../../COMPILING.md) for
build dependencies, the other Dockerfiles can help here. Essentially it's just
looking up what the packages are called on your OS of choice.
Once you have that out of he way, [docker-test.sh](docker-test.sh) will need a
couple edits to be able to build. First, inside the `check_system` function copy
one of the `elif [[ $SYSTEM == "" ]]` and put it before the `else` at the bottom
of that function. Add your system name inside there, copying the style of inside
of the other `elif` statements.
Then, in `cleanup` copy one of the `SYS= ... clean_base_image` lines and change
the `SYS` to your OS.
Finally go to `clean_distro_image` and copy one of the `docker rmi --force`
lines, filling in your OS at the end.
You're done! Now running the script with `./docker-test.sh -s youros` will use
your OS, setting the docker images, base image, and everything else correctly!
## How does this tool work?
See the docker-test.sh file for the script itself, below is the architecture of
the script. The dockerfiles in the debian/fedora/opensuse folders have the build
dependency install commands that are used to build each of the base images.
```text
┌─────────────────────────────────────────────────────┐
|main │
| This function runs the following functions one at a |
| time: |
│ check_docker: This makes sure docker is installed |
| cleanup │
│ check_dir │
│ check_system │
│ build_base_system │
│ prepare_librsvg │
│ run_docker │
| It's found at the bottom of the script, and pauses |
| after everything finishes if -i is passed |
└─────────────────────────────────────────────────────┘
Cleanup │
┌───────────────────────┐ ┌──────────────────────────────────────┐
│cleanup │ ┌─˃│clean_base_image │
│ If -c was passed │ │ │ Delete librsvg-$SYS-base docker image│
│ Confirm with user │ │ └──────────────────────────────────────┘
│ Set SYS to each system├──┘ ┌────────────────────────────────┐ ˄
│ Confirm with user ────┼────˃|clean_distro_image │ |
│ Confirm with user ────┼──┐ | Delete all distro docker images│ |
└───────────────────────┘ │ │ Ie. debian, opensuse/tumbleweed│ |
Check path | │ └────────────────────────────────┘ |
˅ │ ┌─────────────────────────────┐ |
┌───────────────────────┐ └─˃│clean_tmp_dir │ |
│check_dir │ │ Check if $TMPDIR is "/" │ |
│ checks if $LIBDIR is | │ Delete tmp directory on host│ |
| passed with -d, if not| │ default: /tmp/librsvg │ |
| defaults to current | │ specity with -t │ |
| directory, then it | └─────────────────────────────┘ |
| checks for trailing / | ˄ |
│ in library directory, │ | |
│ if it doesn't exist │ | |
│ then it appends one. │ | |
│ This makes sure the │ | |
│ later commands don't | | |
| target the wrong │ | |
| directory. | | |
└───────────────────────┘ | |
Now the system │ | |
˅ | |
┌────────────────────────────────────────┐ | |
│check_system │ | |
│ this parses a few common spellings of │ | |
│ OpenSUSE, Fedora, and Debian │ | |
│ to set the $SYS variable to the correct│ | |
│ OS image. It's convenient to not care │ | |
│ about the difference between "OpenSUSE"│ | |
│ and "opensuse", there's probably a │ | |
| better way to do this | | |
└────────────────────────────────────────┘ | |
Build time! │ | |
˅ | |
┌────────────────────────────────────────┐ | |
│build_base_system | \ |
│ Builds the base docker image: if -r ───┼───────────────┼───────┘
│ then image is rebuilt. If -r is not │ /
│ passed, then Docker reruns the │ |
│ Dockerfile command which updates the │ |
│ existing image using dnf/zypper/apt │ |
└────────────────────────────────────────┘ |
Preparations │ |
˅ |
┌──────────────────────────────────────────────────────┐|
│prepare_librsvg ||
| If -p ───────────────────────────────────────────────┼┘
│ Then creates $TMPDIR if it doesn't exist. |
| Prepares librsvg, copying it to $TMPDIR, using Rsync │
│ to exclude the git and target folders. │
│ It then runs autogen in $TMPDIR to prepare for │
│ building │
└──────────────────────────────────────────────────────┘
Run Docker |
˅
┌──────────────────────────────────────────────────────┐
│run_docker |
│ Runs the docker container with this command: |
│ sudo docker run --name librsvg-$SYS-test \ |
| -v $TMPDIR:$TMPDIR -w $TMPDIR -t --rm \ |
| librsvg/librsvg-$SYS-base cargo test |
| |
| --name runs the docker container with name │
│ librsvg-$SYS-test ex: librsvg-opensuse-test │
| |
│ -v $TMPDIR:$TMPDIR passes through $TMPDIR on the host│
│ to $TMPDIR inside the container ex: /tmp/librsvg │
| |
│ -w $TMPDIR sets the working directory to $TMPDIR │
| inside the container |
| |
| -t binds the container's console to the current one |
| |
| -rm sets the generated image to self-destruct after |
| all processes exit |
| |
| cargo test runs cargo test inside the container |
└──────────────────────────────────────────────────────┘
```

357
tools/docker/docker-test.sh Executable file
View File

@@ -0,0 +1,357 @@
#!/bin/bash
# Here is all of the variables used,
# changed by passing through command line arguments
RECOPY=false
INT=false
SYS="no"
REBUILD=false
DIR=no
TMPDIR=/tmp/librsvg
YES=false
CLEANUP=false
RMDISTROIMG=false
RMSYSTEMIMG=false
RMTMP=false
function usage {
echo "This tool lets you run Librsvg's test suite under a couple different"
echo "docker containers for testing, it requires sudo privleges (for the docker commands)"
echo "Use -d [DIRECTORY] pointing at your librsvg Directory"
echo "Use -s [SYSTEM] to determine what docker container to use (Fedora, OpenSUSE, Debian)"
echo "Use -h to return this Help"
echo "Use -i to have it Interactively pause periodically to check output (the cleanup scripts is always interactive unless -y is passed)"
echo "Use -p to recoPy the librsvg library folder to the tmp directory, removing everything that is there, useful for cleaning the cargo cache"
echo "Use -r to Rebuild the build dependencies docker image forcefully"
echo "Use -t to specify a Temporary directory (default: /tmp/librsvg)"
echo "Use -y to answer Yes to any prompts (This currently only includes the cleanup scripts)"
echo "Use -c to Cleanup ALL related docker images (this will not run the test suite)"
}
# Confirm with user to remove Librsvg system docker image
function confirm {
if [[ $YES == false ]]
then
echo
read -p $'Would you like to remove the librsvg docker image with the build dependencies?\x0a(it will take a while to rebuild if removed)\x0aY/N: ' -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
RMSYSTEMIMG=true
else
RMSYSTEMIMG=false
fi
fi
}
# Confirm with user to remove $TMPDIR
function confirm_rm_dir {
if [[ $YES == false ]]
then
echo
read -p $'Would you like to remove the librsvg files from the tmp directory?\x0aY/N: ' -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
RMTMP=true
else
RMTMP=false
fi
fi
}
# Confirm with user to remove distro docker images
function confirm_rm_distro {
if [[ $YES == false ]]
then
echo
read -p $'Would you like to remove the base docker system images ie. opensuse?\x0a(do this if you dont plan to build librsvg with this tool in the future, otherwise keep them, it takes a while to build)\x0aY/N: ' -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
RMDISTROIMG=true
else
RMDISTROIMG=false
fi
fi
}
# Removes the designated base system docker image
function clean_base_image {
echo "removing system image librsvg-base-$SYS"
sudo docker rmi --force librsvg/librsvg-$SYS-base
}
# Removes distro docker images
function clean_distro_image {
echo "removing base system images"
sudo docker rmi --force debian
sudo docker rmi --force opensuse/tumbleweed
sudo docker rmi --force fedora
}
# Clean the temporary directory
function clean_tmp_dir {
if [[ "$TMPDIR" == "/" ]]
then
echo "Tried to delete root, exiting"
exit 1
fi
if [[ ! -d "$TMPDIR" ]]
then
echo "$TMPDIR does not exist, exiting"
exit 0
fi
echo "This requires sudo because the build is done with the docker image, so build files cannot be removed without it"
echo
if [[ $INT == true ]]
then
read -p "Pausing, press any key to continue, you may be asked for admin password in the next step" -n1 -s
echo
fi
sudo rm -rf $TMPDIR
}
# Cleanup the various directories and docker images
function cleanup {
if [[ $CLEANUP == true ]]
then
confirm
if [ $RMSYSTEMIMG == "true" ]
then
SYS="opensuse"
clean_base_image
SYS="fedora"
clean_base_image
SYS="debian"
clean_base_image
fi
confirm_rm_distro
if [ $RMDISTROIMG == "true" ]
then
clean_distro_image
fi
confirm_rm_dir
if [ $RMTMP == "true" ]
then
clean_tmp_dir
fi
exit 0
fi
}
# Check for a docker installation, the script will not continue if Docker is not present.
function check_docker {
if command -v docker
then
echo "Docker found, proceeding"
else
echo "No Docker, please install Docker, exiting"
exit 1
fi
}
# Check the library directory, defaulting to the current working directory if none is provided
function check_dir {
echo "Checking if $LIBDIR exists"
if [[ ! -d "$LIBDIR" ]]
then
echo "Library directory: '$LIBDIR' does not exist or isn't set, defaulting to current working directory"
echo
LIBDIR=$PWD
fi
if [[ $LIBDIR == */ ]]
then
echo "Directory is good!"
else
echo "Directory missing last /, adding"
echo
LIBDIR+="/"
fi
DIR=$PWD
}
# Manually correct for a few different spellings of supported distros
function check_system {
echo "Checking what system $SYSTEM is"
if [[ $SYSTEM == "fedora" ]]
then
echo "Fedora"
SYS="fedora"
elif [[ $SYSTEM == "Fedora" ]]
then
echo "Fedora"
SYS="fedora"
elif [[ $SYSTEM == "opensuse" ]]
then
echo "OpenSUSE"
SYS="opensuse"
elif [[ $SYSTEM == "OpenSUSE" ]]
then
echo "OpenSUSE"
SYS="opensuse"
elif [[ $SYSTEM == "Debian" ]]
then
echo "Debian"
SYS="debian"
elif [[ $SYSTEM == "debian" ]]
then
echo "Debian"
SYS="debian"
else
echo "Wrong system selected, must be fedora, opensuse, or debian"
echo $flag
echo
exit 2
fi
}
# Build the base image, this contains the dependencies for librsvg to be built, and is used to build the system image
function build_base_image {
if [[ $REBUILD == true ]]
then
if [[ $INT == true ]]
then
read -p "Rebuilding the Librsvg build dependencies docker container, this will take a moment" -n1 -s
echo
fi
clean_base_image
sudo docker build -t librsvg/librsvg-$SYS-base -f tools/docker/librsvg-base/$SYS/Dockerfile tools/docker/librsvg-base/$SYS/.
fi
if [[ $INT == true ]]
then
read -p "Building the Librsvg build dependencies docker container, this will take a moment, press any key to continue" -n1 -s
echo
fi
sudo docker build -t librsvg/librsvg-$SYS-base -f tools/docker/librsvg-base/$SYS/Dockerfile tools/docker/librsvg-base/$SYS/.
}
#Package librsvg for inclusion in the Docker image
function prepare_librsvg {
echo "Preparing Librsvg"
if [[ $RECOPY == false ]]
then
if [[ $INT == true ]]
then
read -p "Making a copy, then packaging Librsvg, press any key to continue" -n1 -s
echo
fi
mkdir $TMPDIR
echo "Copying librsvg to $TMPDIR"
echo
rsync -av --exclude '.git' --exclude 'target' $LIBDIR/ $TMPDIR/
#Uncomment this line if your distro doesn't have rsync, it'll make a lot of text when copying the git folder, but works
#cp -r $LIBDIR/. $TMPDIR
cd $TMPDIR
if [[ $INT == true ]]
then
read -p "Running autogen to prepare for building in $TMPDIR, press any key to continue" -n1 -s
echo
fi
#Run autogen, this prepares librsvg for building
./autogen.sh
else
echo "Recopying Librsvg"
echo
if [[ ! -d "$TMPDIR" ]]
then
echo "$TMPDIR does not exist, creating"
mkdir $TMPDIR
else
echo "Erasing $TMPDIR and recreating"
clean_tmp_dir
mkdir $TMPDIR
fi
echo "Copying librsvg to $TMPDIR"
rsync -av --exclude '.git' --exclude 'target' $LIBDIR/ $TMPDIR/
#Uncomment this line if your distro doesn't have rsync, it'll make a lot of text when copying the git folder, but works
#cp -r $LIBDIR/. $TMPDIR
cd $TMPDIR
if [[ $INT == true ]]
then
read -p "Running autogen to prepare for building in $TMPDIR, then running make clean, press any key to continue" -n1 -s
echo
fi
#Run autogen, this prepares librsvg for building
./autogen.sh
fi
}
# Runs the built docker image, this runs cargo check automatically attached to the console
function run_docker {
sudo docker run --name librsvg-$SYS-test -v $TMPDIR:$TMPDIR -w $TMPDIR -t --rm librsvg/librsvg-$SYS-base cargo test
}
# Get the command line arguments
if [[ ${#} -eq 0 ]]; then
usage
exit 1
fi
# Switch through the command line arguments
while getopts "d:s:irpt:ch" flag; do
case "${flag}" in
d) LIBDIR=${OPTARG};;
s) SYSTEM=${OPTARG};;
i) INT=true;;
r) REBUILD=true; echo "Rebuilding";;
p) RECOPY=true; echo "Recopying";;
t) TMPDIR=${OPTARG};;
c) CLEANUP=true;;
h) usage; exit 0;;
y) YES=true;;
?) usage; echo "Error: $flag"; exit 1;;
esac
done
# Runs the script
function main {
check_docker
cleanup
check_dir
check_system
build_base_image
prepare_librsvg
run_docker
if [[ $INT == true ]]
then
read -p "Tests finished, press any key to exit" -n1 -s
exit 0
fi
echo "Tests finished, exiting"
exit 0
}
main

View File

@@ -0,0 +1,6 @@
FROM debian:testing
LABEL MAINTAINER=librsvg
RUN apt-get update && apt-get upgrade -y && apt-get install -y gcc make rustc cargo \
automake autoconf libtool gi-docgen git \
libgdk-pixbuf2.0-dev libgirepository1.0-dev \
libxml2-dev libcairo2-dev libpango1.0-dev

View File

@@ -0,0 +1,6 @@
FROM fedora
LABEL MAINTAINER=librsvg
RUN dnf update -y && dnf install -y gcc rust rust-std-static cargo make \
automake autoconf libtool gi-docgen git redhat-rpm-config \
gdk-pixbuf2-devel gobject-introspection-devel \
libxml2-devel cairo-devel cairo-gobject-devel pango-devel

View File

@@ -0,0 +1,6 @@
FROM opensuse/tumbleweed
LABEL MAINTAINER=librsvg
RUN zypper refresh && zypper install -y gcc rust rust-std cargo make \
automake autoconf libtool python3-gi-docgen python38-docutils git \
gdk-pixbuf-devel gobject-introspection-devel \
libxml2-devel cairo-devel pango-devel

3
tools/lsan.supp Normal file
View File

@@ -0,0 +1,3 @@
# See ../devel-docs/memory_leaks.rst for more info
leak:FcPatternObjectInsertElt