From patchwork Sun Aug 20 09:15:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136244 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp2412986vqi; Sun, 20 Aug 2023 03:28:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxHYzp3W/7JPlrHryxfjq0zr3UGpODKneoQZc/575w4rq9JM6CIGrJctBGTBYfqTRk3/Uy X-Received: by 2002:a17:906:209d:b0:99b:4378:a5aa with SMTP id 29-20020a170906209d00b0099b4378a5aamr3466707ejq.49.1692527305077; Sun, 20 Aug 2023 03:28:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692527305; cv=none; d=google.com; s=arc-20160816; b=a4ASA/nHeefHzZUkzQ9c6enzvcEVzjwf/KrOUNAsrLaGF8GvzYx2Old01wckmUNDnr jKniarssqTTNOc9Dx8FDkYxnKsGuPehxxCNIn82rFWxPdvbv4OshTA+9AWYX0J0kRLlt XLIn7N89UmxjB6vY0oRW+6uTAXPH6wsos1/uzkYqnfBilscQy9MsgpzZnvZnQMf6ZD4u TxQl4Vmib5aTxciGZdHZ79WAjlyukESjMbEq0OjZ9DS5pncOrsmeMQbyyA2bshEgOUJ3 CeWGygSVXjTOtzJps9SzUoxEi14/eBzugawpgRanmY3wLgMzwK1VjFPMpdSoH2dy9eA0 E17g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=KnAChIn2HDxLLcwE/WR/nT3Zvsn7YSN6ycx+4lq9YE0=; fh=6tXSXGMSR7db9j7/4zWsmjDhZ88xtNZbemKjIIeF8Lo=; b=B42ZWdMDgrwROy0SPRf7e3XCvZ34tuUBzJNhBz4EgXz3Ob9iNrk12t0rS9u2SsuOVU GbA1349YMedaGjaz5JjQiiJdtWbRpqIxoz3d8OrFFfdbOz8vpBdKVGGD5DIwDgxR/Wkp QoOpSkUS97fZS+squJE19LIW+ZGek5Rt8C69zOMYkxe6sb+L8WpeSMXS2/Mm5WVj3xlH nSdZtLpvaviExAiYdGzGOV22tB+3oSBpArzhGbyaHQAJD6M7sJ2vPsO0EsVfnpIJbx2q oWftOTfRRHBYAVhPoi2XAuSqZc4IT1fdOkmQfuo462csUdVrJyOzhm/6toB4tpkF9qfs 3b+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Vw6QHABY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i13-20020a170906444d00b00992a9bc7432si4071188ejp.936.2023.08.20.03.27.50; Sun, 20 Aug 2023 03:28:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Vw6QHABY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230197AbjHTJQT (ORCPT + 99 others); Sun, 20 Aug 2023 05:16:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230177AbjHTJQS (ORCPT ); Sun, 20 Aug 2023 05:16:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CCA8D2; Sun, 20 Aug 2023 02:15:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0BEB261ADA; Sun, 20 Aug 2023 09:15:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F64EC433C8; Sun, 20 Aug 2023 09:15:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692522910; bh=dQwixiJ5YSja69keHsNUxrA+cKlDQpjYQOOiI8zPpAU=; h=From:To:Cc:Subject:Date:From; b=Vw6QHABYQrdSMRQPg3c3OiWjHAd3i8J3q82VfqlEQ5jBlW4NszWlHPa/AozGs6K2D kR7pnB4pS4BEycLcyAbG5u7u+KBWD3d14ni7jsltiaWf6p/p2EYffga/sng9LgKeOY D/3T3m8J9MX2y1G1l57jtPjmxdreaBJLSL06enklVLmuhqJlkomdvI0qGUcwO4dRIE X/4Ywt8o0gcniyW0hfNZscT6BIzHG99qS9lcgrnH2CipJVAAPOtjaLwwumHCjVooHV 4IwKzoPEDT8TPfQzbzdEbvEt++Ph7rt71NchZuan52GXvlUc5eTsTYJ8rFsHsEysov 6nPem4qNO8O3Q== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Bastian Germann , Nathan Chancellor , Nick Desaulniers , Nicolas Schier Subject: [PATCH] kbuild: deb-pkg: support DEB_BUILD_OPTIONS=parallel=N in debian/rules Date: Sun, 20 Aug 2023 18:15:05 +0900 Message-Id: <20230820091505.3812160-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774743511424533374 X-GMAIL-MSGID: 1774743511424533374 'make srcdeb-pkg' generates a source package, which you can build later by using dpkg-buildpackage. In older dpkg versions, 'dpkg-buildpackage -j N' sets not only DEB_BUILD_OPTIONS but also MAKEFLAGS. Hence, passing -j (--jobs) to dpkg-buildpackage was enough to run parallel building. The behavior was changed by commit 1d0ea9b2ba3f ("dpkg-buildpackage: Change -j, --jobs semantics to non-force mode") of dpkg project. [1] Since then, 'dpkg-buildpackage -j N' sets only DEB_BUILD_OPTIONS, which is not parsed by the current debian/rules. You cannot build it in parallel unless you pass --jobs-force instead or set the MAKEFLAGS environment variable. Debian policy [2] suggests the following code snippet for debian/rules. ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS))) NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS))) MAKEFLAGS += -j$(NUMJOBS) endif I added slightly different code to debian/rules so 'make -j N deb-pkg' works as before. In this case, the '-j N' should not be specified in debian/rules again. 'make deb-pkg' without the -j option must explicitly pass -j1 to dpkb-buildpackage because otherwise DEB_BUILD_OPTIONS contains parallel= by default. This should work with almost all Make versions Kbuild supports. Only the corner case I found not working is 'make-3.82 -j deb-pkg', which results in single thread building. It is not a big deal because -j without an argument, which does not limit the number of jobs, is rarely used. As far as I tested, the MAKEFLAGS format varies by Make versions. command line option $(MAKEFLAGS) in recipe Make 3.82 -j j -j1 -j2 -j Make 4.0/4.1 -j -j -j1 -j2 -j Make 4.2+ -j -j -j1 -j1 -j2 -j2 [1] https://salsa.debian.org/dpkg-team/dpkg/-/commit/1d0ea9b2ba3f6a2de5b1a6ff55f3df7b71f73db6 [2] https://www.debian.org/doc/debian-policy/ch-source.html#s-debianrules-options Reported-by: Bastian Germann Signed-off-by: Masahiro Yamada --- scripts/Makefile.package | 4 +++- scripts/package/debian/rules | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/Makefile.package b/scripts/Makefile.package index f8a948ec2c6b..f8b9ba4705c8 100644 --- a/scripts/Makefile.package +++ b/scripts/Makefile.package @@ -148,7 +148,9 @@ deb-pkg srcdeb-pkg bindeb-pkg: $(if $(findstring source, $(build-type)), \ --unsigned-source --compression=$(KDEB_SOURCE_COMPRESS)) \ $(if $(findstring binary, $(build-type)), \ - --rules-file='$(MAKE) -f debian/rules' -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch), \ + --rules-file='$(MAKE) -f debian/rules' \ + $(if $(filter-out -j1,$(filter -j%,$(MAKEFLAGS))),,--jobs=1) \ + -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch), \ --no-check-builddeps) \ $(DPKG_FLAGS)) diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules index 226e127efd63..4753173daaae 100755 --- a/scripts/package/debian/rules +++ b/scripts/package/debian/rules @@ -5,11 +5,13 @@ include debian/rules.vars srctree ?= . +JOBS = $(if $(filter -j%,$(MAKEFLAGS)),,$(patsubst parallel=%,-j%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))) + .PHONY: binary binary-indep binary-arch binary: binary-arch binary-indep binary-indep: build-indep binary-arch: build-arch - $(MAKE) -f $(srctree)/Makefile ARCH=$(ARCH) \ + $(MAKE) $(JOBS) -f $(srctree)/Makefile ARCH=$(ARCH) \ KERNELRELEASE=$(KERNELRELEASE) \ run-command KBUILD_RUN_COMMAND=+$(srctree)/scripts/package/builddeb @@ -17,7 +19,7 @@ binary-arch: build-arch build: build-arch build-indep build-indep: build-arch: - $(MAKE) -f $(srctree)/Makefile ARCH=$(ARCH) \ + $(MAKE) $(JOBS) -f $(srctree)/Makefile ARCH=$(ARCH) \ KERNELRELEASE=$(KERNELRELEASE) \ $(shell $(srctree)/scripts/package/deb-build-option) \ olddefconfig all @@ -25,4 +27,4 @@ build-arch: .PHONY: clean clean: rm -rf debian/files debian/linux-* - $(MAKE) -f $(srctree)/Makefile ARCH=$(ARCH) clean + $(MAKE) $(JOBS) -f $(srctree)/Makefile ARCH=$(ARCH) clean