From patchwork Sat Jan 28 17:38:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13119884 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62A3CC27C76 for ; Sat, 28 Jan 2023 17:38:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231442AbjA1Riv (ORCPT ); Sat, 28 Jan 2023 12:38:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231350AbjA1Riv (ORCPT ); Sat, 28 Jan 2023 12:38:51 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B86E059E9; Sat, 28 Jan 2023 09:38:49 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4559660C33; Sat, 28 Jan 2023 17:38:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59F54C433EF; Sat, 28 Jan 2023 17:38:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674927528; bh=yzi89IhCB78iNCVxrj1M/NJav/gcGQem7RXofjXR3Vk=; h=From:To:Cc:Subject:Date:From; b=iNw+ZlK362yBc8Aw1Tzu2eiULCLiKww0MbyVMDWgkHB8kcvnPGs6c9sg7UpjYiOy+ UUPou6RyEITGqMnAMbC377NSPHSSdyVamEUzmIJ71XuBsqt48oGA9HTsyvgvpmngDJ vvKaHz3sEUU/t3nbtbYaThVTvbsm2Cl3F+me0Ddf0BGavzlEsAv3mdh/O1S5ooSoyr CHr2YahljpYRn0sxmpd/Ic/vFrfNrc30mN2vjTwUjaUmT/MPXyXmQ3Pfl6WXSJ9LuU P5sIk857JB5fry+wQgpvusjtC2abr0kZbns55+3mEBaCpLRfYmKC8B5jisKJK1Cn1M 40UR0qiZle/YA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Masahiro Yamada Subject: [PATCH 1/4] kbuild: add a script to generate a list of files ignored by git Date: Sun, 29 Jan 2023 02:38:40 +0900 Message-Id: <20230128173843.765212-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org In short, the motivation of this commit is to build a source package without cleaning the source tree. The deb-pkg and (src)rpm-pkg targets first run 'make clean' before creating a source tarball. Otherwise build artifacts such as *.o, *.a, etc. would be included in the tarball. Yet, the tarball ends up containing several garbage files since 'make clean' does not clean everything. Clearning the tree everytime is annoying since it makes the incremental build impossible. It is desireable to create a source tarball without cleaning the tree. In fact, there are some ways to archive this. The easiest way is "git archive". Actually, "make perf-tar*-src-pkg" does this way, but I do not like it because it works only when the source tree is managed by git, and all files you want in the tarball must be committed in advance. I want to make it work without relying on git. We can do this. Files that are not tracked by git are generated files. We can list them out by parsing the .gitignore files. Of course, .gitignore does not cover all the cases, but it works well mostly. tar(1) claims to support it: --exclude-vcs-ignores Exclude files that match patterns read from VCS-specific ignore files. Supported files are: .cvsignore, .gitignore, .bzrignore, and .hgignore. The best scenario would be to use "tar --exclude-vcs-ignores", but this option does not work. --exclude-vcs-ignore does not understand any of the negation (!), preceding slash, following slash. So, this option is just useless. I explored some libraries. - libgit2 libgit2 supports git_ignore_path_is_ignored(), but it only works in a git-managed tree. So, this does not fit to my purpose. - Python's gitignore-parser This library does not work. For example, if .gitignore is like this: $ cat .gitignore foo/ You will get this: >>> gitignore_parser.parse_gitignore('.gitignore')('foo.a') True I do not understand why 'foo.a' matches 'foo/'. This library is buggy. - Perl's Parse::Gitignore It does not understand glob patterns at all. 'foo.o' does not match '*.o'. Hence, this library is also useless. After all, I decided to write the code by myself. It is much faster. Hence, this tool. The new script, scripts/gen-exclude.py, tarverses the source tree, parsing the .gitignore files. It prints the file paths that are not tracked by git. This is suitable to be passed to tar's --exclude-from= option. A drawback is this script is so slow. It takes more than a minutes to traverse the kernel tree. It is better to rewrite it in C or something, but this is useful at least for proof of concept. [How to test this script] $ git clean -dfx $ make -s -j$(nproc) defconfig all # or allmodconifg or whatever $ git archive -o ../linux1.tar --prefix=./ HEAD $ tar tf ../linux1.tar | LANG=C sort > ../file-list1 # files emitted by 'git archive' $ scripts/gen-exclude.py --prefix=./ > ../exclude-list $ tar cf ../linux2.tar --exclude-from=../exclude-list . $ tar tf ../linux2.tar | LANG=C sort > ../file-list2 # files emitted by 'tar' $ diff ../file-list1 ../file-list2 | grep -E '^(<|>)' < ./Documentation/devicetree/bindings/.yamllint < ./drivers/clk/.kunitconfig < ./drivers/gpu/drm/tests/.kunitconfig < ./drivers/hid/.kunitconfig < ./fs/ext4/.kunitconfig < ./fs/fat/.kunitconfig < ./kernel/kcsan/.kunitconfig < ./lib/kunit/.kunitconfig < ./mm/kfence/.kunitconfig < ./tools/testing/selftests/arm64/tags/ < ./tools/testing/selftests/arm64/tags/.gitignore < ./tools/testing/selftests/arm64/tags/Makefile < ./tools/testing/selftests/arm64/tags/run_tags_test.sh < ./tools/testing/selftests/arm64/tags/tags_test.c < ./tools/testing/selftests/kvm/.gitignore < ./tools/testing/selftests/kvm/Makefile < ./tools/testing/selftests/kvm/config < ./tools/testing/selftests/kvm/settings The source tarball contains most of files that are tracked by git. You see some diffs, but it is just because some .gitignore files are wrong. $ git ls-files -i -c --exclude-per-directory=.gitignore Documentation/devicetree/bindings/.yamllint drivers/clk/.kunitconfig drivers/gpu/drm/tests/.kunitconfig drivers/hid/.kunitconfig fs/ext4/.kunitconfig fs/fat/.kunitconfig kernel/kcsan/.kunitconfig lib/kunit/.kunitconfig mm/kfence/.kunitconfig tools/testing/selftests/arm64/tags/.gitignore tools/testing/selftests/arm64/tags/Makefile tools/testing/selftests/arm64/tags/run_tags_test.sh tools/testing/selftests/arm64/tags/tags_test.c tools/testing/selftests/kvm/.gitignore tools/testing/selftests/kvm/Makefile tools/testing/selftests/kvm/config tools/testing/selftests/kvm/settings Signed-off-by: Masahiro Yamada --- scripts/gen-exclude.py | 201 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100755 scripts/gen-exclude.py diff --git a/scripts/gen-exclude.py b/scripts/gen-exclude.py new file mode 100755 index 000000000000..308c30779c79 --- /dev/null +++ b/scripts/gen-exclude.py @@ -0,0 +1,201 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 only +# +# Copyright: Masahiro Yamada + +import argparse +import collections +import logging +import os +import pathlib + + +class IgnorePattern: + + def __init__(self, pattern, dirpath): + + logging.debug(f" Add pattern: {pattern}") + + self.orig = pattern + self.negate = False + self.dir_only = False + self.double_asterisk = False + + # The prefix '!' negates the pattern. + if pattern[0] == '!': + self.negate = True + pattern = pattern[1:] + + # a pattern with a trailing slash only matches to directories + if pattern[-1] == '/': + self.dir_only = True + pattern = pattern[:-1] + + # FIXME: + # Escape sequence ('\') does not work correctly. + # Just strip a backslash at the beginning to support '\#*#'. + if pattern[0] == '\\': + pattern = pattern[1:] + + # It is tricky to handle double asterisks ("**"). + # pathlib's match() cannot handle it but glob() can. + if '**' in pattern: + self.double_asterisk = True + if pattern[0] == '/': + pattern = pattern[1:] + + self.pattern = [] + + for f in dirpath.glob(pattern): + self.pattern.append(f.absolute()) + + return + # If a slash appears at the beginning or middle of the pattern, + # (e.g. "/a", "a/b", etc.) it is relative to the directory level. + elif '/' in pattern: + if pattern[0] == '/': + pattern = pattern[1:] + pattern = str(dirpath.joinpath(pattern).absolute()) + + self.pattern = pattern + + def is_ignored(self, path): + + if path.is_dir() and path.name == '.git': + logging.debug(f' Ignore: {path}') + return True + + if self.dir_only and not path.is_dir(): + return None + + if self.double_asterisk: + # Special handling for double asterisks + if not path.absolute() in self.pattern: + return None + else: + # make the path abosolute before matching, so it works for patterns + # that contain slash(es) such as "/a", "a/b". + if not path.absolute().match(self.pattern): + return None + + logging.debug(f' {"Not" if self.negate else ""}Ignore: {path} (pattern: {self.orig})') + + return not self.negate + + +class GitIgnore: + def __init__(self, path): + # If a path matches multiple patterns, the last one wins. + # So, patterns must be checked in the reverse order. + # Use deque's appendleft() to add a new pattern. + self.patterns = collections.deque() + if path is not None: + logging.debug(f" Add gitignore: {path}") + self._parse(path) + + def _parse(self, path): + with open(path) as f: + for line in f: + if line.startswith('#'): + continue + + line = line.strip() + if not line: + continue + + self.patterns.appendleft(IgnorePattern(line, path.parent)) + + def is_ignored(self, path): + for pattern in self.patterns: + ret = pattern.is_ignored(path) + if ret is not None: + return ret + + return None + + +class GitIgnores: + def __init__(self): + self.ignore_files = collections.deque() + + def append(self, path): + self.ignore_files.appendleft(GitIgnore(path)) + + def pop(self): + self.ignore_files.popleft() + + def is_ignored(self, path): + + for gitignore in self.ignore_files: + ret = gitignore.is_ignored(path) + if ret is not None: + return ret + + logging.debug(f" NoMatch: {path}") + + return False + + +def parse_arguments(): + + parser = argparse.ArgumentParser(description='Print files that are not ignored by .gitignore') + + parser.add_argument('-d', '--debug', action='store_true', help='enable debug log') + + parser.add_argument('--prefix', default='', help='prefix added to each path') + + parser.add_argument('--rootdir', default='.', help='root of the source tree (default: current working directory)') + + args = parser.parse_args() + + return args + + +def traverse_directory(path, gitignores, printer): + + logging.debug(f"Enter: {path}") + + gitignore_file = None + all_ignored = True + + for f in path.iterdir(): + if f.is_file() and f.name == '.gitignore': + gitignore_file = f + + gitignores.append(gitignore_file) + + for f in path.iterdir(): + logging.debug(f" Check: {f}") + if gitignores.is_ignored(f): + printer(f) + else: + if f.is_dir() and not f.is_symlink(): + ret = traverse_directory(f, gitignores, printer) + all_ignored = all_ignored and ret + else: + all_ignored = False + + if all_ignored: + printer(path) + + gitignores.pop() + logging.debug(f"Leave: {path}") + + return all_ignored + + +def main(): + + args = parse_arguments() + + logging.basicConfig(format='%(levelname)s: %(message)s', + level='DEBUG' if args.debug else 'WARNING') + + os.chdir(args.rootdir) + + traverse_directory(pathlib.Path('.'), GitIgnores(), + lambda path: print(f'{args.prefix}{str(path)}')) + + +if __name__ == '__main__': + main() From patchwork Sat Jan 28 17:38:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13119886 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD443C61DA4 for ; Sat, 28 Jan 2023 17:39:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234569AbjA1Ri7 (ORCPT ); Sat, 28 Jan 2023 12:38:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234552AbjA1Riy (ORCPT ); Sat, 28 Jan 2023 12:38:54 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE9B0298F9; Sat, 28 Jan 2023 09:38:53 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4813DB80AF8; Sat, 28 Jan 2023 17:38:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17AB3C4339B; Sat, 28 Jan 2023 17:38:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674927530; bh=v3mGrohSr9bDJCU80FA5vw5BtHfkP5BeWMETdmxm4ig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BJ77Hd9pAM2KjrvlAv7HMI+wb6gmzEBp0khlIkiklt15F6IdOiKaoQ+ctKHDdQQ3T Qwnwxnnkn5iiRHWRcnoWV31HAMhIAQM7rVeQdBApeS1+eoijx2RAWdhOuY5XHpduAU tibyai5jwb+Md3UW01iGzsg7n/R1hBXfCVX6cU7qBm4P3IQVWSrjMdg0XNQYTQlek5 U8fR58y7chseduKcSV+NUyCOt9P6tYeFnBkHe9/r9AUGTB5Hu1WSyeGEOXRrxBE+ET jzoHbWkQ0pA0v5bYufGHaQ2HtDv5ObWbzyMldFkbbgky27DnJx3IJIkpDhQlS7ozsm 92FgL92Q9Wfuw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Masahiro Yamada , Tom Rix , llvm@lists.linux.dev Subject: [PATCH 2/4] kbuild: deb-pkg: create source package without cleaning Date: Sun, 29 Jan 2023 02:38:41 +0900 Message-Id: <20230128173843.765212-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230128173843.765212-1-masahiroy@kernel.org> References: <20230128173843.765212-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org If you run 'make deb-pkg', all objects are lost due to 'make clean', which makes the incremental builds impossible. Instead of cleaning, pass the exclude list to tar's --exclude-from option. Previously, *.diff.gz contained some check-in files such as .clang-format, .cocciconfig. With this commit, *.diff.gz will only contain the .config and debian/. The other source files will go into the tarball. Signed-off-by: Masahiro Yamada --- scripts/Makefile.package | 27 ++++++++++++++++++++++----- scripts/package/mkdebian | 27 +++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/scripts/Makefile.package b/scripts/Makefile.package index dfbf40454a99..cb135c99a273 100644 --- a/scripts/Makefile.package +++ b/scripts/Makefile.package @@ -50,6 +50,21 @@ fi ; \ tar -I $(KGZIP) -c $(RCS_TAR_IGNORE) -f $(2).tar.gz \ --transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3) +# Source Tarball +# --------------------------------------------------------------------------- + +quiet_cmd_exclude_list = GEN $@ + cmd_exclude_list = $(srctree)/scripts/gen-exclude.py --prefix=./ --rootdir=$(srctree) > $@; echo "./$@" >> $@ + +.exclude-list: FORCE + $(call cmd,exclude_list) + +quiet_cmd_tar = TAR $@ + cmd_tar = tar -I $(KGZIP) -c -f $@ -C $(srctree) --exclude-from=$< --exclude=./$@ --transform 's:^\.:linux:S' . + +%.tar.gz: .exclude-list + $(call cmd,tar) + # rpm-pkg # --------------------------------------------------------------------------- PHONY += rpm-pkg @@ -81,12 +96,11 @@ binrpm-pkg: PHONY += deb-pkg deb-pkg: - $(MAKE) clean $(CONFIG_SHELL) $(srctree)/scripts/package/mkdebian - $(call cmd,src_tar,$(KDEB_SOURCENAME)) - origversion=$$(dpkg-parsechangelog -SVersion |sed 's/-[^-]*$$//');\ - mv $(KDEB_SOURCENAME).tar.gz ../$(KDEB_SOURCENAME)_$${origversion}.orig.tar.gz - +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) --source-option=-sP -i.git -us -uc + $(Q)origversion=$$(dpkg-parsechangelog -SVersion |sed 's/-[^-]*$$//');\ + $(MAKE) -f $(srctree)/scripts/Makefile.package ../$(KDEB_SOURCENAME)_$${origversion}.orig.tar.gz + +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) \ + --build=source,binary --source-option=-sP -nc -us -uc PHONY += bindeb-pkg bindeb-pkg: @@ -174,4 +188,7 @@ help: @echo ' perf-tarxz-src-pkg - Build $(perf-tar).tar.xz source tarball' @echo ' perf-tarzst-src-pkg - Build $(perf-tar).tar.zst source tarball' +PHONY += FORCE +FORCE: + .PHONY: $(PHONY) diff --git a/scripts/package/mkdebian b/scripts/package/mkdebian index c3bbef7a6754..12c057ffbe6e 100755 --- a/scripts/package/mkdebian +++ b/scripts/package/mkdebian @@ -84,6 +84,8 @@ set_debarch() { fi } +rm -rf debian + # Some variables and settings used throughout the script version=$KERNELRELEASE if [ -n "$KDEB_PKGVERSION" ]; then @@ -135,6 +137,31 @@ fi mkdir -p debian/source/ echo "1.0" > debian/source/format +cat<<'EOF' > debian/source/local-options +# +# Ugly: ignore anything except .config or debian/ +# (is there a cleaner way to do this?) +# +diff-ignore + +extend-diff-ignore = ^[^.d] + +extend-diff-ignore = ^\.[^c] +extend-diff-ignore = ^\.c($|[^o]) +extend-diff-ignore = ^\.co($|[^n]) +extend-diff-ignore = ^\.con($|[^f]) +extend-diff-ignore = ^\.conf($|[^i]) +extend-diff-ignore = ^\.confi($|[^g]) +extend-diff-ignore = ^\.config. + +extend-diff-ignore = ^d($|[^e]) +extend-diff-ignore = ^de($|[^b]) +extend-diff-ignore = ^deb($|[^i]) +extend-diff-ignore = ^debi($|[^a]) +extend-diff-ignore = ^debia($|[^n]) +extend-diff-ignore = ^debian[^/] +EOF + echo $debarch > debian/arch extra_build_depends=", $(if_enabled_echo CONFIG_UNWINDER_ORC libelf-dev:native)" extra_build_depends="$extra_build_depends, $(if_enabled_echo CONFIG_SYSTEM_TRUSTED_KEYRING libssl-dev:native)" From patchwork Sat Jan 28 17:38:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13119885 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 713FFC27C76 for ; Sat, 28 Jan 2023 17:39:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234586AbjA1Ri7 (ORCPT ); Sat, 28 Jan 2023 12:38:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231350AbjA1Riy (ORCPT ); Sat, 28 Jan 2023 12:38:54 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4FEA29E12; Sat, 28 Jan 2023 09:38:53 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 512ED60C38; Sat, 28 Jan 2023 17:38:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CFB9C4339E; Sat, 28 Jan 2023 17:38:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674927532; bh=GrGb9cq9sIB19Bfg04e4zkiYmu8jJkmhEilowIb/Og4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gL0CscrWnVnssNZCMOLIlMWfvuZN8HbXrPrbjuVCqaBgpLGBu7NujXdKVmRAXEG9g FlSUNxSpA2opyc/ftP2YywZ5QnO0jGJ6+JxG9Nhg5xDheLIVj//gDvq0+wwiBigb3b i+qhpyvcPw/dqLpN1FbfeSWjcE3gtHznTxPt4Bro461Wiy9e/foIv+L60PxddBwr2J SevVw0ReF+9deWGLKJe3yqXOjXVaQMIxQFC62aScua6Yj76dltGUtsBq1UQlQ1WY6q IwXAVhnJUbaPf1TOycxpL3jmVod5Ec1LibRUcp34vnUfDBoPyNNJFodqsp/VpwQ8HO 3Dzzf6VSALsSQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Masahiro Yamada Subject: [PATCH 3/4] kbuild: rpm-pkg: build binary packages from source rpm Date: Sun, 29 Jan 2023 02:38:42 +0900 Message-Id: <20230128173843.765212-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230128173843.765212-1-masahiroy@kernel.org> References: <20230128173843.765212-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org The build rules of rpm-pkg and srcrpm-pkg are almost the same. Remove the code duplication. Make rpm-pkg build binary packages from the source package built by srcrpm-pkg. Signed-off-by: Masahiro Yamada --- scripts/Makefile.package | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/Makefile.package b/scripts/Makefile.package index cb135c99a273..8fa6f05967aa 100644 --- a/scripts/Makefile.package +++ b/scripts/Makefile.package @@ -68,11 +68,9 @@ quiet_cmd_tar = TAR $@ # rpm-pkg # --------------------------------------------------------------------------- PHONY += rpm-pkg -rpm-pkg: - $(MAKE) clean - $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec - $(call cmd,src_tar,$(KERNELPATH),kernel.spec) - +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -ta $(KERNELPATH).tar.gz \ +rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec) +rpm-pkg: srcrpm-pkg + +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \ --define='_smp_mflags %{nil}' # srcrpm-pkg From patchwork Sat Jan 28 17:38:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13119887 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64ED5C636BD for ; Sat, 28 Jan 2023 17:39:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234570AbjA1RjB (ORCPT ); Sat, 28 Jan 2023 12:39:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234556AbjA1RjA (ORCPT ); Sat, 28 Jan 2023 12:39:00 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90F492A16E; Sat, 28 Jan 2023 09:38:58 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 37C92B80B57; Sat, 28 Jan 2023 17:38:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F58FC433A0; Sat, 28 Jan 2023 17:38:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674927535; bh=P19kYlGfD3VxBVIeWwkF+xYQQvFrLROr+eyRMXl63m8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KloQZ1aiZfD75B8qAlJ1PJVdb0nqw3EncU3v/lftBFLC1C98PXfsqx9Nmctkf9KBP PiOywUKd9jApp1kZuKHz1LxCz2Ntr1AwA5C56xxoQcS9wf9hSsT722Xqse+MyQNOL8 V80VheaSJB4H7j1H4s3oPABql/qv6mxrHy4rgTCmTQr4d4+N9KUAyljgCekRpp/dz8 t1L078mlDpZ3JlnFTW3NKB6qvSoYojKidJU4oPZXl4QAO4bkH1jN+vA8f/o3VRcwrv 2gTfUee9U3iLzpASeu2XXrvna8ci3cZGJPUA6n8S//XZW5MVzIYyajDfM2UpgcwzfE tH8xYDGjBTfwQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Masahiro Yamada , Alex Gaynor , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Boqun Feng , Gary Guo , Miguel Ojeda , Wedson Almeida Filho , rust-for-linux@vger.kernel.org Subject: [PATCH 4/4] kbuild: srcrpm-pkg: create source package without cleaning Date: Sun, 29 Jan 2023 02:38:43 +0900 Message-Id: <20230128173843.765212-4-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230128173843.765212-1-masahiroy@kernel.org> References: <20230128173843.765212-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org If you run 'make (src)rpm-pkg', all objects are lost due to 'make clean', which makes the incremental builds impossible. Instead of cleaning, pass the exclude list to tar's --exclude-from option. Previously, the .config was contained in the source tarball. With this commit, the source rpm consists of separate linux.tar.gz and .config. Remove stale comments. Now, 'make (src)rpm-pkg' works with O= option. Signed-off-by: Masahiro Yamada --- scripts/Makefile.package | 50 +++------------------------------------- scripts/package/mkspec | 8 +++---- 2 files changed, 7 insertions(+), 51 deletions(-) diff --git a/scripts/Makefile.package b/scripts/Makefile.package index 8fa6f05967aa..b899fe747bc9 100644 --- a/scripts/Makefile.package +++ b/scripts/Makefile.package @@ -3,53 +3,11 @@ include $(srctree)/scripts/Kbuild.include -# RPM target -# --------------------------------------------------------------------------- -# The rpm target generates two rpm files: -# /usr/src/packages/SRPMS/kernel-2.6.7rc2-1.src.rpm -# /usr/src/packages/RPMS/i386/kernel-2.6.7rc2-1..rpm -# The src.rpm files includes all source for the kernel being built -# The .rpm includes kernel configuration, modules etc. -# -# Process to create the rpm files -# a) clean the kernel -# b) Generate .spec file -# c) Build a tar ball, using symlink to make kernel version -# first entry in the path -# d) and pack the result to a tar.gz file -# e) generate the rpm files, based on kernel.spec -# - Use /. to avoid tar packing just the symlink - -# Note that the rpm-pkg target cannot be used with KBUILD_OUTPUT, -# but the binrpm-pkg target can; for some reason O= gets ignored. - -# Remove hyphens since they have special meaning in RPM filenames -KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE)) KDEB_SOURCENAME ?= linux-upstream KBUILD_PKG_ROOTCMD ?="fakeroot -u" export KDEB_SOURCENAME -# Include only those top-level files that are needed by make, plus the GPL copy -TAR_CONTENT := Documentation LICENSES arch block certs crypto drivers fs \ - include init io_uring ipc kernel lib mm net rust \ - samples scripts security sound tools usr virt \ - .config Makefile \ - Kbuild Kconfig COPYING $(wildcard localversion*) MKSPEC := $(srctree)/scripts/package/mkspec -quiet_cmd_src_tar = TAR $(2).tar.gz - cmd_src_tar = \ -if test "$(objtree)" != "$(srctree)"; then \ - echo >&2; \ - echo >&2 " ERROR:"; \ - echo >&2 " Building source tarball is not possible outside the"; \ - echo >&2 " kernel source tree. Don't set KBUILD_OUTPUT, or use the"; \ - echo >&2 " binrpm-pkg or bindeb-pkg target instead."; \ - echo >&2; \ - false; \ -fi ; \ -tar -I $(KGZIP) -c $(RCS_TAR_IGNORE) -f $(2).tar.gz \ - --transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3) - # Source Tarball # --------------------------------------------------------------------------- @@ -76,12 +34,10 @@ rpm-pkg: srcrpm-pkg # srcrpm-pkg # --------------------------------------------------------------------------- PHONY += srcrpm-pkg -srcrpm-pkg: - $(MAKE) clean +srcrpm-pkg: linux.tar.gz $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec - $(call cmd,src_tar,$(KERNELPATH),kernel.spec) - +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -ts $(KERNELPATH).tar.gz \ - --define='_smp_mflags %{nil}' --define='_srcrpmdir $(srctree)' + +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -bs kernel.spec \ + --define='_smp_mflags %{nil}' --define='_sourcedir .' --define='_srcrpmdir .' # binrpm-pkg # --------------------------------------------------------------------------- diff --git a/scripts/package/mkspec b/scripts/package/mkspec index 108c0cb95436..83a64d9d7372 100755 --- a/scripts/package/mkspec +++ b/scripts/package/mkspec @@ -47,7 +47,8 @@ sed -e '/^DEL/d' -e 's/^\t*//' <