devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sam Ravnborg <sam@ravnborg.org>
To: Rob Herring <robh@kernel.org>, devicetree@vger.kernel.org
Cc: Sam Ravnborg <sam@ravnborg.org>, Maxime Ripard <mripard@kernel.org>
Subject: [PATCH v1 1/2] tools/dt-extract-example: support examples with root node
Date: Sat, 25 Apr 2020 12:52:54 +0200	[thread overview]
Message-ID: <20200425105255.1064-2-sam@ravnborg.org> (raw)
In-Reply-To: <20200425105255.1064-1-sam@ravnborg.org>

Examples are prefixed with boiler plate in the normal case.
In the rare case a root node is required this boiler plate shall not be
used.

Example with root node:

    / {
        chosen {
            ...;
        }
    }

Teach the script to recognize that the example starts with a root node
and avoid the boiler plate in such cases.
The root node is recognized using a simple regular expression search.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
---
 tools/dt-extract-example | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/tools/dt-extract-example b/tools/dt-extract-example
index 99e59c3..0e933e4 100755
--- a/tools/dt-extract-example
+++ b/tools/dt-extract-example
@@ -4,6 +4,7 @@
 # Copyright 2019 Arm Ltd.
 
 import os
+import re
 import sys
 import ruamel.yaml
 import argparse
@@ -17,11 +18,14 @@ example_template = """
 {example}
 
     }};
+}};
 """
 
 example_header = """
 /dts-v1/;
 /plugin/; // silence any missing phandle references
+"""
+example_start = """
 /{
     compatible = "foo";
     model = "foo";
@@ -49,7 +53,15 @@ if __name__ == "__main__":
 
     if 'examples' in binding.keys():
         for idx,ex in enumerate(binding['examples']):
-            ex = '        '.join(ex.splitlines(True))
-            print(example_template.format(example=ex,example_num=idx))
+            # Check if example contains a root node "/{"
+            root_node = re.search('^/\s*{', ex)
 
-    print("\n};")
+            if not root_node:
+                print(example_start)
+                ex = '        '.join(ex.splitlines(True))
+                print(example_template.format(example=ex,example_num=idx))
+            else:
+                print(ex)
+    else:
+        print(example_start)
+        print("\n};")
-- 
2.20.1


  reply	other threads:[~2020-04-25 10:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-25 10:52 [PATCH v1 0/2] update dt-extract-example Sam Ravnborg
2020-04-25 10:52 ` Sam Ravnborg [this message]
2020-04-25 10:52 ` [PATCH v1 2/2] tools/dt-extract-example: beautify output Sam Ravnborg

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=20200425105255.1064-2-sam@ravnborg.org \
    --to=sam@ravnborg.org \
    --cc=devicetree@vger.kernel.org \
    --cc=mripard@kernel.org \
    --cc=robh@kernel.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).