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 8B4A143344; Thu, 16 Nov 2023 12:18:27 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 33C47402B7; Thu, 16 Nov 2023 12:18:27 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 2CA80402B0 for ; Thu, 16 Nov 2023 12:18:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700133504; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=U5+v3Vab0ra1EO2pQr5bbtB43GAkxnf3OeOQTaFrVHs=; b=R/HXiGsbMaIw6/KTrekHx/CtdkwWgAHgKmww/+HzxABGKv61OrL+zRoAYPT6jPpaJ3a8H4 FztS9RsY6/RXd9Edqg5DZYnIQODu4JVQB4rxIWUOX6r28R/ySDYrMi6p7FhzW6VstkVUnn oK5U4LFTqKq7SqrI72uaB9MHyFC6Kds= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-448-YNU3ezEYMTm7hkC2bfYspw-1; Thu, 16 Nov 2023 06:18:22 -0500 X-MC-Unique: YNU3ezEYMTm7hkC2bfYspw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9FF7C185A783; Thu, 16 Nov 2023 11:18:22 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.208.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06D9E1C060AE; Thu, 16 Nov 2023 11:18:21 +0000 (UTC) From: Robin Jarry To: dev@dpdk.org Cc: Bruce Richardson Subject: [PATCH] cmdline-gen: fix error when command list has empty lines Date: Thu, 16 Nov 2023 12:18:13 +0100 Message-ID: <20231116111812.296090-2-rjarry@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 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 Fix the following error when a command list file contains empty lines: Traceback (most recent call last): File "buildtools/dpdk-cmdline-gen.py", line 202, in main() File "buildtools/dpdk-cmdline-gen.py", line 184, in main process_commands(args.infile, sys.stdout, None, args.context_name) File "buildtools/dpdk-cmdline-gen.py", line 141, in process_commands cmd_inst, h_out, c_out = process_command(lineno, tokens.strip().spl… ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^… File "buildtools/dpdk-cmdline-gen.py", line 36, in process_command if tokens[0].startswith("<"): ~~~~~~^^^ IndexError: list index out of range Use shlex.split() to properly split each line arguments into tokens and strip comments. If there are no tokens, ignore the line. Fixes: 37666691e9ed ("buildtools: add a tool to generate cmdline boilerplate") Cc: Bruce Richardson Signed-off-by: Robin Jarry --- buildtools/dpdk-cmdline-gen.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/buildtools/dpdk-cmdline-gen.py b/buildtools/dpdk-cmdline-gen.py index 8922bb5fc38e..49b03bee4a26 100755 --- a/buildtools/dpdk-cmdline-gen.py +++ b/buildtools/dpdk-cmdline-gen.py @@ -7,6 +7,7 @@ """ import argparse +import shlex import sys PARSE_FN_PARAMS = "void *parsed_result, struct cmdline *cl, void *data" @@ -133,12 +134,14 @@ def process_commands(infile, hfile, cfile, ctxname): ) for lineno, line in enumerate(infile.readlines()): - if line.lstrip().startswith("#"): + tokens = shlex.split(line, comments=True) + if not tokens: continue - if "#" not in line: - line = line + "#" # ensure split always works, even if no help text - tokens, comment = line.split("#", 1) - cmd_inst, h_out, c_out = process_command(lineno, tokens.strip().split(), comment.strip()) + if "#" in line: + comment = line.split("#", 1)[-1].strip() + else: + comment = "" + cmd_inst, h_out, c_out = process_command(lineno, tokens, comment) hfile.write("\n".join(h_out)) if cfile: cfile.write("\n".join(c_out)) -- 2.41.0