mirror of
https://github.com/openwrt/openwrt.git
synced 2026-10-12 06:57:57 +04:00
The GitHub CI spends 10 to 18 minutes rebuilding all host tools in most
"Check Kernel patches" jobs, although the tools container ships them
prebuilt. Before, the "Build tools" step took about 10 seconds.
The refresh sets all stamps to one time given to touch -t, which has a
resolution of a full second, so the fraction is zero. The CI job runs the
refresh about 0.2 seconds after actions/checkout finished, and git writes
the tools directory last. Its files therefore often get a timestamp in
the same second as the stamps, but after the full second. Since
timestamp.pl compares the fraction of a second, these source files are
newer than the stamps and every tool gets cleaned and built again.
Take the time from a freshly created temporary file and set all stamps
to it with touch -r. They still share one timestamp, but it now includes
the fraction and is always later than the checkout.
Fixes: 3cf47c5c17 ("build: compare timestamps with a fraction of a second")
Assisted-by: Claude:claude-opus-5-5
Link: https://github.com/openwrt/openwrt/pull/25626
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
112 lines
3.1 KiB
Bash
Executable File
112 lines
3.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
TOOLS_TAR=""
|
|
HOST_BUILD_DIR=$(pwd)/"build_dir/host"
|
|
HOST_STAGING_DIR_STAMP=$(pwd)/"staging_dir/host/stamp"
|
|
|
|
extract_prebuilt_tar() {
|
|
tar -xf "$1"
|
|
}
|
|
|
|
refresh_prebuilt_tools() {
|
|
if [ ! -d "$HOST_BUILD_DIR" ]; then
|
|
echo "Can't find Host Build Dir "$HOST_BUILD_DIR"" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -d "$HOST_STAGING_DIR_STAMP" ]; then
|
|
echo "Can't find Host Staging Dir Stamp "$HOST_STAGING_DIR_STAMP"" >&2
|
|
exit 1
|
|
fi
|
|
|
|
local ref
|
|
ref=$(mktemp)
|
|
find -H "$HOST_BUILD_DIR" "$HOST_STAGING_DIR_STAMP" \
|
|
-type f -empty -print0 | xargs -0 touch -r "$ref"
|
|
rm -f "$ref"
|
|
|
|
return 0
|
|
}
|
|
|
|
install_prebuilt_tools() {
|
|
extract_prebuilt_tar "$TOOLS_TAR"
|
|
|
|
refresh_prebuilt_tools
|
|
|
|
return 0
|
|
}
|
|
|
|
while [ -n "$1" ]; do
|
|
arg="$1"; shift
|
|
case "$arg" in
|
|
--host-build-dir)
|
|
[ -d "$1" ] || {
|
|
echo "Directory '$1' does not exist." >&2
|
|
exit 1
|
|
}
|
|
HOST_BUILD_DIR="$(cd "$1"; pwd)"; shift
|
|
;;
|
|
|
|
--host-staging-dir-stamp)
|
|
[ -d "$1" ] || {
|
|
echo "Directory '$1' does not exist." >&2
|
|
exit 1
|
|
}
|
|
HOST_STAGING_DIR_STAMP="$(cd "$1"; pwd)"; shift
|
|
;;
|
|
|
|
--tools)
|
|
[ -f "$1" ] || {
|
|
echo "Tools tar file '$1' does not exist." >&2
|
|
exit 1
|
|
}
|
|
TOOLS_TAR="$1"; shift
|
|
install_prebuilt_tools
|
|
|
|
exit $?
|
|
;;
|
|
|
|
--refresh)
|
|
refresh_prebuilt_tools
|
|
|
|
exit $?
|
|
;;
|
|
|
|
-h|--help)
|
|
me="$(basename "$0")"
|
|
echo -e "\nUsage:\n" >&2
|
|
echo -e " $me --host-build-dir {directory}" >&2
|
|
echo -e " Set to refresh timestamp of this build directory" >&2
|
|
echo -e " with --tools." >&2
|
|
echo -e " THIS OPTION MUST BE SET BEFORE --tools." >&2
|
|
echo -e " If not provided the default directory is:" >&2
|
|
echo -e " $(pwd)/build_dir/host\n" >&2
|
|
echo -e " $me --host-staging-dir-stamp {directory}" >&2
|
|
echo -e " Set to refresh staging timestamp present in this" >&2
|
|
echo -e " directory with --tools." >&2
|
|
echo -e " THIS OPTION MUST BE SET BEFORE --tools." >&2
|
|
echo -e " If not provided the default directory is:" >&2
|
|
echo -e " $(pwd)/staging_dir/host/stamp\n" >&2
|
|
echo -e " $me --tools {tar}" >&2
|
|
echo -e " Install the prebuilt tools present in the passed" >&2
|
|
echo -e " tar and prepare them." >&2
|
|
echo -e " To correctly use them it's needed to update the" >&2
|
|
echo -e " timestamp of each tools to skip recompilation.\n" >&2
|
|
echo -e " $me --refresh" >&2
|
|
echo -e " Refresh timestamps of already extracted prebuilt" >&2
|
|
echo -e " tools to correctly use them and skip" >&2
|
|
echo -e " recompilation.\n" >&2
|
|
echo -e " $me --help" >&2
|
|
echo -e " Display this help text and exit.\n\n" >&2
|
|
exit 1
|
|
;;
|
|
|
|
*)
|
|
echo "Unknown argument '$arg'" >&2
|
|
exec $0 --help
|
|
;;
|
|
esac
|
|
done
|
|
|
|
exec $0 --help
|