From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 7D91F139694 for ; Sun, 30 Apr 2017 21:38:16 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C927E21C11C; Sun, 30 Apr 2017 21:38:01 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 80C9121C107 for ; Sun, 30 Apr 2017 21:37:56 +0000 (UTC) Received: from katipo2.fritz.box (unknown [IPv6:2406:e001:1:d01:de0e:a1ff:fea1:6ec4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: kentnl) by smtp.gentoo.org (Postfix) with ESMTPSA id 8C83B34169C; Sun, 30 Apr 2017 21:37:53 +0000 (UTC) From: kentnl@gentoo.org To: gentoo-dev@lists.gentoo.org Cc: vapier@gentoo.org, tools-portage@gentoo.org, Kent Fredric Subject: [gentoo-dev] [PATCH] app-portage/eclass-manpages: Add support for @DEFAULT-VALUE Date: Mon, 1 May 2017 09:37:41 +1200 Message-Id: <20170430213741.21740-1-kentnl@gentoo.org> X-Mailer: git-send-email 2.12.2 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Archives-Salt: bda47952-7a86-4e0d-9fe7-aec2e972ec36 X-Archives-Hash: f1798202613e2ca5a5e0310fea0cf24a From: Kent Fredric @DEFAULT-VALUE allows eclasses to document the default values they will inject when eclass-to-manpage can't extract it. When eclass-to-manpage *can* extract it, it adds a warning when the extracted value is different from that declared, (but the declared value still takes precedence) Note: there is a pre-exisitng poorly documented hack where # FOO=VALUE In a comment serves as a fallback for literal value parsing, which can supplement DEFAULT-VALUE in a less clear way. But due to the nature of this syntax, its not trivial to identify which eclasses are, and aren't using it as variables are routinely commented without intending them to be used as documentation. Some such commented assignments lurk in @CODE examples, which are surely not intended to be extracted as their values Subsequently, if present, @DEFAULT-VALUE will also trump any such commented assignments --- .../eclass-manpages/files/eclass-to-manpage.awk | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app-portage/eclass-manpages/files/eclass-to-manpage.awk b/app-portage/eclass-manpages/files/eclass-to-manpage.awk index 0d41f96327..d6ed59efd9 100644 --- a/app-portage/eclass-manpages/files/eclass-to-manpage.awk +++ b/app-portage/eclass-manpages/files/eclass-to-manpage.awk @@ -40,6 +40,7 @@ # [@DEFAULT_UNSET] # [@INTERNAL] # [@REQUIRED] +# @DEFAULT-VALUE: # @DESCRIPTION: # # foo="" @@ -49,6 +50,7 @@ # [@DEFAULT_UNSET] # [@INTERNAL] # [@REQUIRED] +# @DEFAULT-VALUE: # @DESCRIPTION: # # foo="" @@ -283,6 +285,7 @@ function _handle_variable() { default_unset = 0 internal = 0 required = 0 + default_value = "" # make sure people haven't specified this before (copy & paste error) if (all_vars[var_name]) @@ -299,6 +302,10 @@ function _handle_variable() { internal = 1 else if ($2 == "@REQUIRED") required = 1 + else if ($2 == "@DEFAULT-VALUE:") { + sub(/^# @[A-Z_]*:[[:space:]]*/,"") + default_value = $0 + } else opts = 0 } @@ -315,15 +322,21 @@ function _handle_variable() { op = "?=" regex = "^[[:space:]]*:[[:space:]]*[$]{" var_name ":?=(.*)}" val = gensub(regex, "\\1", 1, $0) - if (val == $0) { - if (default_unset + required + internal == 0) + } + if (default_value != "") { + if ( val != $0 && default_value != val ) + warn( var_name ": extracted different from DEFAULT-VALUE: " default_value " <=> " val ) + op = "=" + val = default_value + } + if ( val == $0 ) { + if (default_unset + required + internal == 0) warn(var_name ": unable to extract default variable content: " $0) val = "" - } else if (val !~ /^["']/ && val ~ / /) { + } else if (val !~ /^["']/ && val ~ / /) { if (default_unset == 1) warn(var_name ": marked as unset, but has value: " val) val = "\"" val "\"" - } } if (length(val)) val = " " op " \\fI" val "\\fR" -- 2.12.2