Skip to content

Commit 05e96e9

Browse files
committed
kbuild: use git-archive for source package creation
Commit 5c3d1d0 ("kbuild: add a tool to list files ignored by git") added a new tool, scripts/list-gitignored. My intention was to create source packages without cleaning the source tree, without relying on git. Linus strongly objected to it, and suggested using 'git archive' instead. [1] [2] [3] This commit goes in that direction - Remove scripts/list-gitignored.c and rewrites Makefiles and scripts to use 'git archive' for building Debian and RPM source packages. It also makes 'make perf-tar*-src-pkg' use 'git archive' again. Going forward, building source packages is only possible in a git-managed tree. Building binary packages does not require git. [1]: https://lore.kernel.org/lkml/CAHk-=wi49sMaC7vY1yMagk7eqLK=1jHeHQ=yZ_k45P=xBccnmA@mail.gmail.com/ [2]: https://lore.kernel.org/lkml/CAHk-=wh5AixGsLeT0qH2oZHKq0FLUTbyTw4qY921L=PwYgoGVw@mail.gmail.com/ [3]: https://lore.kernel.org/lkml/CAHk-=wgM-W6Fu==EoAVCabxyX8eYBz9kNC88-tm9ExRQwA79UQ@mail.gmail.com/ Fixes: 5c3d1d0 ("kbuild: add a tool to list files ignored by git") Fixes: e0ca167 ("kbuild: make perf-tar*-src-pkg work without relying on git") Suggested-by: Linus Torvalds <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 81f59a2 commit 05e96e9

File tree

10 files changed

+181
-1155
lines changed

10 files changed

+181
-1155
lines changed

Makefile

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,7 @@ no-dot-config-targets := $(clean-targets) \
274274
cscope gtags TAGS tags help% %docs check% coccicheck \
275275
$(version_h) headers headers_% archheaders archscripts \
276276
%asm-generic kernelversion %src-pkg dt_binding_check \
277-
outputmakefile rustavailable rustfmt rustfmtcheck \
278-
scripts_package
277+
outputmakefile rustavailable rustfmt rustfmtcheck
279278
# Installation targets should not require compiler. Unfortunately, vdso_install
280279
# is an exception where build artifacts may be updated. This must be fixed.
281280
no-compiler-targets := $(no-dot-config-targets) install dtbs_install \
@@ -1656,10 +1655,6 @@ distclean: mrproper
16561655
%pkg: include/config/kernel.release FORCE
16571656
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@
16581657

1659-
PHONY += scripts_package
1660-
scripts_package: scripts_basic
1661-
$(Q)$(MAKE) $(build)=scripts scripts/list-gitignored
1662-
16631658
# Brief documentation of the typical targets used
16641659
# ---------------------------------------------------------------------------
16651660

scripts/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
/generate_rust_target
44
/insert-sys-cert
55
/kallsyms
6-
/list-gitignored
76
/module.lds
87
/recordmcount
98
/sign-file

scripts/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ HOSTCFLAGS_sorttable.o += -DMCOUNT_SORT_ENABLED
3838
endif
3939

4040
# The following programs are only built on demand
41-
hostprogs += list-gitignored unifdef
41+
hostprogs += unifdef
4242

4343
# The module linker script is preprocessed on demand
4444
targets += module.lds

scripts/Makefile.package

Lines changed: 68 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Makefile for the different targets used to generate full packages of a kernel
33

44
include $(srctree)/scripts/Kbuild.include
5+
include $(srctree)/scripts/Makefile.lib
56

67
KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE))
78
KBUILD_PKG_ROOTCMD ?="fakeroot -u"
@@ -26,54 +27,46 @@ fi ; \
2627
tar -I $(KGZIP) -c $(RCS_TAR_IGNORE) -f $(2).tar.gz \
2728
--transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3)
2829

29-
# .tmp_filelist .tmp_filelist_exclude
30+
# tarball compression
3031
# ---------------------------------------------------------------------------
3132

32-
scripts/list-gitignored: FORCE
33-
$(Q)$(MAKE) -f $(srctree)/Makefile scripts_package
33+
%.tar.gz: %.tar
34+
$(call cmd,gzip)
3435

35-
# 1f5d3a6b6532e25a5cdf1f311956b2b03d343a48 removed '*.rej' from .gitignore,
36-
# but it is definitely a generated file.
37-
filechk_filelist = \
38-
$< --exclude='*.rej' --output=$@_exclude --prefix=./ --rootdir=$(srctree) --stat=-
36+
%.tar.bz2: %.tar
37+
$(call cmd,bzip2)
3938

