From patchwork Fri Aug 2 16:45:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 142868 X-Patchwork-Delegate: thomas@monjalon.net 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 3AF284571D; Fri, 2 Aug 2024 18:46:46 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8B06440E22; Fri, 2 Aug 2024 18:46:40 +0200 (CEST) Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by mails.dpdk.org (Postfix) with ESMTP id 66909406B8 for ; Fri, 2 Aug 2024 18:46:38 +0200 (CEST) Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-7104f939aaaso2768184b3a.1 for ; Fri, 02 Aug 2024 09:46:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1722617197; x=1723221997; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tQxNv6lj4Rb2InV7FsuUQ9V4I3NFyCxd2hOtlNTsRJ4=; b=dthSmfaOp8dHt3FlBYRbiqFTl5JMMMQHjTiawnXPi/xi2qmLIDjcbZMwFEurNalv/O VZU8F73aLJ3E89/Uvd1yIA1/5XoDV8uHLxF0pu/wtpw67VnTSwYA8+N86dBohnM3+qZx cxpun6dtCCteun4WhOXvtVxhw0NQmOJ3gyOdiiDun5jSybX1jVm7DzJ8/O3zHIWhTQEx 2+p9/1YdijWNTvGAkh/RVWyNvvnKZ3tTv9OSMU3kOKkX9Q3VfJ+ABHvSNbqmqX/RcAYq cj42sp8EVgvhVHM5/wfPJuHYtSWg25oM5z2PEj32tnZjzSKih7WTQL9Z+RBuZfC+chpW g8SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722617197; x=1723221997; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tQxNv6lj4Rb2InV7FsuUQ9V4I3NFyCxd2hOtlNTsRJ4=; b=VyZ9nK5EOZgDBFl2/46EYSGmcXKhRzbKgL+rQtFOutsl4isjd2NQKCLIS4QlxO2JyA yOUcfEfZB9TnNxVI4Xfi5xWUB4WUlXOBhcI9ff0VvrC4Tevjab8j6H9z8HTVDSEfGOfF Fgn4O0dBxt+4eybptcCSY2TNpBRo+RUBwN0neghMReS3awQTGR5YGIUrqVMSRnSNWo6W 0P7bFjjXmZ/OZ5LnlBAG7dz448txDu2QNMFZBXW/fFUmPBs5eQeU+ztTicF1ufWmNJ9B t7TVInPrTKJIEzRDco/dls9EjbBVOqL9COfYYXdKuoWyqZ2n1NLlYZpSIavuGMAEiL+b xFwA== X-Gm-Message-State: AOJu0Yy3L9epQ7VhEyz4Sj9fsKsWOWO9R2qsY61iwYgSMNnkdOKiIG92 +ue5CwTSCC9mjOLthKPXoxo2AQoJuIp1hlXuA0mPn3hupL+LL2LmW+XdnPjCS3r9aYS9UqYkKLc A X-Google-Smtp-Source: AGHT+IGFM3fdJ5nVHgq2DsrBDFR5MwXnXARetgrH7cqfz9qaw+xe3fKHH2+CVLNzJmDKkRuSfUCkqQ== X-Received: by 2002:a05:6a00:3e19:b0:706:5dab:83c4 with SMTP id d2e1a72fcca58-7106cfd77e7mr5559027b3a.14.1722617197443; Fri, 02 Aug 2024 09:46:37 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ecdfec9sm1591011b3a.97.2024.08.02.09.46.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 09:46:37 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson Subject: [PATCH v5 1/4] buildtools: add helper to convert text file to header Date: Fri, 2 Aug 2024 09:45:00 -0700 Message-ID: <20240802164626.389286-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240802164626.389286-1-stephen@networkplumber.org> References: <20240730225520.83314-1-stephen@networkplumber.org> <20240802164626.389286-1-stephen@networkplumber.org> 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 Simple script to read a file and make it into a initialized C string in a header file. Signed-off-by: Stephen Hemminger Acked-by: Bruce Richardson --- buildtools/gen-header.py | 36 ++++++++++++++++++++++++++++++++++++ buildtools/meson.build | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 buildtools/gen-header.py diff --git a/buildtools/gen-header.py b/buildtools/gen-header.py new file mode 100644 index 0000000000..06e645863c --- /dev/null +++ b/buildtools/gen-header.py @@ -0,0 +1,36 @@ +#! /usr/bin/env python3 +# SPDX-License-Identifier: BSD-3-Clause +# Copyright (c) 2023 Stephen Hemminger + +""" +Script to read a text file and convert it into a header file. +""" +import sys +import os + + +def main(): + '''program main function''' + print(f'/* File autogenerated by {sys.argv[0]} */') + for path in sys.argv[1:]: + name = os.path.basename(path) + print() + print(f'/* generated from {name} */') + with open(path, "r") as f: + array = name.replace(".", "_") + print(f'static const char {array}[] = ' + '{') + line = f.readline() + + # make sure empty string is null terminated + if not line: + print(' ""') + + while line: + s = repr(line) + print(' {}'.format(s.replace("'", '"'))) + line = f.readline() + print('};') + + +if __name__ == "__main__": + main() diff --git a/buildtools/meson.build b/buildtools/meson.build index 3adf34e1a8..bc818a71d5 100644 --- a/buildtools/meson.build +++ b/buildtools/meson.build @@ -24,6 +24,7 @@ get_numa_count_cmd = py3 + files('get-numa-count.py') get_test_suites_cmd = py3 + files('get-test-suites.py') has_hugepages_cmd = py3 + files('has-hugepages.py') cmdline_gen_cmd = py3 + files('dpdk-cmdline-gen.py') +header_gen_cmd = py3 + files('gen-header.py') # install any build tools that end-users might want also install_data([ @@ -48,4 +49,3 @@ else pmdinfo += 'ar' pmdinfogen += 'elf' endif -