From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 1364942361;
	Wed, 11 Oct 2023 15:34:42 +0200 (CEST)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 655EA40A79;
	Wed, 11 Oct 2023 15:34:18 +0200 (CEST)
Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136])
 by mails.dpdk.org (Postfix) with ESMTP id 799C040A75
 for <dev@dpdk.org>; Wed, 11 Oct 2023 15:34:16 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1697031256; x=1728567256;
 h=from:to:cc:subject:date:message-id:in-reply-to:
 references:mime-version:content-transfer-encoding;
 bh=Si2td+8Vm6nRBSEIPNkk58iqmtLPH4XTbWIJFc8Dgxs=;
 b=YZb7eyBJKXHnH8PhoYkBThjEWJmNkMPjBM2flnRU0V2YHylgxyEi2wNL
 We2+oot/wi+3Fr7xDbOxQubTOwCRZ0mkM4vRJQHnpCJ9rTgT0h3gBuIlo
 gyt53B5E1gyff3GLtz4Ub5YJlAS8/zPyCXetjmi17U5JKyfBZKtxJ9cRN
 atvgdDhqbLW58AFVrA4eViKybRs685ddKzeB/zFVcnoM3KwSrwLkDfGb3
 FHeOuFL2R0PKqcwc5uWc9I3jAG5g/hUbvrxo5MksIUx+D8g1c9EETGVcf
 CyzhAeu0K/s/sRdY6/jQ6PkJJSmVIU+IbdrULIfqmR53EBFVrJxrLusZ/ Q==;
X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="364025735"
X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="364025735"
Received: from fmsmga006.fm.intel.com ([10.253.24.20])
 by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 11 Oct 2023 06:34:16 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="1001111904"
X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="1001111904"
Received: from unknown (HELO silpixa00401385.ir.intel.com) ([10.237.214.46])
 by fmsmga006.fm.intel.com with ESMTP; 11 Oct 2023 06:34:14 -0700
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>,
 Anatoly Burakov <anatoly.burakov@intel.com>
Subject: [PATCH v3 4/5] examples/hotplug_mp: auto-generate cmdline boilerplate
Date: Wed, 11 Oct 2023 14:33:56 +0100
Message-Id: <20231011133357.111058-5-bruce.richardson@intel.com>
X-Mailer: git-send-email 2.39.2
In-Reply-To: <20231011133357.111058-1-bruce.richardson@intel.com>
References: <20230802170052.955323-1-bruce.richardson@intel.com>
 <20231011133357.111058-1-bruce.richardson@intel.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

Use the dpdk-cmdline-gen script to autogenerate all the boilerplate
structs and defines for the commandline part of the app.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 examples/multi_process/hotplug_mp/Makefile    |  12 +-
 examples/multi_process/hotplug_mp/commands.c  | 147 ++----------------
 examples/multi_process/hotplug_mp/commands.h  |  10 --
 .../multi_process/hotplug_mp/commands.list    |   5 +
 examples/multi_process/hotplug_mp/meson.build |   9 ++
 5 files changed, 35 insertions(+), 148 deletions(-)
 delete mode 100644 examples/multi_process/hotplug_mp/commands.h
 create mode 100644 examples/multi_process/hotplug_mp/commands.list

diff --git a/examples/multi_process/hotplug_mp/Makefile b/examples/multi_process/hotplug_mp/Makefile
index 6b20d6e49a..81ee85cd6b 100644
--- a/examples/multi_process/hotplug_mp/Makefile
+++ b/examples/multi_process/hotplug_mp/Makefile
@@ -6,6 +6,7 @@ APP = hotplug_mp
 
 # all source are stored in SRCS-y
 SRCS-y := main.c commands.c
+SRC-DEPS := build/commands.h
 
 PKGCONF ?= pkg-config
 
@@ -22,10 +23,13 @@ static: build/$(APP)-static
 	ln -sf $(APP)-static build/$(APP)
 
 PC_FILE := $(shell $(PKGCONF) --path libdpdk 2>/dev/null)
-CFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk)
+CFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk) -I build/
 LDFLAGS_SHARED = $(shell $(PKGCONF) --libs libdpdk)
 LDFLAGS_STATIC = $(shell $(PKGCONF) --static --libs libdpdk)
 
+build/commands.h: commands.list Makefile
+	dpdk-cmdline-gen.py -o $@ --context-name=main_ctx $<
+
 ifeq ($(MAKECMDGOALS),static)
 # check for broken pkg-config
 ifeq ($(shell echo $(LDFLAGS_STATIC) | grep 'whole-archive.*l:lib.*no-whole-archive'),)
@@ -36,10 +40,10 @@ endif
 
 CFLAGS += -DALLOW_EXPERIMENTAL_API
 
