Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions build-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,8 @@ install_r() {
cat > \"\$rscript\" << 'RSCRIPT'
#!/bin/bash
R_BIN=\"${pkg_dest}/bin/R\"
export LD_LIBRARY_PATH=\"${pkg_dest}/lib/R/lib:${pkg_dest}/syslib\${LD_LIBRARY_PATH:+:}\${LD_LIBRARY_PATH}\"
export FONTCONFIG_FILE=\"\${FONTCONFIG_FILE:-${pkg_dest}/fontconfig/fonts.conf}\"
if [ \"\$#\" -eq 0 ] || [ \"\${1#-}\" != \"\$1\" ]; then
exec \"\$R_BIN\" --no-echo --no-restore \"\$@\"
fi
Expand Down Expand Up @@ -659,12 +661,22 @@ RINSTALL
}
EOF

# NsJail mounts /usr but not /etc, so fontconfig cannot find
# /etc/fonts/fonts.conf and every R plot that draws text warns. The
# fonts are fine — they live under /usr/share/fonts. Carry the config
# into the R tree, which is mounted.
if [ -r /etc/fonts/fonts.conf ]; then
mkdir -p ${pkg_dest}/fontconfig
cp /etc/fonts/fonts.conf ${pkg_dest}/fontconfig/fonts.conf
fi

cat > ${pkg_dest}/run << 'EOF'
#!/bin/bash
SCRIPT_DIR=\"\$(cd \"\$(dirname \"\${BASH_SOURCE[0]}\")\" && pwd)\"
export R_HOME=\"\${SCRIPT_DIR}/lib/R\"
export R_LIBS_SITE=\"\${SCRIPT_DIR}/lib/R/site-library\"
export LD_LIBRARY_PATH=\"\${SCRIPT_DIR}/lib/R/lib:\${SCRIPT_DIR}/syslib\${LD_LIBRARY_PATH:+:}\${LD_LIBRARY_PATH}\"
export FONTCONFIG_FILE=\"\${FONTCONFIG_FILE:-\${SCRIPT_DIR}/fontconfig/fonts.conf}\"
exec \"\${SCRIPT_DIR}/bin/Rscript\" \"\$@\"
EOF
chmod +x ${pkg_dest}/run
Expand All @@ -674,6 +686,7 @@ EOF
echo 'R_HOME=${pkg_dest}/lib/R'
echo 'LD_LIBRARY_PATH=${pkg_dest}/lib/R/lib:${pkg_dest}/syslib'
echo 'R_LIBS_SITE=${pkg_dest}/lib/R/site-library'
echo 'FONTCONFIG_FILE=${pkg_dest}/fontconfig/fonts.conf'
} > ${pkg_dest}/.env

echo \$(date +%s)000 > ${pkg_dest}/.package-installed
Expand Down
23 changes: 23 additions & 0 deletions docker/package-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ R_BIN="${R_DEST}/bin/R"
# Same reasoning as the run launcher: package build scripts call this directly
# through R_HOME, where no .env has been applied.
export LD_LIBRARY_PATH="${R_DEST}/lib/R/lib:${R_DEST}/syslib\${LD_LIBRARY_PATH:+:}\${LD_LIBRARY_PATH}"
export FONTCONFIG_FILE="\${FONTCONFIG_FILE:-${R_DEST}/fontconfig/fonts.conf}"
if [ "\$#" -eq 0 ] || [ "\${1#-}" != "\$1" ]; then
# No file argument, or a flag such as -e: hand through unchanged.
exec "\$R_BIN" --no-echo --no-restore "\$@"
Expand Down Expand Up @@ -794,6 +795,26 @@ if [ -n "$R_ARCH" ] && [ "$INSTALL_FAILED" != true ]; then
echo "Carried $(ls -1 "${R_DEST}/syslib" | wc -l) shared libraries into ${R_DEST}/syslib"
rm -f /tmp/r-syslibs.txt

# Fontconfig's config lives at /etc/fonts/fonts.conf, and NsJail mounts
# /usr but NOT /etc — see api/config/sandbox.cfg, whose only /etc entries
# are ld.so.cache and an inline hosts file. So every R plot that draws text
# emitted "Fontconfig error: Cannot load default config file" into the
# caller's stderr. The fonts themselves were never the problem: they are in
# /usr/share/fonts, which IS mounted.
#
# Carried into the R tree rather than fixed by mounting /etc/fonts, because
# /pkgs/r/<version> is already mounted and widening the jail's mount set is
# not worth doing for a config file. The copy is self-sufficient: the dirs
# it names are under /usr, and its only include is conf.d with
# ignore_missing="yes".
if [ -r /etc/fonts/fonts.conf ]; then
mkdir -p "${R_DEST}/fontconfig"
cp /etc/fonts/fonts.conf "${R_DEST}/fontconfig/fonts.conf"
echo "Carried fonts.conf into ${R_DEST}/fontconfig"
else
echo "WARNING: /etc/fonts/fonts.conf not found; R plots will warn about fontconfig"
fi

cat > "$R_DEST/pkg-info.json" << EOF
{
"language": "r",
Expand All @@ -819,6 +840,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export R_HOME="${SCRIPT_DIR}/lib/R"
export R_LIBS_SITE="${SCRIPT_DIR}/lib/R/site-library"
export LD_LIBRARY_PATH="${SCRIPT_DIR}/lib/R/lib:${SCRIPT_DIR}/syslib${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}"
export FONTCONFIG_FILE="${FONTCONFIG_FILE:-${SCRIPT_DIR}/fontconfig/fonts.conf}"
exec "${SCRIPT_DIR}/bin/Rscript" "$@"
EOF
chmod +x "$R_DEST/run"
Expand All @@ -832,6 +854,7 @@ EOF
echo "R_HOME=${R_DEST}/lib/R"
echo "LD_LIBRARY_PATH=${R_DEST}/lib/R/lib:${R_DEST}/syslib"
echo "R_LIBS_SITE=${R_DEST}/lib/R/site-library"
echo "FONTCONFIG_FILE=${R_DEST}/fontconfig/fonts.conf"
} > "$R_DEST/.env"

echo "$(date +%s)000" > "$R_DEST/.package-installed"
Expand Down
Loading