From patchwork Thu Dec 29 09:15:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 37334 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2310979wrt; Thu, 29 Dec 2022 01:22:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXtmFrxE+85c2Jba7uPeoRCJEviub6lEjxG3eTl4BE1LsmnzkuxpMpdrFT9J1HjYyX4iDPzo X-Received: by 2002:a17:902:7584:b0:191:35c9:db30 with SMTP id j4-20020a170902758400b0019135c9db30mr27299910pll.5.1672305745213; Thu, 29 Dec 2022 01:22:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672305745; cv=none; d=google.com; s=arc-20160816; b=ZwN0QD5mqfpup0ZsJpcdBAmNGTV69R+ZYVBwUJwZ2kl/oOyegKhZJwMMsUnqQimSn5 YbQ/5yEbqPfvGF8fYvYwJa8AI9OqqrUwIWgfJJKXUjoGyoD1yZyYK+LBgzIQPv78aF9P wQBzEdX7v2cgZueK8jWPfraxw3+Tv1QPKiUByTZYZgRJwXft8VsTI1R4eMCzNIWo0eQ7 9I81sVioODxoxveyI252+VCvKXhJwPVMaHv7b/dHwqy2dIhfCZ3zzAEO2EAgFDn4OwMs 28uwXKtqJDfoD+fHFo535GylQqazZ0oMMsle6axun+4CSrOICw/l55oD3f/1lTi78MFs /6dw== 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=M+g5UOa+thTat/Ha3HXP7xMUaH/j7DEkp1pAHfBc9R4=; b=q+IgYtAQHyo4i4REMpd0OkC4DWS1c0/nze+7XDkLKc1eHFsNCCdreR/FOBf1JY71lE VnPH0E06AiWhULEdm/os21C72MfLPUiXLJauhGcKETrINP+pNEZL0zjsbb78yd0cjFZE mimm+mjrHildcYle+0dKtE9MPRwNPbCAuZFUFQIOiBVeBjR52CJwQSc0pYhzKiwsy+oz m/HFbMTdS1QGfdSt59sUitm72Wxyl6yPUEsuVFTaHriOZdzEus8mnn7HCA6u0++FXa3b DWPURVgMVKqrIU9xTWLenIBKiG+WZ9a6jG2KS8CMnCsc6YRYmjWyi69cRo2AvLS7Aea0 1Utw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UcEFphRE; 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 q7-20020a170902a3c700b00189ed8594bbsi17508591plb.64.2022.12.29.01.22.13; Thu, 29 Dec 2022 01:22:25 -0800 (PST) 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=UcEFphRE; 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 S233108AbiL2JPP (ORCPT + 99 others); Thu, 29 Dec 2022 04:15:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231280AbiL2JPL (ORCPT ); Thu, 29 Dec 2022 04:15:11 -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 CAF2C638B; Thu, 29 Dec 2022 01:15:09 -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 558DB61739; Thu, 29 Dec 2022 09:15:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E927C433F0; Thu, 29 Dec 2022 09:15:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672305308; bh=wtSs6J9YLnzQPlTY0VzKME94in4y1oLZtAIe70huUqE=; h=From:To:Cc:Subject:Date:From; b=UcEFphREvL1CSWRfHNQSiBEvCbzdCYvSblsfY1GzZ55jhvhdsI8UsH3HDdlRpF/t1 2XdtBz6nmOMBxobkhx1IehWgBZO/SRgpd1EyGEdEVe2pAmXmaGlOr6j88E95Ewl5jK ljZ7wtS9XwHgydVIhHN0foW/zfZGSU/8rvAGhfNJSVpAY86ZZebOTb21AJQDb9dmWu QCSp3xt5DO+pEzAJGahamtTCdcKPMyCjsvQmXIU+2gyFMzj22jCmSCl5izvROR0YTg LbeSmZsEIJOo2RrmkX8wYpS9iPsuWg5fWgzqOoQMXJ1QkgS7w1oppvJS9GmOjR7aLq aukoscZ3qYCzw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Tom Rix , llvm@lists.linux.dev Subject: [PATCH 1/2] kbuild: rename cmd_$@ to savedcmd_$@ in *.cmd files Date: Thu, 29 Dec 2022 18:15:00 +0900 Message-Id: <20221229091501.916296-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753539668770440861?= X-GMAIL-MSGID: =?utf-8?q?1753539668770440861?= The cmd-check macro compares $(cmd_$@) and $(cmd_$1), but a pitfall is that you cannot use cmd_ as the variable name for the command. For example, the following code will not work in the top Makefile or ./Kbuild. quiet_cmd_foo = GEN $@ cmd_foo = touch $@ targets += foo foo: FORCE $(call if_changed,foo) In this case, both $@ and $1 are expanded to 'foo', so $(cmd_check) is always empty. We do not need to use the same prefix for cmd_$@ and cmd_$1. Rename the former to savedcmd_$@. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- scripts/Kbuild.include | 8 ++++---- scripts/Makefile.modfinal | 2 +- scripts/basic/fixdep.c | 4 ++-- scripts/clang-tools/gen_compile_commands.py | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 10cf8d2d82ef..1a7514f49089 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -170,10 +170,10 @@ cmd = @$(if $(cmd_$(1)),set -e; $($(quiet)log_print) $(delete-on-interrupt) $(cm ifneq ($(KBUILD_NOCMDDEP),1) # Check if both commands are the same including their order. Result is empty # string if equal. User may override this check using make KBUILD_NOCMDDEP=1 -cmd-check = $(filter-out $(subst $(space),$(space_escape),$(strip $(cmd_$@))), \ +cmd-check = $(filter-out $(subst $(space),$(space_escape),$(strip $(savedcmd_$@))), \ $(subst $(space),$(space_escape),$(strip $(cmd_$1)))) else -cmd-check = $(if $(strip $(cmd_$@)),,1) +cmd-check = $(if $(strip $(savedcmd_$@)),,1) endif # Replace >$< with >$$< to preserve $ when reloading the .cmd file @@ -199,7 +199,7 @@ if_changed = $(if $(if-changed-cond),$(cmd_and_savecmd),@:) cmd_and_savecmd = \ $(cmd); \ - printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd + printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd # Execute the command and also postprocess generated .d dependencies file. if_changed_dep = $(if $(if-changed-cond),$(cmd_and_fixdep),@:) @@ -239,7 +239,7 @@ _why = \ $(if $(wildcard $@), \ $(if $(newer-prereqs),- due to: $(newer-prereqs), \ $(if $(cmd-check), \ - $(if $(cmd_$@),- due to command line change, \ + $(if $(savedcmd_$@),- due to command line change, \ $(if $(filter $@, $(targets)), \ - due to missing .cmd file, \ - due to $(notdir $@) not in $$(targets) \ diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal index a30d5b08eee9..4703f652c009 100644 --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -54,7 +54,7 @@ newer_prereqs_except = $(filter-out $(PHONY) $(1),$?) # Same as if_changed, but allows to exclude specified extra dependencies if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \ $(cmd); \ - printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) + printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) # Re-generate module BTFs if either module's .ko or vmlinux changed %.ko: %.o %.mod.o scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),vmlinux) FORCE diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index 2328f9a641da..7a408bb97478 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -70,7 +70,7 @@ * * It first generates a line * - * cmd_ = + * savedcmd_ = * * and then basically copies the ..d file to stdout, in the * process filtering out the dependency on autoconf.h and adding @@ -344,7 +344,7 @@ int main(int argc, char *argv[]) target = argv[2]; cmdline = argv[3]; - printf("cmd_%s := %s\n\n", target, cmdline); + printf("savedcmd_%s := %s\n\n", target, cmdline); buf = read_file(depfile); parse_dep_file(buf, target); diff --git a/scripts/clang-tools/gen_compile_commands.py b/scripts/clang-tools/gen_compile_commands.py index 0227522959a4..15ba56527acd 100755 --- a/scripts/clang-tools/gen_compile_commands.py +++ b/scripts/clang-tools/gen_compile_commands.py @@ -19,7 +19,7 @@ _DEFAULT_OUTPUT = 'compile_commands.json' _DEFAULT_LOG_LEVEL = 'WARNING' _FILENAME_PATTERN = r'^\..*\.cmd$' -_LINE_PATTERN = r'^cmd_[^ ]*\.o := (.* )([^ ]*\.c) *(;|$)' +_LINE_PATTERN = r'^savedcmd_[^ ]*\.o := (.* )([^ ]*\.c) *(;|$)' _VALID_LOG_LEVELS = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] # The tools/ directory adopts a different build system, and produces .cmd # files in a different format. Do not support it. From patchwork Thu Dec 29 09:15:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 37335 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2311152wrt; Thu, 29 Dec 2022 01:23:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXv2GNpy+eTUCVRxsrckbDhSHlpPkmXJPjf0/92+hn5Ov7ECT+LONqUSrhLC837RMj8aHk5I X-Received: by 2002:a17:907:1385:b0:7c1:6167:7816 with SMTP id vs5-20020a170907138500b007c161677816mr19391034ejb.28.1672305780604; Thu, 29 Dec 2022 01:23:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672305780; cv=none; d=google.com; s=arc-20160816; b=qARZU/gdGXeOKIuPPMzcki85hxzUPhotbejsa6wVLYwxaof+oC+9FNb1kbarTl5P2S jqBOKptn8/U2Efoe3XFzTQSYoOF553GOg/5521zD0RCvyCCSLVRtODT6G2p5dldUJ+D0 dfH67EZwuxF2zCLpV1Ses6oUrhRTcxRxPTKGGajej3dlfaW5tEY3t70eJb9Omkpe4A35 rA41PZtpnImdBhPlLGl70leR0yWs9Qp07/Xtrt4W2fGY8W283Eyiwda8Qeu51gHh8ylA MIoAw1+XPRBKcRAKDxhYAsKCd0AL92L+Uq1zaLivOtMA7L/WSw23mz2YVdUZxWFqw9EQ Fh/A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XvwX8D6Ma4lU/pDRWuwISOPaC6h7eZe/Om5PDjQzuT4=; b=tODgPO8IXjJqNLpm7pWRDunaiATyAdULbyfsWYrJBwZn5fZLGGbQNwp/G5xjZJuKsH 9+NC155dvVjwYA0UFXCaFVwnZDG9XS13//gea+xScwStwCLtb9+5b9Wc85QfBf4JJQ1T hkJ0ffw/I7dhpPGXfk12yGfvLJrl80AkP2Sh3Cm/bDnd8UXYkbnciQ/w3bZgphfw8GW+ 3C/nLhcGCmAYfJeiMwiNL9r+D5NX5Cxx0OdYLQF1r1xcKVpOam6sBFN3wnfD74/lZdDq lMaef090LksJrvFGmQZmTdCa21XDetQ+jHvK/wFo6gdzkrvqgA0AuezUJ3kMu554Mr3+ Zeww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=od+ifUeG; 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 w12-20020a056402268c00b0046dc6205bc3si16516091edd.460.2022.12.29.01.22.36; Thu, 29 Dec 2022 01:23:00 -0800 (PST) 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=od+ifUeG; 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 S233139AbiL2JPX (ORCPT + 99 others); Thu, 29 Dec 2022 04:15:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230237AbiL2JPM (ORCPT ); Thu, 29 Dec 2022 04:15:12 -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 A4907B878; Thu, 29 Dec 2022 01:15:11 -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 3C35761736; Thu, 29 Dec 2022 09:15:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 349E8C433F1; Thu, 29 Dec 2022 09:15:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672305310; bh=eWNkQZA1QG5UrTZIG/e9yXi6rO1HLZ2+3IAAewb9dNc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=od+ifUeGcuIM05gq4YB+UpsmTXjM2YP4OJJnk54ZAHgO/usJ1qKAD3qtgV7iXV3H4 NBiScj9r7wWrJO2r6v13M15DzHMVV4yLI6NZE0mJ2jxWsesitknhwFNsWS/z23lmxt vMRS/TY31GaPBX/C/gr7nM4uPIG9+mnnEyLUstQOJK7Y68f2A4SU4EDPNeSROyjnHJ b+aODD7Z11nTTwWwcC+6VL/j5xUI4ANJQAsdPY+g+JqKIbcYQTP94k4ekGnCpomr4b AMRfdtt5wJnLxgstVw/gN63sVkpAvPRtU+54xnQjN0coJP7yGQFEmcVX7iPy9egkK3 qtf/vew5vN4sg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier Subject: [PATCH 2/2] kbuild: add more comments for KBUILD_NOCMDDEP=1 Date: Thu, 29 Dec 2022 18:15:01 +0900 Message-Id: <20221229091501.916296-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221229091501.916296-1-masahiroy@kernel.org> References: <20221229091501.916296-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753539705899492511?= X-GMAIL-MSGID: =?utf-8?q?1753539705899492511?= The cmd-check for KBUILD_NOCMDDEP=1 may not be clear until you see commit c4d5ee13984f ("kbuild: make KBUILD_NOCMDDEP=1 handle empty built-in.o"). When a phony target (i.e. FORCE) is the only prerequisite, Kbuild uses a tricky way to detect that the target does not exist. Add more comments. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- scripts/Kbuild.include | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 1a7514f49089..4648ab8f11d4 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -170,9 +170,13 @@ cmd = @$(if $(cmd_$(1)),set -e; $($(quiet)log_print) $(delete-on-interrupt) $(cm ifneq ($(KBUILD_NOCMDDEP),1) # Check if both commands are the same including their order. Result is empty # string if equal. User may override this check using make KBUILD_NOCMDDEP=1 +# If the target does not exist, the *.cmd file should not be included so +# $(savedcmd_$@) gets empty. Then, target will be built even if $(newer-prereqs) +# happens to become empty. cmd-check = $(filter-out $(subst $(space),$(space_escape),$(strip $(savedcmd_$@))), \ $(subst $(space),$(space_escape),$(strip $(cmd_$1)))) else +# We still need to detect missing targets. cmd-check = $(if $(strip $(savedcmd_$@)),,1) endif @@ -186,6 +190,8 @@ make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1)))) # Find any prerequisites that are newer than target or that do not exist. # PHONY targets skipped in both cases. +# If there is no prerequisite other than phony targets, $(newer-prereqs) becomes +# empty even if the target does not exist. cmd-check saves this corner case. newer-prereqs = $(filter-out $(PHONY),$?) # It is a typical mistake to forget the FORCE prerequisite. Check it here so