# the wrong result when systemd is being built as a meson subproject
project_source_root = meson.current_source_dir()
project_build_root = meson.current_build_dir()
-relative_source_path = run_command('realpath',
- '--relative-to=@0@'.format(project_build_root),
+relative_path_sh = find_program('tools/relative-path.sh')
+relative_source_path = run_command(relative_path_sh,
+ '@0@'.format(project_build_root),
project_source_root,
check : true).stdout().strip()
conf.set_quoted('RELATIVE_SOURCE_PATH', relative_source_path)
fi
# The calling test.sh scripts have TEST_BASE_DIR set via their Makefile, but we don't need them to provide it
-TEST_BASE_DIR=${TEST_BASE_DIR:-$(realpath "$(dirname "${BASH_SOURCE[0]}")")}
-TEST_UNITS_DIR="$(realpath "$TEST_BASE_DIR/units")"
-SOURCE_DIR=$(realpath "$TEST_BASE_DIR/..")
+TEST_BASE_DIR=${TEST_BASE_DIR:-$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")}
+TEST_UNITS_DIR="$(readlink -f "$TEST_BASE_DIR/units")"
+SOURCE_DIR=$(readlink -f "$TEST_BASE_DIR/..")
# These variables are used by test scripts
export TEST_BASE_DIR TEST_UNITS_DIR SOURCE_DIR
echo "ERROR: test-functions must be sourced from one of the TEST-*/test.sh scripts" >&2
exit 1
fi
-TESTNAME="$(basename "$(dirname "$(realpath "$TESTFILE")")")"
+TESTNAME="$(basename "$(dirname "$(readlink -f "$TESTFILE")")")"
WORKDIR="/var/tmp/systemd-tests"
if get_bool "${NO_BUILD:=}"; then
pkill
ps
readlink
- realpath
rev
rm
rmdir
fi
if [ -e "${IMAGE_PRIVATE:?}" ]; then
- echo "Reusing existing image $IMAGE_PRIVATE → $(realpath "$IMAGE_PRIVATE")"
+ echo "Reusing existing image $IMAGE_PRIVATE → $(readlink -f "$IMAGE_PRIVATE")"
mount_initdir
else
if [ ! -e "${IMAGE_PUBLIC:?}" ]; then
IMAGE_PUBLIC="${image_old}"
fi
if [ "${IMAGE_NAME:?}" != "default" ] && ! get_bool "${TEST_FORCE_NEWIMAGE}"; then
- cp -v "$(realpath "${IMAGESTATEDIR}/default.img")" "$IMAGE_PUBLIC"
+ cp -v "$(readlink -f "${IMAGESTATEDIR}/default.img")" "$IMAGE_PUBLIC"
fi
fi
local hook_defined
declare -f -F test_append_files >/dev/null && hook_defined=yes || hook_defined=no
- echo "Reusing existing cached image $IMAGE_PUBLIC → $(realpath "$IMAGE_PUBLIC")"
+ echo "Reusing existing cached image $IMAGE_PUBLIC → $(readlink -f "$IMAGE_PUBLIC")"
if get_bool "$TEST_PARALLELIZE" || get_bool "$hook_defined"; then
- cp -v -- "$(realpath "$IMAGE_PUBLIC")" "$IMAGE_PRIVATE"
+ cp -v -- "$(readlink -f "$IMAGE_PUBLIC")" "$IMAGE_PRIVATE"
else
- ln -sv -- "$(realpath "$IMAGE_PUBLIC")" "$IMAGE_PRIVATE"
+ ln -sv -- "$(readlink -f "$IMAGE_PUBLIC")" "$IMAGE_PRIVATE"
fi
mount_initdir
exit 1
fi
-binary=$(realpath "${1}")
+binary=$(readlink -f "${1}")
if [[ "${1}" =~ systemd-boot([[:alnum:]]+).efi ]]; then
target="systemd-boot"
- symbols=$(realpath "${1%efi}elf")
+ symbols=$(readlink -f "${1%efi}elf")
elif [[ "${1}" =~ linux([[:alnum:]]+).efi.stub ]]; then
target="systemd-stub"
- symbols=$(realpath "${1%efi.stub}elf.stub")
+ symbols=$(readlink -f "${1%efi.stub}elf.stub")
else
echo "Cannot detect EFI binary '${1}'."
exit 1
# we look for subdirectories of the parent directory that look like ninja build dirs.
if [ -n "${BUILD_DIR:=}" ]; then
- realpath "$BUILD_DIR"
+ readlink -f "$BUILD_DIR"
exit 0
fi
-root="$(dirname "$(realpath "$0")")"
+root="$(dirname "$(readlink -f "$0")")"
found=
for i in "$root"/../*/build.ninja; do
exit 1
fi
-realpath "$found"
+readlink -f "$found"
--- /dev/null
+#!/bin/sh
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -eu
+
+# relative-path.sh <RELATIVE_TO> <PATH>
+#
+# Print resolved <PATH> relative to <RELATIVE_TO>
+
+full_path=$(readlink -f ${2})/
+relative_path=$(readlink -f ${1})/
+
+while [ -n "${full_path}" -a \
+ -n "${relative_path}" -a \
+ "${full_path%%/*}" = "${relative_path%%/*}" ]; do
+ full_path=${full_path#*/}
+ relative_path=${relative_path#*/}
+done
+
+dots=""
+
+full_path=${full_path%/}
+relative_path=${relative_path%/}
+
+relative_path=${relative_path:+/$relative_path}
+while [ -n "${relative_path}" ]; do
+ dots="../$dots"
+ relative_path=${relative_path%/*}
+done
+dots=${dots%/}
+if [ -z "$full_path" ]; then
+ echo ${dots}
+else
+ echo ${dots}/${full_path}
+fi