[PATCH v1 1/2] tools/dt-extract-example: support examples with root node

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxx>
---
 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




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux