From patchwork Tue Dec 5 14:51:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Richardson X-Patchwork-Id: 134881 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2F2014367A; Tue, 5 Dec 2023 15:51:25 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1FF4A42E58; Tue, 5 Dec 2023 15:51:25 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by mails.dpdk.org (Postfix) with ESMTP id 569E642E58 for ; Tue, 5 Dec 2023 15:51:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701787882; x=1733323882; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OCsFSOn3iM4pELdEM4DDLNx4PPzoa0spQ3Fn0lz2igQ=; b=UArB9gxnBKzeKbfSrdZcRZBYiRD8ObnfIEVIGVggyhAYZedovkhnmhwC C5X9u/zDRM0G3iOuoYJt+Jt4ILfyWfBLAMclFQCcK/aOfvlcYEWnMtuN9 wlK3FTxDZKd6UJ+1+HsWgjA0k441oZ3rYQbPQBSkAyDUr9F61TjHlaPOf tdM2+IYU4kdf5X77k0k912xr4v34maz2hhEC6YJnkSblUAaaTFvz67lJM qzRg2w0mJM2YovxAmWK1Ci7Q8VCo/9jr1T1UiIH9UdENFigz/Q5zinoCa jSHl3iS7wufBoDVrqBHrTFEkevevk21B5b3FrLTBUls8SwA/hN3mXsU+f g==; X-IronPort-AV: E=McAfee;i="6600,9927,10915"; a="374089947" X-IronPort-AV: E=Sophos;i="6.04,252,1695711600"; d="scan'208";a="374089947" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Dec 2023 06:51:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10915"; a="1018234152" X-IronPort-AV: E=Sophos;i="6.04,252,1695711600"; d="scan'208";a="1018234152" Received: from unknown (HELO silpixa00401385.ir.intel.com) ([10.237.214.152]) by fmsmga006.fm.intel.com with ESMTP; 05 Dec 2023 06:51:20 -0800 From: Bruce Richardson To: dev@dpdk.org Cc: skori@marvell.com, david.marchand@redhat.com, Bruce Richardson Subject: [PATCH 1/3] buildtools/dpdk-cmdline-gen: support optional parameters Date: Tue, 5 Dec 2023 14:51:07 +0000 Message-Id: <20231205145109.1000464-2-bruce.richardson@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231205145109.1000464-1-bruce.richardson@intel.com> References: <20231205145109.1000464-1-bruce.richardson@intel.com> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sometimes a user may want to have a command which takes an optional parameter. For commands with an optional constant string, this is no issue, as it can be configured as two separate commands, e.g. start start tx_first. However, if we want to have a variable parameter on the command, we hit issues, because variable tokens do not form part of the generated command names used for function and result-struct naming. To avoid duplicate name issues, we add a special syntax to allow the user to indicate that a particular variable parameter should be included in the name. Any leading variable names starting with a "__" will be included in command naming. This then allows us to have: start start tx_first start tx_first __n without hitting any naming conflicts. Signed-off-by: Bruce Richardson Acked-by: Sunil Kumar Kori --- buildtools/dpdk-cmdline-gen.py | 9 ++++++++- doc/guides/prog_guide/cmdline.rst | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/buildtools/dpdk-cmdline-gen.py b/buildtools/dpdk-cmdline-gen.py index bf1253d949..faee4ffca7 100755 --- a/buildtools/dpdk-cmdline-gen.py +++ b/buildtools/dpdk-cmdline-gen.py @@ -40,7 +40,12 @@ def process_command(lineno, tokens, comment): name_tokens = [] for t in tokens: if t.startswith("<"): - break + # stop processing the name building at a variable token, + # UNLESS the token name starts with "__" + t_type, t_name = t[1:].split(">") + if not t_name.startswith("__"): + break + t = t_name[2:] # strip off the leading '__' name_tokens.append(t) name = "_".join(name_tokens) @@ -51,6 +56,8 @@ def process_command(lineno, tokens, comment): if t.startswith("<"): t_type, t_name = t[1:].split(">") t_val = "NULL" + if t_name.startswith("__"): + t_name = t_name[2:] else: t_type = "STRING" t_name = t diff --git a/doc/guides/prog_guide/cmdline.rst b/doc/guides/prog_guide/cmdline.rst index b804d7a328..fc32d727dc 100644 --- a/doc/guides/prog_guide/cmdline.rst +++ b/doc/guides/prog_guide/cmdline.rst @@ -155,6 +155,19 @@ To get at the results structure for each command above, the ``parsed_result`` parameter should be cast to ``struct cmd_quit_result`` or ``struct cmd_show_port_stats_result`` respectively. +.. note:: + + In some cases, the user may want to have an optional variable parameter at the end of a command. + Such a variable parameter would not normally be included in the ```` string, + leading to duplicate definition errors. + To work around this, + any variable token with a name prefixed by ``'__'`` will be included in the cmdname string, + with the prefix removed. + Using this, it is possible to have commands, such as: + ``start tx_first`` and ``start tx_first __n``, without them conflicting. + The resulting code generated will expect functions called ``cmd_start_tx_first_parsed`` + and ``cmd_start_tx_first_n_parsed`` respectively. + Integrating with the Application ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~