-build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build
+build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(SRC-DEPS)
 	$(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
 
-build/$(APP)-static: $(SRCS-y) Makefile $(PC_FILE) | build
+build/$(APP)-static: $(SRCS-y) Makefile $(PC_FILE) | build  $(SRC-DEPS)
 	$(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_STATIC)
 
 build:
@@ -47,5 +51,5 @@ build:
 
 .PHONY: clean
 clean:
-	rm -f build/$(APP) build/$(APP)-static build/$(APP)-shared
+	rm -f build/$(APP) build/$(APP)-static build/$(APP)-shared build/commands.h
 	test -d build && rmdir -p build || true
diff --git a/examples/multi_process/hotplug_mp/commands.c b/examples/multi_process/hotplug_mp/commands.c
index 88f44e00a0..900eb9f774 100644
--- a/examples/multi_process/hotplug_mp/commands.c
+++ b/examples/multi_process/hotplug_mp/commands.c
@@ -1,24 +1,12 @@
 /* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2018 Intel Corporation.
+ * Copyright(c) 2018-2023 Intel Corporation.
  */
 
-#include <cmdline_rdline.h>
-#include <cmdline_parse.h>
-#include <cmdline_parse_ipaddr.h>
-#include <cmdline_parse_num.h>
-#include <cmdline_parse_string.h>
-#include <cmdline.h>
-
 #include <rte_bus.h>
 #include <rte_ethdev.h>
+#include "commands.h"
 
-/**********************************************************/
-
-struct cmd_help_result {
-	cmdline_fixed_string_t help;
-};
-
-static void cmd_help_parsed(__rte_unused void *parsed_result,
+void cmd_help_parsed(__rte_unused void *parsed_result,
 			    struct cmdline *cl,
 			    __rte_unused void *data)
 {
@@ -29,52 +17,16 @@ static void cmd_help_parsed(__rte_unused void *parsed_result,
 		       "- list\n\n");
 }
 
-cmdline_parse_token_string_t cmd_help_help =
-	TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, "help");
-
-cmdline_parse_inst_t cmd_help = {
-	.f = cmd_help_parsed,  /* function to call */
-	.data = NULL,      /* 2nd arg of func */
-	.help_str = "show help",
-	.tokens = {        /* token list, NULL terminated */
-		(void *)&cmd_help_help,
-		NULL,
-	},
-};
-
-/**********************************************************/
-
-struct cmd_quit_result {
-	cmdline_fixed_string_t quit;
-};
-
-static void cmd_quit_parsed(__rte_unused void *parsed_result,
+void
+cmd_quit_parsed(__rte_unused void *parsed_result,
 			    struct cmdline *cl,
 			    __rte_unused void *data)
 {
 	cmdline_quit(cl);
 }
 
-cmdline_parse_token_string_t cmd_quit_quit =
-	TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
-
-cmdline_parse_inst_t cmd_quit = {
-	.f = cmd_quit_parsed,  /* function to call */
-	.data = NULL,      /* 2nd arg of func */
-	.help_str = "quit",
-	.tokens = {        /* token list, NULL terminated */
-		(void *)&cmd_quit_quit,
-		NULL,
-	},
-};
-
-/**********************************************************/
-
-struct cmd_list_result {
-	cmdline_fixed_string_t list;
-};
-
-static void cmd_list_parsed(__rte_unused void *parsed_result,
+void
+cmd_list_parsed(__rte_unused void *parsed_result,
 			    struct cmdline *cl,
 			    __rte_unused void *data)
 {
@@ -92,31 +44,12 @@ static void cmd_list_parsed(__rte_unused void *parsed_result,
 	}
 }
 
-cmdline_parse_token_string_t cmd_list_list =
-	TOKEN_STRING_INITIALIZER(struct cmd_list_result, list, "list");
-
-cmdline_parse_inst_t cmd_list = {
-	.f = cmd_list_parsed,  /* function to call */
-	.data = NULL,      /* 2nd arg of func */
-	.help_str = "list all devices",
-	.tokens = {        /* token list, NULL terminated */
-		(void *)&cmd_list_list,
-		NULL,
-	},
-};
-
-/**********************************************************/
-
-struct cmd_dev_attach_result {
-	cmdline_fixed_string_t attach;
-	cmdline_fixed_string_t devargs;
-};
-
-static void cmd_dev_attach_parsed(void *parsed_result,
+void
+cmd_attach_parsed(void *parsed_result,
 				  struct cmdline *cl,
 				  __rte_unused void *data)
 {
-	struct cmd_dev_attach_result *res = parsed_result;
+	struct cmd_attach_result *res = parsed_result;
 	struct rte_devargs da;
 
 	memset(&da, 0, sizeof(da));
@@ -134,35 +67,12 @@ static void cmd_dev_attach_parsed(void *parsed_result,
 	rte_devargs_reset(&da);
 }
 
-cmdline_parse_token_string_t cmd_dev_attach_attach =
-	TOKEN_STRING_INITIALIZER(struct cmd_dev_attach_result, attach,
-				 "attach");
-cmdline_parse_token_string_t cmd_dev_attach_devargs =
-	TOKEN_STRING_INITIALIZER(struct cmd_dev_attach_result, devargs, NULL);
-
-cmdline_parse_inst_t cmd_attach_device = {
-	.f = cmd_dev_attach_parsed,  /* function to call */
-	.data = NULL,      /* 2nd arg of func */
-	.help_str = "attach a device",
-	.tokens = {        /* token list, NULL terminated */
-		(void *)&cmd_dev_attach_attach,
-		(void *)&cmd_dev_attach_devargs,
-		NULL,
-	},
-};
-
-/**********************************************************/
-
-struct cmd_dev_detach_result {
-	cmdline_fixed_string_t detach;
-	cmdline_fixed_string_t devargs;
-};
-
-static void cmd_dev_detach_parsed(void *parsed_result,
+void
+cmd_detach_parsed(void *parsed_result,
 				   struct cmdline *cl,
 				   __rte_unused void *data)
 {
-	struct cmd_dev_detach_result *res = parsed_result;
+	struct cmd_detach_result *res = parsed_result;
 	struct rte_devargs da;
 
 	memset(&da, 0, sizeof(da));
@@ -181,34 +91,3 @@ static void cmd_dev_detach_parsed(void *parsed_result,
 			da.name);
 	rte_devargs_reset(&da);
 }
-
-cmdline_parse_token_string_t cmd_dev_detach_detach =
-	TOKEN_STRING_INITIALIZER(struct cmd_dev_detach_result, detach,
-				 "detach");
-
-cmdline_parse_token_string_t cmd_dev_detach_devargs =
-	TOKEN_STRING_INITIALIZER(struct cmd_dev_detach_result, devargs, NULL);
-
-cmdline_parse_inst_t cmd_detach_device = {
-	.f = cmd_dev_detach_parsed,  /* function to call */
-	.data = NULL,      /* 2nd arg of func */
-	.help_str = "detach a device",
-	.tokens = {        /* token list, NULL terminated */
-		(void *)&cmd_dev_detach_detach,
-		(void *)&cmd_dev_detach_devargs,
-		NULL,
-	},
-};
-
-/**********************************************************/
-/**********************************************************/
-/****** CONTEXT (list of instruction) */
-
-cmdline_parse_ctx_t main_ctx[] = {
-	(cmdline_parse_inst_t *)&cmd_help,
-	(cmdline_parse_inst_t *)&cmd_quit,
-	(cmdline_parse_inst_t *)&cmd_list,
-	(cmdline_parse_inst_t *)&cmd_attach_device,
-	(cmdline_parse_inst_t *)&cmd_detach_device,
-	NULL,
-};
diff --git a/examples/multi_process/hotplug_mp/commands.h b/examples/multi_process/hotplug_mp/commands.h
deleted file mode 100644
index afcf177dba..0000000000
--- a/examples/multi_process/hotplug_mp/commands.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2018 Intel Corporation
- */
-
-#ifndef _COMMANDS_H_
-#define _COMMANDS_H_
-
-extern cmdline_parse_ctx_t main_ctx[];
-
-#endif /* _COMMANDS_H_ */
diff --git a/examples/multi_process/hotplug_mp/commands.list b/examples/multi_process/hotplug_mp/commands.list
new file mode 100644
index 0000000000..e3de503965
--- /dev/null
+++ b/examples/multi_process/hotplug_mp/commands.list
@@ -0,0 +1,5 @@
+attach <STRING>devargs     # attach a device
+detach <STRING>devargs     # detach a device
+list                       # list all devices
+help                       # show help
+quit                       # quit
diff --git a/examples/multi_process/hotplug_mp/meson.build b/examples/multi_process/hotplug_mp/meson.build
index a1ad98ca2e..7a0e9ca47a 100644
--- a/examples/multi_process/hotplug_mp/meson.build
+++ b/examples/multi_process/hotplug_mp/meson.build
@@ -7,7 +7,16 @@
 # DPDK instance, use 'make'
 
 allow_experimental_apis = true
+
+cmd_h = custom_target('commands_hdr',
+	output: 'commands.h',
+	input: files('commands.list'),
+	capture: true,
+	command: [cmdline_gen_cmd, '--context-name=main_ctx', '@INPUT@']
+)
+
 sources = files(
         'commands.c',
         'main.c',
 )
+sources += cmd_h
-- 
2.39.2