Skip to content

Commit fc2fe7d

Browse files
committed
build: Add prune targets
These reduce the size of the kernel/selftest build directory, but leave artifacts like the vmlinux around.
1 parent af4d1ee commit fc2fe7d

3 files changed

Lines changed: 68 additions & 0 deletions

File tree

build/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ kernel@${1}@${2}: image@${1}@${2}
5353
clean-kernel@${1}@${2}:
5454
@./scripts/clean.sh $$@
5555

56+
prune-kernel@${1}@${2}:
57+
@./scripts/prune.sh $$@
58+
5659
KERNEL += $(if $(filter-out ${ALIAS_DISTROS},${2}), kernel@${1}@${2})
5760
endef
5861

@@ -63,6 +66,9 @@ ppctests@${1}@${2} selftests@${1}@${2}: image@${1}@${2}
6366
clean-selftests@${1}@${2}:
6467
@./scripts/clean.sh $$@
6568

69+
prune-selftests@${1}@${2}:
70+
@./scripts/prune.sh $$@
71+
6672
PPCTESTS += $(if $(filter-out ${ALIAS_DISTROS},${2}), ppctests@${1}@${2})
6773
SELFTESTS += $(if $(filter-out ${ALIAS_DISTROS},${2}), selftests@${1}@${2})
6874
endef

build/scripts/lib.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function get_output_dir()
4141

4242
case "$task" in
4343
kernel) ;&
44+
prune-kernel) ;&
4445
clean-kernel)
4546
if [[ -n "$symlink" ]]; then
4647
echo "$d/latest-kernel"
@@ -53,6 +54,7 @@ function get_output_dir()
5354
;;
5455
ppctests) ;&
5556
selftests) ;&
57+
prune-selftests) ;&
5658
clean-selftests)
5759
if [[ -n "$symlink" ]]; then
5860
echo "$d/latest-selftests"

build/scripts/prune.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
3+
if [[ -z "$1" ]]; then
4+
echo "Usage: $0 <target>" >&2
5+
exit 1
6+
fi
7+
8+
dir="$(dirname "$0")"
9+
script_base="$(realpath "$dir")"
10+
. "$script_base/lib.sh"
11+
12+
IFS=@ read -r task subarch distro version <<< "$1"
13+
14+
output_dir=$(get_output_dir "$script_base" "$subarch" "$distro" "$version" "$task" "$DEFCONFIG" "$TARGETS" "$CLANG")
15+
16+
case "$task" in
17+
prune-kernel)
18+
if [[ ! -e "$output_dir/Makefile" ]]; then
19+
# Assume it's already been pruned
20+
exit 0
21+
fi
22+
23+
echo "Pruning non-outputs in $output_dir"
24+
25+
set -euo pipefail
26+
cd "$output_dir"
27+
mkdir -p "artifacts"
28+
for path in .config vmlinux System.map arch/powerpc/boot/zImage include/config/kernel.release \
29+
arch/powerpc/kernel/asm-offsets.s arch/powerpc/boot/uImage modules.tar.bz2 \
30+
sparse.log log.txt
31+
do
32+
if [[ -e "$path" ]]; then
33+
mv "$path" artifacts/
34+
fi
35+
done
36+
find . -not -path "./artifacts*" -delete
37+
mv artifacts/.config config
38+
mv artifacts/* .
39+
rmdir artifacts
40+
;;
41+
prune-selftests)
42+
if [[ ! -e "$output_dir/kselftest" ]]; then
43+
# Assume it's already been pruned
44+
exit 0
45+
fi
46+
47+
echo "Pruning non-outputs in $output_dir"
48+
49+
set -euo pipefail
50+
cd "$output_dir"
51+
if [[ -d install ]]; then
52+
mv install selftests
53+
tar -cJf selftests.tar.xz selftests
54+
fi
55+
find . -not -path "./selftests.tar.xz" -delete
56+
;;
57+
*)
58+
(set -x ; rm -rf "$output_dir")
59+
;;
60+
esac

0 commit comments

Comments
 (0)