40-
.tmp_filelist: scripts/list-gitignored FORCE
41-
$(call filechk,filelist)
39+
%.tar.xz: %.tar
40+
$(call cmd,xzmisc)
4241

43-
# tarball
44-
# ---------------------------------------------------------------------------
45-
46-
quiet_cmd_tar = TAR $@
47-
cmd_tar = tar -c -f $@ $(tar-compress-opt) $(tar-exclude-opt) \
48-
--owner=0 --group=0 --sort=name \
49-
--transform 's:^\.:$*:S' -C $(tar-rootdir) .
50-
51-
tar-rootdir := $(srctree)
42+
%.tar.zst: %.tar
43+
$(call cmd,zstd)
5244

53-
%.tar:
54-
$(call cmd,tar)
55-
56-
%.tar.gz: private tar-compress-opt := -I $(KGZIP)
57-
%.tar.gz:
58-
$(call cmd,tar)
45+
# Git
46+
# ---------------------------------------------------------------------------
5947

60-
%.tar.bz2: private tar-compress-opt := -I $(KBZIP2)
61-
%.tar.bz2:
62-
$(call cmd,tar)
48+
filechk_HEAD = git -C $(srctree) rev-parse --verify HEAD 2>/dev/null
6349

64-
%.tar.xz: private tar-compress-opt := -I $(XZ)
65-
%.tar.xz:
66-
$(call cmd,tar)
50+
.tmp_HEAD: check-git FORCE
51+
$(call filechk,HEAD)
6752

68-
%.tar.zst: private tar-compress-opt := -I $(ZSTD)
69-
%.tar.zst:
70-
$(call cmd,tar)
53+
PHONY += check-git
54+
check-git:
55+
@if ! $(srctree)/scripts/check-git; then \
56+
echo >&2 "error: creating source package requires git repository"; \
57+
false; \
58+
fi
7159

7260
# Linux source tarball
7361
# ---------------------------------------------------------------------------
7462

75-
linux.tar.gz: tar-exclude-opt = --exclude=./$@ --exclude-from=$<_exclude
76-
linux.tar.gz: .tmp_filelist
63+
quiet_cmd_archive_linux = ARCHIVE $@
64+
cmd_archive_linux = \
65+
git -C $(srctree) archive --output=$$(realpath $@) --prefix=$(basename $@)/ $$(cat $<)
66+
67+
targets += linux.tar
68+
linux.tar: .tmp_HEAD FORCE
69+
$(call if_changed,archive_linux)
7770

7871
# rpm-pkg
7972
# ---------------------------------------------------------------------------
@@ -148,74 +141,62 @@ snap-pkg:
148141
# dir-pkg tar*-pkg - tarball targets
149142
# ---------------------------------------------------------------------------
150143

151-
tar-pkg-tarball = linux-$(KERNELRELEASE)-$(ARCH).$(1)
152-
tar-pkg-phony = $(subst .,,$(1))-pkg
153-
154144
tar-install: FORCE
155145
$(Q)$(MAKE) -f $(srctree)/Makefile
156146
+$(Q)$(srctree)/scripts/package/buildtar $@
157147

148+
quiet_cmd_tar = TAR $@
149+
cmd_tar = cd $<; tar cf ../$@ --owner=root --group=root --sort=name *
150+
151+
linux-$(KERNELRELEASE)-$(ARCH).tar: tar-install
152+
$(call cmd,tar)
153+
158154
PHONY += dir-pkg
159155
dir-pkg: tar-install
160156
@echo "Kernel tree successfully created in $<"
161157

162-
define tar-pkg-rule
163-
PHONY += $(tar-pkg-phony)
164-
$(tar-pkg-phony): $(tar-pkg-tarball)
158+
PHONY += tar-pkg
159+
tar-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar
165160
@:
166161

167-
$(tar-pkg-tarball): private tar-rootdir := tar-install
168-
$(tar-pkg-tarball): tar-install
169-
endef
170-
171-
$(foreach x, tar tar.gz tar.bz2 tar.xz tar.zst, $(eval $(call tar-pkg-rule,$(x))))
162+
tar%-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar.% FORCE
163+
@:
172164

173165
# perf-tar*-src-pkg - generate a source tarball with perf source
174166
# ---------------------------------------------------------------------------
175167

