Files
buildroot/support/misc/relocate-sdk.sh
Florian Larysch 63877f9e86 support/misc/relocate-sdk.sh: pre-calculate files in need of relocation
Currently, the relocate-sdk.sh script scans the whole extracted SDK tree
to find instances of paths it needs to replace, which can take a
significant amount of time when the SDK is large, particularly relative
to the number of files that actually need to change.

However, the resulting list only depends on the SDK tarball itself, so
we can calculate it at build time and ship it with the tarball so
relocate-sdk.sh can use it directly.

Testing this on my machine with somewhat IOPS-limited rotating media,
the time goes down from:

$ time ./relocate-sdk.sh
Relocating the buildroot SDK from [...] to [...] ...
./relocate-sdk.sh  5.19s user 26.21s system 9% cpu 5:34.40 total

To:

$ time ./relocate-sdk.sh
Relocating the buildroot SDK from [...] to [...] ...
./relocate-sdk.sh  0.49s user 0.29s system 103% cpu 0.749 total

Signed-off-by: Florian Larysch <fl@n621.de>
Signed-off-by: Arnout Vandecappelle <arnout@rnout.be>
2026-02-04 10:44:01 +01:00

48 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
if [ "$#" -gt 1 ]; then
echo "Usage: $0 [path]"
echo "Run this script to relocate the buildroot SDK to the current location"
echo "If [path] is given, sets the location to [path] (without moving it)"
exit 1
fi
cd "$(dirname "$(readlink -f "$0")")"
if [ "$#" -eq 1 ]; then
NEWPATH="$1"
else
NEWPATH="${PWD}"
fi
LOCFILE="share/buildroot/sdk-location"
if [ ! -r "${LOCFILE}" ]; then
echo "Previous location of the buildroot SDK not found!"
exit 1
fi
OLDPATH="$(cat "${LOCFILE}")"
if [ "${NEWPATH}" = "${OLDPATH}" ]; then
echo "This buildroot SDK has already been relocated!"
exit 0
fi
# Check if the path substitution does work properly, e.g. a tree
# "/a/b/c" copied into "/a/b/c/a/b/c/" would not be allowed.
newpath="$(sed -e "s|${OLDPATH}|${NEWPATH}|g" "${LOCFILE}")"
if [ "${NEWPATH}" != "${newpath}" ]; then
echo "Something went wrong with substituting the path!"
echo "Please choose another location for your SDK!"
exit 1
fi
echo "Relocating the buildroot SDK from ${OLDPATH} to ${NEWPATH} ..."
# Replace the old path with the new one in all text files
while read -r FILE ; do
sed -i "s|${OLDPATH}|${NEWPATH}|g" "${FILE}"
done < share/buildroot/sdk-relocs
# At the very end, we update the location file to not break the
# SDK if this script gets interruted.
sed -i "s|${OLDPATH}|${NEWPATH}|g" ${LOCFILE}