Skip to content

Commit aa7d233

Browse files
committed
kbuild: give up untracked files for source package builds
When the source tree is dirty and contains untracked files, package builds may fail, for example, when a broken symlink exists, a file path contains whitespaces, etc. Since commit 05e96e9 ("kbuild: use git-archive for source package creation"), the source tarball only contains committed files because it is created by 'git archive'. scripts/package/gen-diff-patch tries to address the diff from HEAD, but including untracked files by the hand-crafted script introduces more complexity. I wrote a patch [1] to make it work in most cases, but still wonder if this is what we should aim for. To simplify the code, this patch just gives up untracked files. Going forward, it is your responsibility to do 'git add' for what you want in the source package. The script shows a warning just in case you forgot to do so. It should be checked only when building source packages. [1]: https://lore.kernel.org/all/CAK7LNAShbZ56gSh9PrbLnBDYKnjtTkHMoCXeGrhcxMvqXGq9=g@mail.gmail.com/2-0001-kbuild-make-package-builds-more-robust.patch Fixes: 05e96e9 ("kbuild: use git-archive for source package creation") Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
1 parent dcc11ac commit aa7d233

File tree

4 files changed

+90
-89
lines changed

4 files changed

+90
-89
lines changed

scripts/Makefile.package

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ binrpm-pkg:
9494
$(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec
9595

9696
quiet_cmd_debianize = GEN $@
97-
cmd_debianize = $(srctree)/scripts/package/mkdebian
97+
cmd_debianize = $(srctree)/scripts/package/mkdebian $(mkdebian-opts)
9898

9999
debian: FORCE
100100
$(call cmd,debianize)
@@ -103,6 +103,7 @@ PHONY += debian-orig
103103
debian-orig: private source = $(shell dpkg-parsechangelog -S Source)
104104
debian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//')
105105
debian-orig: private orig-name = $(source)_$(version).orig.tar.gz
106+
debian-orig: mkdebian-opts = --need-source
106107
debian-orig: linux.tar.gz debian
107108
$(Q)if [ "$(df --output=target .. 2>/dev/null)" = "$(df --output=target $< 2>/dev/null)" ]; then \
108109
ln -f $< ../$(orig-name); \

scripts/package/gen-diff-patch

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,36 @@
11
#!/bin/sh
22
# SPDX-License-Identifier: GPL-2.0-only
33

4-
diff_patch="${1}"
5-
untracked_patch="${2}"
6-
srctree=$(dirname $0)/../..
4+
diff_patch=$1
75

8-
rm -f ${diff_patch} ${untracked_patch}
6+
mkdir -p "$(dirname "${diff_patch}")"
97

10-
if ! ${srctree}/scripts/check-git; then
11-
exit
12-
fi
13-
14-
mkdir -p "$(dirname ${diff_patch})" "$(dirname ${untracked_patch})"
8+
git -C "${srctree:-.}" diff HEAD > "${diff_patch}"
159

16-
git -C "${srctree}" diff HEAD > "${diff_patch}"
17-
18-
if [ ! -s "${diff_patch}" ]; then
19-
rm -f "${diff_patch}"
10+
if [ ! -s "${diff_patch}" ] ||
11+
[ -z "$(git -C "${srctree:-.}" ls-files --other --exclude-standard | head -n1)" ]; then
2012
exit
2113
fi
2214

23-
git -C ${srctree} status --porcelain --untracked-files=all |
24-
while read stat path
25-
do
26-
if [ "${stat}" = '??' ]; then
27-
28-
if ! diff -u /dev/null "${srctree}/${path}" > .tmp_diff &&
29-
! head -n1 .tmp_diff | grep -q "Binary files"; then
30-
{
31-
echo "--- /dev/null"
32-
echo "+++ linux/$path"
33-
cat .tmp_diff | tail -n +3
34-
} >> ${untracked_patch}
35-
fi
36-
fi
37-
done
38-
39-
rm -f .tmp_diff
40-
41-
if [ ! -s "${diff_patch}" ]; then
42-
rm -f "${diff_patch}"
43-
exit
44-
fi
15+
# The source tarball, which is generated by 'git archive', contains everything
16+
# you committed in the repository. If you have local diff ('git diff HEAD'),
17+
# it will go into ${diff_patch}. If untracked files are remaining, the resulting
18+
# source package may not be correct.
19+
#
20+
# Examples:
21+
# - You modified a source file to add #include "new-header.h"
22+
# but forgot to add new-header.h
23+
# - You modified a Makefile to add 'obj-$(CONFIG_FOO) += new-dirver.o'
24+
# but you forgot to add new-driver.c
25+
#
26+
# You need to commit them, or at least stage them by 'git add'.
27+
#
28+
# This script does not take care of untracked files because doing so would
29+
# introduce additional complexity. Instead, print a warning message here if
30+
# untracked files are found.
31+
# If all untracked files are just garbage, you can ignore this warning.
32+
echo >&2 "============================ WARNING ============================"
33+
echo >&2 "Your working tree has diff from HEAD, and also untracked file(s)."
34+
echo >&2 "Please make sure you did 'git add' for all new files you need in"
35+
echo >&2 "the source package."
36+
echo >&2 "================================================================="

scripts/package/mkdebian

Lines changed: 59 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,66 @@ set_debarch() {
8484
fi
8585
}
8686

87+
# Create debian/source/ if it is a source package build
88+
gen_source ()
89+
{
90+
mkdir -p debian/source
91+
92+
echo "3.0 (quilt)" > debian/source/format
93+
94+
{
95+
echo "diff-ignore"
96+
echo "extend-diff-ignore = .*"
97+
} > debian/source/local-options
98+
99+
# Add .config as a patch
100+
mkdir -p debian/patches
101+
{
102+
echo "Subject: Add .config"
103+
echo "Author: ${maintainer}"
104+
echo
105+
echo "--- /dev/null"
106+
echo "+++ linux/.config"
107+
diff -u /dev/null "${KCONFIG_CONFIG}" | tail -n +3
108+
} > debian/patches/config.patch
109+
echo config.patch > debian/patches/series
110+
111+
"${srctree}/scripts/package/gen-diff-patch" debian/patches/diff.patch
112+
if [ -s debian/patches/diff.patch ]; then
113+
sed -i "
114+
1iSubject: Add local diff
115+
1iAuthor: ${maintainer}
116+
1i
117+
" debian/patches/diff.patch
118+
119+
echo diff.patch >> debian/patches/series
120+
else
121+
rm -f debian/patches/diff.patch
122+
fi
123+
}
124+
87125
rm -rf debian
126+
mkdir debian
127+
128+
email=${DEBEMAIL-$EMAIL}
129+
130+
# use email string directly if it contains <email>
131+
if echo "${email}" | grep -q '<.*>'; then
132+
maintainer=${email}
133+
else
134+
# or construct the maintainer string
135+
user=${KBUILD_BUILD_USER-$(id -nu)}
136+
name=${DEBFULLNAME-${user}}
137+
if [ -z "${email}" ]; then
138+
buildhost=${KBUILD_BUILD_HOST-$(hostname -f 2>/dev/null || hostname)}
139+
email="${user}@${buildhost}"
140+
fi
141+
maintainer="${name} <${email}>"
142+
fi
143+
144+
if [ "$1" = --need-source ]; then
145+
gen_source
146+
fi
88147

89148
# Some variables and settings used throughout the script
90149
version=$KERNELRELEASE
@@ -104,22 +163,6 @@ fi
104163
debarch=
105164
set_debarch
106165

107-
email=${DEBEMAIL-$EMAIL}
108-
109-
# use email string directly if it contains <email>
110-
if echo $email | grep -q '<.*>'; then
111-
maintainer=$email
112-
else
113-
# or construct the maintainer string
114-
user=${KBUILD_BUILD_USER-$(id -nu)}
115-
name=${DEBFULLNAME-$user}
116-
if [ -z "$email" ]; then
117-
buildhost=${KBUILD_BUILD_HOST-$(hostname -f 2>/dev/null || hostname)}
118-
email="$user@$buildhost"
119-
fi
120-
maintainer="$name <$email>"
121-
fi
122-
123166
# Try to determine distribution
124167
if [ -n "$KDEB_CHANGELOG_DIST" ]; then
125168
distribution=$KDEB_CHANGELOG_DIST
@@ -132,34 +175,6 @@ else
132175
echo >&2 "Install lsb-release or set \$KDEB_CHANGELOG_DIST explicitly"
133176
fi
134177

135-
mkdir -p debian/source/
136-
echo "3.0 (quilt)" > debian/source/format
137-
138-
{
139-
echo "diff-ignore"
140-
echo "extend-diff-ignore = .*"
141-
} > debian/source/local-options
142-
143-
# Add .config as a patch
144-
mkdir -p debian/patches
145-
{
146-
echo "Subject: Add .config"
147-
echo "Author: ${maintainer}"
148-
echo
149-
echo "--- /dev/null"
150-
echo "+++ linux/.config"
151-
diff -u /dev/null "${KCONFIG_CONFIG}" | tail -n +3
152-
} > debian/patches/config
153-
echo config > debian/patches/series
154-
155-
$(dirname $0)/gen-diff-patch debian/patches/diff.patch debian/patches/untracked.patch
156-
if [ -f debian/patches/diff.patch ]; then
157-
echo diff.patch >> debian/patches/series
158-
fi
159-
if [ -f debian/patches/untracked.patch ]; then
160-
echo untracked.patch >> debian/patches/series
161-
fi
162-
163178
echo $debarch > debian/arch
164179
extra_build_depends=", $(if_enabled_echo CONFIG_UNWINDER_ORC libelf-dev:native)"
165180
extra_build_depends="$extra_build_depends, $(if_enabled_echo CONFIG_SYSTEM_TRUSTED_KEYRING libssl-dev:native)"

scripts/package/mkspec

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ else
1919
mkdir -p rpmbuild/SOURCES
2020
cp linux.tar.gz rpmbuild/SOURCES
2121
cp "${KCONFIG_CONFIG}" rpmbuild/SOURCES/config
22-
$(dirname $0)/gen-diff-patch rpmbuild/SOURCES/diff.patch rpmbuild/SOURCES/untracked.patch
23-
touch rpmbuild/SOURCES/diff.patch rpmbuild/SOURCES/untracked.patch
22+
"${srctree}/scripts/package/gen-diff-patch" rpmbuild/SOURCES/diff.patch
2423
fi
2524

2625
if grep -q CONFIG_MODULES=y include/config/auto.conf; then
@@ -56,7 +55,6 @@ sed -e '/^DEL/d' -e 's/^\t*//' <<EOF
5655
$S Source0: linux.tar.gz
5756
$S Source1: config
5857
$S Source2: diff.patch
59-
$S Source3: untracked.patch
6058
Provides: $PROVIDES
6159
$S BuildRequires: bc binutils bison dwarves
6260
$S BuildRequires: (elfutils-libelf-devel or libelf-devel) flex
@@ -94,12 +92,7 @@ $S$M
9492
$S %prep
9593
$S %setup -q -n linux
9694
$S cp %{SOURCE1} .config
97-
$S if [ -s %{SOURCE2} ]; then
98-
$S patch -p1 < %{SOURCE2}
99-
$S fi
100-
$S if [ -s %{SOURCE3} ]; then
101-
$S patch -p1 < %{SOURCE3}
102-
$S fi
95+
$S patch -p1 < %{SOURCE2}
10396
$S
10497
$S %build
10598
$S $MAKE %{?_smp_mflags} KERNELRELEASE=$KERNELRELEASE KBUILD_BUILD_VERSION=%{release}

0 commit comments

Comments
 (0)