176-
perf-tar-src-pkg-tarball = perf-$(KERNELVERSION).$(1)
177-
perf-tar-src-pkg-phony = perf-$(subst .,,$(1))-src-pkg
178-
179-
quiet_cmd_stage_perf_src = STAGE $@
180-
cmd_stage_perf_src = \
181-
rm -rf $@; \
182-
mkdir -p $@; \
183-
tar -c -f - --exclude-from=$<_exclude -C $(srctree) --files-from=$(srctree)/tools/perf/MANIFEST | \
184-
tar -x -f - -C $@
185-
186-
.tmp_perf: .tmp_filelist
187-
$(call cmd,stage_perf_src)
188-
189-
filechk_perf_head = \
190-
if test -z "$(git -C $(srctree) rev-parse --show-cdup 2>/dev/null)" && \
191-
head=$$(git -C $(srctree) rev-parse --verify HEAD 2>/dev/null); then \
192-
echo $$head; \
193-
else \
194-
echo "not a git tree"; \
195-
fi
168+
.tmp_perf:
169+
$(Q)mkdir .tmp_perf
196170

197-
.tmp_perf/HEAD: .tmp_perf FORCE
198-
$(call filechk,perf_head)
171+
.tmp_perf/HEAD: .tmp_HEAD | .tmp_perf
172+
$(call cmd,copy)
199173

200174
quiet_cmd_perf_version_file = GEN $@
201175
cmd_perf_version_file = cd $(srctree)/tools/perf; util/PERF-VERSION-GEN $(dir $(abspath $@))
202176

203-
# PERF-VERSION-FILE and HEAD are independent, but this avoids updating the
177+
# PERF-VERSION-FILE and .tmp_HEAD are independent, but this avoids updating the
204178
# timestamp of PERF-VERSION-FILE.
205179
# The best is to fix tools/perf/util/PERF-VERSION-GEN.
206-
.tmp_perf/PERF-VERSION-FILE: .tmp_perf/HEAD $(srctree)/tools/perf/util/PERF-VERSION-GEN
180+
.tmp_perf/PERF-VERSION-FILE: .tmp_HEAD $(srctree)/tools/perf/util/PERF-VERSION-GEN | .tmp_perf
207181
$(call cmd,perf_version_file)
208182

209-
define perf-tar-src-pkg-rule
210-
PHONY += $(perf-tar-src-pkg-phony)
211-
$(perf-tar-src-pkg-phony): $(perf-tar-src-pkg-tarball)
212-
@:
183+
quiet_cmd_archive_perf = ARCHIVE $@
184+
cmd_archive_perf = \
185+
git -C $(srctree) archive --output=$$(realpath $@) --prefix=$(basename $@)/ \
186+
--add-file=$$(realpath $(word 2, $^)) \
187+
--add-file=$$(realpath $(word 3, $^)) \
188+
$$(cat $(word 2, $^))^{tree} $$(cat $<)
213189

214-
$(perf-tar-src-pkg-tarball): private tar-rootdir := .tmp_perf
215-
$(perf-tar-src-pkg-tarball): .tmp_filelist .tmp_perf/HEAD .tmp_perf/PERF-VERSION-FILE
216-
endef
190+
targets += perf-$(KERNELVERSION).tar
191+
perf-$(KERNELVERSION).tar: tools/perf/MANIFEST .tmp_perf/HEAD .tmp_perf/PERF-VERSION-FILE FORCE
192+
$(call if_changed,archive_perf)
193+
194+
PHONY += perf-tar-src-pkg
195+
perf-tar-src-pkg: perf-$(KERNELVERSION).tar
196+
@:
217197

218-
$(foreach x, tar tar.gz tar.bz2 tar.xz tar.zst, $(eval $(call perf-tar-src-pkg-rule,$(x))))
198+
perf-tar%-src-pkg: perf-$(KERNELVERSION).tar.% FORCE
199+
@:
219200

220201
# Help text displayed when executing 'make help'
221202
# ---------------------------------------------------------------------------
@@ -243,4 +224,13 @@ help:
243224
PHONY += FORCE
244225
FORCE:
245226

227+
# Read all saved command lines and dependencies for the $(targets) we
228+
# may be building above, using $(if_changed{,_dep}). As an
229+
# optimization, we don't need to read them if the target does not
230+
# exist, we will rebuild anyway in that case.
231+
232+
existing-targets := $(wildcard $(sort $(targets)))
233+
234+
-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
235+
246236
.PHONY: $(PHONY)

scripts/check-git

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: GPL-2.0-only
3+
#
4+
# succeed if we are in a git repository
5+
6+
srctree="$(dirname $0)/.."
7+
8+
if ! git -C "${srctree}" rev-parse --verify HEAD >/dev/null 2>/dev/null; then
9+
exit 1
10+
fi
11+
12+
if ! test -z $(git -C "${srctree}" rev-parse --show-cdup 2>/dev/null); then
13+
exit 1
14+
fi

0 commit comments

Comments
 (0)