From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH v3 1/3] buildtools: add helper to convert text file to header
Date: Wed, 31 Jul 2024 10:35:11 -0700 [thread overview]
Message-ID: <20240731173616.91081-2-stephen@networkplumber.org> (raw)
In-Reply-To: <20240731173616.91081-1-stephen@networkplumber.org>
Simple script to read a file and make it into a initialized
C string in a header file.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
| 36 ++++++++++++++++++++++++++++++++++++
buildtools/meson.build | 2 +-
2 files changed, 37 insertions(+), 1 deletion(-)
create mode 100644 buildtools/gen-header.py
--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 <stephen@networkplumber.org>
+
+"""
+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
-
--
2.43.0
next prev parent reply other threads:[~2024-07-31 17:36 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-30 22:51 [PATCH 0/3] restore cfgfile library tests Stephen Hemminger
2024-07-30 22:51 ` [PATCH 1/3] buildtools: add helper to convert text file to header Stephen Hemminger
2024-07-30 22:51 ` [PATCH 2/3] test: restore cfgfile tests Stephen Hemminger
2024-07-30 22:51 ` [PATCH 3/3] test: remove unused resource API Stephen Hemminger
2024-07-31 4:20 ` [PATCH v2 0/3] restore cfgfile library tests Stephen Hemminger
2024-07-31 4:20 ` [PATCH v2 1/3] buildtools: add helper to convert text file to header Stephen Hemminger
2024-07-31 4:20 ` [PATCH v2 2/3] test: restore cfgfile tests Stephen Hemminger
2024-07-31 4:20 ` [PATCH v2 3/3] test: remove unused resource API Stephen Hemminger
2024-07-31 17:35 ` [PATCH v3 0/3] restore lost tests for rte_cfgfile Stephen Hemminger
2024-07-31 17:35 ` Stephen Hemminger [this message]
2024-07-31 17:35 ` [PATCH v3 2/3] test: remove unused resource API Stephen Hemminger
2024-07-31 17:35 ` [PATCH v3 3/3] test: restore cfgfile tests Stephen Hemminger
2024-08-01 17:29 ` [PATCH v4 0/3] restore lost " Stephen Hemminger
2024-08-01 17:29 ` [PATCH v4 1/3] buildtools: add helper to convert text file to header Stephen Hemminger
2024-08-02 15:15 ` Bruce Richardson
2024-08-01 17:29 ` [PATCH v4 2/3] test: remove unused resource API Stephen Hemminger
2024-08-02 15:16 ` Bruce Richardson
2024-08-01 17:29 ` [PATCH v4 3/3] test: restore cfgfile tests Stephen Hemminger
2024-08-02 15:21 ` Bruce Richardson
2024-08-02 16:44 ` [PATCH v5 0/4] restore unused " Stephen Hemminger
2024-08-02 16:45 ` [PATCH v5 1/4] buildtools: add helper to convert text file to header Stephen Hemminger
2024-08-02 16:45 ` [PATCH v5 2/4] test: remove unused resource API Stephen Hemminger
2024-08-02 16:45 ` [PATCH v5 3/4] test: restore cfgfile tests Stephen Hemminger
2024-08-02 16:52 ` Bruce Richardson
2024-08-02 16:45 ` [PATCH v5 4/4] test: rearrange test_cfgfiles cases Stephen Hemminger
2024-08-02 16:51 ` Bruce Richardson
2024-08-02 17:06 ` Stephen Hemminger
2024-08-06 8:37 ` Bruce Richardson
2024-08-13 15:57 ` [PATCH v6 0/4] test: restore cfgfile lib tests Stephen Hemminger
2024-08-13 15:57 ` [PATCH v6 1/4] buildtools: add helper to convert text file to header Stephen Hemminger
2024-08-13 15:57 ` [PATCH v6 2/4] test: remove unused resource API Stephen Hemminger
2024-08-13 15:57 ` [PATCH v6 3/4] test: rearrange test_cfgfiles cases Stephen Hemminger
2024-08-13 15:57 ` [PATCH v6 4/4] test: restore cfgfile tests Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240731173616.91081-2-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).