@@ -538,6 +538,44 @@ emit_depmod_pkgdata() {
PACKAGEFUNCS += "emit_depmod_pkgdata"
+# Print, relative to ${S}, the source files the target compiler read, from
+# kbuild's .cmd files. The intermediate lists are left in ${T}.
+kernel_source_manifest() {
+ (
+ cd ${B}
+ # The .cmd files hold millions of lines: a UTF-8 locale is ~40x slower
+ export LC_ALL=C
+
+ cmds=${T}/kernel-source-cmds
+ paths=${T}/kernel-source-paths
+
+ # The .cmd files of objects built with the target compiler, matching:
+ # savedcmd_kernel/fork.o := x86_64-poky-linux-gcc -fuse-ld=bfd ...
+ # savedcmd_kernel/fork.o := ccache x86_64-poky-linux-gcc ...
+ target_cc="^savedcmd_[^ ]+ := ([^ ]*ccache )?${HOST_PREFIX}"
+ find . -name '.*.cmd' -exec grep -l -E "$target_cc" {} + > $cmds
+
+ # Every path under ${S} they name, matching (dedup before the regex):
+ # source_kernel/fork.o := ${S}/kernel/fork.c
+ # ${S}/include/linux/types.h
+ # ... -I${S}/include -include ${S}/include/linux/kconfig.h ...
+ # Directories and other non-files are dropped below.
+ xargs -r grep -hF "${S}/" < $cmds | sort -u | \
+ grep -o "${S}/[^ ]*" | sort -u > $paths
+
+ # Normalized relative to ${S}, for example:
+ # ${S}/arch/x86/boot/compressed/../../../../lib/ctype.c -> lib/ctype.c
+ # and kept only if they are regular files inside ${S}.
+ xargs -r realpath -m --relative-to=${S} < $paths | \
+ grep -v '^\.\./' | sort -u | \
+ while read f; do
+ if [ -f "${S}/$f" ]; then
+ echo "$f"
+ fi
+ done
+ )
+}
+
do_shared_workdir[cleandirs] += " ${STAGING_KERNEL_BUILDDIR}"
do_shared_workdir () {
cd ${B}
@@ -605,6 +643,9 @@ do_shared_workdir () {
fi
fi
+ # The source files this kernel was built from, for kernel-devsrc
+ kernel_source_manifest > $kerneldir/kernel-source-files
+
# When building with CONFIG_MODVERSIONS=y and CONFIG_RANDSTRUCT=y we need
# to copy the build assets generated for the randstruct seed to
# STAGING_KERNEL_BUILDDIR, otherwise the out-of-tree modules build will