From patchwork Thu Aug 1 17:29:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 142850 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 DE96745715; Thu, 1 Aug 2024 19:30:47 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 866A740E72; Thu, 1 Aug 2024 19:30:43 +0200 (CEST) Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by mails.dpdk.org (Postfix) with ESMTP id A5D3440A8B for ; Thu, 1 Aug 2024 19:30:40 +0200 (CEST) Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-70d2ae44790so5216201b3a.2 for ; Thu, 01 Aug 2024 10:30:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1722533440; x=1723138240; 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=9h/uq1FGHGIM+pFt6ArfZ8KdOyxnzCimgviYb7GL8GA=; b=TGOELlQo0FyVd5CqkeZDby1qNDm3fLlauO0qs4ozt50R4q1oP6OQC3t7bt/6bPR8li 61W2OX2ZnT3I1LHBXxit4Jz8qrY6l7+8LXkPDIDcR7OqNo9DJrt2bAIvpZpxmslbXW86 cwRIJPF9zyCYXu2ajtWx0y/c9cq+KfYl7GwtcrUmson3v0417RDSp9dig+j6e/KUpYAA zQPchwUuraAV8hvDW6a9aDL4wvZcz7WGgdDcITOEoPFlPOyGtuM0NgajHB01MLAPkpvN Qne50WsuqGJ2S1Ww4tQUnxIbxJH6WHB0K0H0bWdxfuS18OqP+3zm2a60LmgHfNnKzb+J J1cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722533440; x=1723138240; 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=9h/uq1FGHGIM+pFt6ArfZ8KdOyxnzCimgviYb7GL8GA=; b=ETfk+YuzTChr/N2Tu4mQXH6EgGweSO3usyyk/4rtJLCQR/364wXkhDTgXh2FidWMLH pQ55+qUN/HtQ0U/Z7VrDscFuzqdSlPwDQisVODprqhQ9fGRnGd9o05WOqj4OiylSKBFH o0c6qUdk2JnuKeeggeyiM8hR6+frcS1xNgGA1Q60bT7+EiAzDLXCwBqa6Q2YpUvG6UQK B8kN/MAUpeh+4CW6VUoU4vEzx3xaQwWZsUDtlSoGqgsqXfdxHqVyUkt/02dj2Mrg5PeV 96XXUFyOUozM7Xr/QwYqqHIqS5vHenePisO8jSxE913dn3M6i8siZ3P1k2maFIcSFT5G WY+Q== X-Gm-Message-State: AOJu0YxUFey97Iz079dM6CUgcCbywY3dkcv5CYdbfRrBwpZW6fodUaXA 9BZ0IQ/c/+GuD9M6i0nT5dRq90EqfSDgl0I5Bks16Z8bIC0YtptxqSz9yzemdRC6Evq68mNJdEP + X-Google-Smtp-Source: AGHT+IGMSbGqZ6ZRzRXOT8OaRO8cwMNIgnJPiSmM23S1e6oHfShzIxJoFreHmloShGqghIpXRA+QIA== X-Received: by 2002:a05:6a20:432c:b0:1c3:b263:d992 with SMTP id adf61e73a8af0-1c699527ecemr1334643637.5.1722533439716; Thu, 01 Aug 2024 10:30:39 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ec02a3fsm100170b3a.16.2024.08.01.10.30.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 10:30:39 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v4 1/3] buildtools: add helper to convert text file to header Date: Thu, 1 Aug 2024 10:29:08 -0700 Message-ID: <20240801173029.65710-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240801173029.65710-1-stephen@networkplumber.org> References: <20240730225520.83314-1-stephen@networkplumber.org> <20240801173029.65710-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 -