From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3F158A0032; Mon, 18 Jul 2022 15:26:55 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6D2F942B83; Mon, 18 Jul 2022 15:26:22 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mails.dpdk.org (Postfix) with ESMTP id 1319740DF6 for ; Mon, 18 Jul 2022 15:26:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658150776; x=1689686776; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UKOeBB4jfHy8qzsuk44emkAEXr1Jv/Z0+d4QN/W5qSQ=; b=KywLSb20LJpOuKorLfCmQCDuWVZYHT1KDroPh9ml1fbkFPpkHlaQy7Jr hMSaxLFKNb9pKvZOBQ4RgyFKY9mD0aSQG3ErFofZhVODs38JcHEDiOBvi sbaqld1Up6ulBxxf0aH6fQsQIMMq1AzxS5Ku6kr9MLT7nvG2Ln4TPo/cc nbPNIYaJ6Rhdygefj6rXp2a7W7HjfoYR2NHhhRYT2UyKYCH1wHdMmCeDp 1c1ExtdGUYrCevlIKl0B8z+U7jEZsTRhDez04G/6dc0xLsxj09I5yztb8 fjEZRsk18Sm1kMdclzLo3F4VLn5dpJnf/Rx2JX8Cnbj1YqLP7F1gkV+Sh w==; X-IronPort-AV: E=McAfee;i="6400,9594,10411"; a="284974539" X-IronPort-AV: E=Sophos;i="5.92,281,1650956400"; d="scan'208";a="284974539" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jul 2022 06:26:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,281,1650956400"; d="scan'208";a="655275292" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by fmsmga008.fm.intel.com with ESMTP; 18 Jul 2022 06:26:12 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Cc: "Kamalakannan R ." Subject: [PATCH V2 8/9] examples/pipeline: add CLI command for shared library build Date: Mon, 18 Jul 2022 13:26:02 +0000 Message-Id: <20220718132603.339314-8-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220718132603.339314-1-cristian.dumitrescu@intel.com> References: <20220718130713.339003-1-cristian.dumitrescu@intel.com> <20220718132603.339314-1-cristian.dumitrescu@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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add CLI command for the shared object library build operation. Signed-off-by: Cristian Dumitrescu Signed-off-by: Kamalakannan R. --- examples/pipeline/cli.c | 147 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 143 insertions(+), 4 deletions(-) diff --git a/examples/pipeline/cli.c b/examples/pipeline/cli.c index fdaf5dd16b..f1d2fbf52d 100644 --- a/examples/pipeline/cli.c +++ b/examples/pipeline/cli.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -25,6 +26,10 @@ #define CMD_MAX_TOKENS 256 #endif +#ifndef MAX_LINE_SIZE +#define MAX_LINE_SIZE 2048 +#endif + #define MSG_OUT_OF_MEMORY "Not enough memory.\n" #define MSG_CMD_UNKNOWN "Unknown command \"%s\".\n" #define MSG_CMD_UNIMPLEM "Command \"%s\" not implemented.\n" @@ -1030,6 +1035,130 @@ cmd_pipeline_codegen(char **tokens, return; } } + +static const char cmd_pipeline_libbuild_help[] = +"pipeline libbuild \n"; + +static void +cmd_pipeline_libbuild(char **tokens, + uint32_t n_tokens, + char *out, + size_t out_size, + void *obj __rte_unused) +{ + char *code_file, *lib_file, *obj_file = NULL, *log_file = NULL; + char *install_dir, *buffer = NULL; + size_t length; + int status = 0; + + if (n_tokens != 4) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + goto free; + } + + install_dir = getenv("RTE_INSTALL_DIR"); + if (!install_dir) { + snprintf(out, out_size, "Error: Environment variable RTE_INSTALL_DIR is not set."); + return; + } + + snprintf(out, out_size, "Using DPDK source code from \"%s\".\n", install_dir); + out_size -= strlen(out); + out += strlen(out); + + code_file = tokens[2]; + length = strnlen(code_file, MAX_LINE_SIZE); + if ((length < 3) || + (code_file[length - 2] != '.') || + (code_file[length - 1] != 'c')) { + snprintf(out, out_size, MSG_ARG_INVALID, "code_file"); + goto free; + } + + lib_file = tokens[3]; + length = strnlen(lib_file, MAX_LINE_SIZE); + if ((length < 4) || + (lib_file[length - 3] != '.') || + (lib_file[length - 2] != 's') || + (lib_file[length - 1] != 'o')) { + snprintf(out, out_size, MSG_ARG_INVALID, "lib_file"); + goto free; + } + + obj_file = malloc(length); + log_file = malloc(length + 2); + if (!obj_file || !log_file) { + snprintf(out, out_size, MSG_OUT_OF_MEMORY); + goto free; + } + + memcpy(obj_file, lib_file, length - 2); + obj_file[length - 2] = 'o'; + obj_file[length - 1] = 0; + + memcpy(log_file, lib_file, length - 2); + log_file[length - 2] = 'l'; + log_file[length - 1] = 'o'; + log_file[length] = 'g'; + log_file[length + 1] = 0; + + buffer = malloc(MAX_LINE_SIZE); + if (!buffer) { + snprintf(out, out_size, MSG_OUT_OF_MEMORY); + return; + } + + snprintf(buffer, + MAX_LINE_SIZE, + "gcc -c -O3 -fpic -Wno-deprecated-declarations -o %s %s " + "-I %s/lib/pipeline " + "-I %s/lib/eal/include " + "-I %s/lib/eal/x86/include " + "-I %s/lib/eal/include/generic " + "-I %s/lib/meter " + "-I %s/lib/port " + "-I %s/lib/table " + "-I %s/lib/pipeline " + "-I %s/config " + "-I %s/build " + "-I %s/lib/eal/linux/include " + ">%s 2>&1 " + "&& " + "gcc -shared %s -o %s " + ">>%s 2>&1", + obj_file, + code_file, + install_dir, + install_dir, + install_dir, + install_dir, + install_dir, + install_dir, + install_dir, + install_dir, + install_dir, + install_dir, + install_dir, + log_file, + obj_file, + lib_file, + log_file); + + status = system(buffer); + if (status) { + snprintf(out, + out_size, + "Library build failed, see file \"%s\" for details.\n", + log_file); + goto free; + } + +free: + free(obj_file); + free(log_file); + free(buffer); +} + static const char cmd_pipeline_build_help[] = "pipeline build \n"; @@ -1080,10 +1209,6 @@ table_entry_free(struct rte_swx_table_entry *entry) free(entry); } -#ifndef MAX_LINE_SIZE -#define MAX_LINE_SIZE 2048 -#endif - static int pipeline_table_entries_add(struct rte_swx_ctl_pipeline *p, const char *table_name, @@ -3010,6 +3135,7 @@ cmd_help(char **tokens, "\tpipeline port in\n" "\tpipeline port out\n" "\tpipeline codegen\n" + "\tpipeline libbuild\n" "\tpipeline build\n" "\tpipeline table add\n" "\tpipeline table delete\n" @@ -3085,6 +3211,12 @@ cmd_help(char **tokens, return; } + if ((strcmp(tokens[0], "pipeline") == 0) && + (n_tokens == 2) && (strcmp(tokens[1], "libbuild") == 0)) { + snprintf(out, out_size, "\n%s\n", cmd_pipeline_libbuild_help); + return; + } + if ((strcmp(tokens[0], "pipeline") == 0) && (n_tokens == 2) && (strcmp(tokens[1], "build") == 0)) { snprintf(out, out_size, "\n%s\n", cmd_pipeline_build_help); @@ -3370,6 +3502,13 @@ cli_process(char *in, char *out, size_t out_size, void *obj) return; } + if ((n_tokens >= 3) && + (strcmp(tokens[1], "libbuild") == 0)) { + cmd_pipeline_libbuild(tokens, n_tokens, out, out_size, + obj); + return; + } + if ((n_tokens >= 3) && (strcmp(tokens[2], "build") == 0)) { cmd_pipeline_build(tokens, n_tokens, out, out_size, -- 2.34.1