From patchwork Tue Jun 6 08:57:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 103688 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3264449vqr; Tue, 6 Jun 2023 02:35:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4eD9PKrWShM0Tv/xRoazmp8bhY+6BH+ghPGrwm1KcOJRvTtMFV/qup9mOaEiz60fqY/tvv X-Received: by 2002:a17:903:244d:b0:1b0:56cf:b8c0 with SMTP id l13-20020a170903244d00b001b056cfb8c0mr2254586pls.13.1686044151766; Tue, 06 Jun 2023 02:35:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686044151; cv=none; d=google.com; s=arc-20160816; b=LcY4e6+oxoSc/FMpQE+GCIiNrrC9lXODddmUxVJUe41pomk6KRpMq2lTyG+gDFyiln MVeh5OrGDOZbbUVsH4evX2rP5dRfD99MsZFpPYx8d1X2oMl3SSaPcOS0rP3R11LhoFFd t6YE58z2c4xM09ewKHqFOfc9cBIebYwAAYpckS6p27pyljn2LYTPoXWBkRT9tcUmUyU+ E4lHsKxz/E+Dy76up/xeiwi5ctw5jnQ5M8njH4eHjKjic8TtCgEwaEg7FgTz8CYrMe3Z VV/yCRWp/eBNLHNpLGCnsLzc++xy80wa2WE6+BZgLJBFs1/PJqxFYYALTuWwW7VplYxT QInA== 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=iAvSNf9q5H7Fglw+xBqescyQX0+5g18cx1WVw0mtFJM=; b=Z9uPRF5GxmEgfbrvRDg83OtfqG6hbrQfnjGnT65HaDPm4UVSPsmhYqHoa8Nnztgjpj qnvQ7W9jSU/BHrAcNasDiwXFcgXk0xfG4C99BjnpgI45gNUEf41Dqqd/IGmeFplcnawE +Z+G3Bb1W6G/bmijtCTOHqPbBHwkQNHc4MuzvlmF0XI+JCbQoE6QQL5WdSzVK0IpO1n/ WIssXo0YCI2TaS7nYKdKfqVmF3ZC94ULNpvHkV05bly6dNZkRLAcTCc17NKltSPXYkGt XWU9qIW963ITNjtWxCq/ze1WA/eZ/oZGm6+2EIK1rBBeGeOSHxV45Z67l0o5xwli3pUF TWTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=ucRmKruX; 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=REJECT dis=NONE) header.from=sipsolutions.net Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w17-20020a170902e89100b001a24521e826si7224925plg.61.2023.06.06.02.35.39; Tue, 06 Jun 2023 02:35:51 -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=@sipsolutions.net header.s=mail header.b=ucRmKruX; 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=REJECT dis=NONE) header.from=sipsolutions.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231511AbjFFI53 (ORCPT + 99 others); Tue, 6 Jun 2023 04:57:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237243AbjFFI5U (ORCPT ); Tue, 6 Jun 2023 04:57:20 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:191:4433::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 915A010D7; Tue, 6 Jun 2023 01:57:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: Message-Id:Date:Subject:Cc:To:From:Content-Type:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-To:Resent-Cc: Resent-Message-ID:In-Reply-To:References; bh=iAvSNf9q5H7Fglw+xBqescyQX0+5g18cx1WVw0mtFJM=; t=1686041835; x=1687251435; b=ucRmKruXVABKqw2i94E4yzYRB+HPv6sk4wqVlkVlVrE8DzJ2ED+brrSIvomsBO86XjbreHH9M0u R+Zg/MA3j5afqmXG0NYBtMBTRUx7bn8zOdURnWRuenCXTjpanDUBROnN6TFv+1W2B8r225g80HK7L St/kPH7gza2FGS87PNxP4zQhFlty+YGgZMioa4BKM23jkI6n+QHkHZVlx04bONT44oRBtddiGgCMm t4JDSz5PqmByALNoxitFcrwxi3BzWLeN273avf2s9Nty+Q9xzHnDvtCG5wI9nTdUlXAB572fDoX45 qrULDZr6h/CszuZdr8zJDfWrqzxaKZ2FXh1A==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1q6SV6-00FTy6-35; Tue, 06 Jun 2023 10:57:13 +0200 From: Johannes Berg To: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-doc@vger.kernel.org Cc: Masahiro Yamada , Johannes Berg Subject: [PATCH v2 1/2] kernel-doc: don't let V=1 change outcome Date: Tue, 6 Jun 2023 10:57:05 +0200 Message-Id: <20230606105706.60807b85ff79.I21ab3b54eeebd638676bead3b2f87417944e44f3@changeid> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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?1767945432442369372?= X-GMAIL-MSGID: =?utf-8?q?1767945432442369372?= From: Johannes Berg The kernel-doc script currently reports a number of issues only in "verbose" mode, but that's initialized from V=1 (via KBUILD_VERBOSE), so if you use KDOC_WERROR=1 then adding V=1 might actually break the build. This is rather unexpected. Change kernel-doc to not change its behaviour wrt. errors (or warnings) when verbose mode is enabled, but rather add separate warning flags (and -Wall) for it. Allow enabling those flags via environment/make variables in the kernel's build system for easier user use, but to not have to parse them in the script itself. Signed-off-by: Johannes Berg Acked-by: Jonathan Corbet --- v2: - parse environment variables in build system rather than the script itself, as suggested by Masahiro Yamada - fix indentation --- scripts/Makefile.build | 7 ++++++- scripts/kernel-doc | 28 +++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 9f94fc83f086..90bb5badb0e9 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -101,7 +101,12 @@ else ifeq ($(KBUILD_CHECKSRC),2) endif ifneq ($(KBUILD_EXTRA_WARN),) - cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $< + cmd_checkdoc = $(srctree)/scripts/kernel-doc -none \ + $(if $(KDOC_WALL), -Wall) \ + $(if $(KDOC_WRETURN), -Wreturn) \ + $(if $(KDOC_WSHORT_DESC), -Wshort-desc) \ + $(if $(KDOC_WSHORT_DESC), -Wcontents-before-sections) \ + $< endif # Compile C sources (.c) diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 2486689ffc7b..8f8440870a0f 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc @@ -23,7 +23,7 @@ kernel-doc - Print formatted kernel documentation to stdout =head1 SYNOPSIS - kernel-doc [-h] [-v] [-Werror] + kernel-doc [-h] [-v] [-Werror] [-Wall] [-Wreturn] [-Wshort-description] [-Wcontents-before-sections] [ -man | -rst [-sphinx-version VERSION] [-enable-lineno] | -none @@ -133,6 +133,9 @@ my $dohighlight = ""; my $verbose = 0; my $Werror = 0; +my $Wreturn = 0; +my $Wshort_desc = 0; +my $Wcontents_before_sections = 0; my $output_mode = "rst"; my $output_preformatted = 0; my $no_doc_sections = 0; @@ -187,9 +190,14 @@ if (defined($ENV{'KCFLAGS'})) { } } +# reading this variable is for backwards compat just in case +# someone was calling it with the variable from outside the +# kernel's build system if (defined($ENV{'KDOC_WERROR'})) { $Werror = "$ENV{'KDOC_WERROR'}"; } +# other environment variables are converted to command-line +# arguments in cmd_checkdoc in the build system # Generated docbook code is inserted in a template at a point where # docbook v3.1 requires a non-zero sequence of RefEntry's; see: @@ -318,6 +326,16 @@ while ($ARGV[0] =~ m/^--?(.*)/) { $verbose = 1; } elsif ($cmd eq "Werror") { $Werror = 1; + } elsif ($cmd eq "Wreturn") { + $Wreturn = 1; + } elsif ($cmd eq "Wshort-desc") { + $Wshort_desc = 1; + } elsif ($cmd eq "Wcontents-before-sections") { + $Wcontents_before_sections = 1; + } elsif ($cmd eq "Wall") { + $Wreturn = 1; + $Wshort_desc = 1; + $Wcontents_before_sections = 1; } elsif (($cmd eq "h") || ($cmd eq "help")) { pod2usage(-exitval => 0, -verbose => 2); } elsif ($cmd eq 'no-doc-sections') { @@ -1748,9 +1766,9 @@ sub dump_function($$) { # This check emits a lot of warnings at the moment, because many # functions don't have a 'Return' doc section. So until the number # of warnings goes sufficiently down, the check is only performed in - # verbose mode. + # -Wreturn mode. # TODO: always perform the check. - if ($verbose && !$noret) { + if ($Wreturn && !$noret) { check_return_section($file, $declaration_name, $return_type); } @@ -2054,7 +2072,7 @@ sub process_name($$) { $state = STATE_NORMAL; } - if (($declaration_purpose eq "") && $verbose) { + if (($declaration_purpose eq "") && $Wshort_desc) { emit_warning("${file}:$.", "missing initial short description on line:\n$_"); } @@ -2103,7 +2121,7 @@ sub process_body($$) { } if (($contents ne "") && ($contents ne "\n")) { - if (!$in_doc_sect && $verbose) { + if (!$in_doc_sect && $Wcontents_before_sections) { emit_warning("${file}:$.", "contents before sections\n"); } dump_section($file, $section, $contents);