]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dtoc: Move the main code into a function
authorSimon Glass <sjg@chromium.org>
Fri, 24 Feb 2023 01:18:15 +0000 (18:18 -0700)
committerSimon Glass <sjg@chromium.org>
Wed, 8 Mar 2023 19:40:49 +0000 (11:40 -0800)
Put this code into a function so it is easy for it be run when packaged.

Signed-off-by: Simon Glass <sjg@chromium.org>
tools/dtoc/main.py

index 91521661f4615e36a02f4626d9a7f86d95723f9c..6c91450410eee6f87818fa45a86d6e6b22724912 100755 (executable)
@@ -65,58 +65,62 @@ def run_tests(processes, args):
     return (0 if result.wasSuccessful() else 1)
 
 
-def RunTestCoverage():
+def RunTestCoverage(build_dir):
     """Run the tests and check that we get 100% coverage"""
     sys.argv = [sys.argv[0]]
     test_util.run_test_coverage('tools/dtoc/dtoc', '/main.py',
             ['tools/patman/*.py', 'tools/u_boot_pylib/*','*/fdt*', '*test*'],
-            args.build_dir)
-
-
-if __name__ != '__main__':
-    sys.exit(1)
-
-epilog = '''Generate C code from devicetree files. See of-plat.rst for details'''
-
-parser = ArgumentParser(epilog=epilog)
-parser.add_argument('-B', '--build-dir', type=str, default='b',
-        help='Directory containing the build output')
-parser.add_argument('-c', '--c-output-dir', action='store',
-                  help='Select output directory for C files')
-parser.add_argument('-C', '--h-output-dir', action='store',
-                  help='Select output directory for H files (defaults to --c-output-di)')
-parser.add_argument('-d', '--dtb-file', action='store',
-                  help='Specify the .dtb input file')
-parser.add_argument('-i', '--instantiate', action='store_true', default=False,
-                  help='Instantiate devices to avoid needing device_bind()')
-parser.add_argument('--include-disabled', action='store_true',
-                  help='Include disabled nodes')
-parser.add_argument('-o', '--output', action='store',
-                  help='Select output filename')
-parser.add_argument('-p', '--phase', type=str,
-                  help='set phase of U-Boot this invocation is for (spl/tpl)')
-parser.add_argument('-P', '--processes', type=int,
-                  help='set number of processes to use for running tests')
-if HAVE_TESTS:
-    parser.add_argument('-t', '--test', action='store_true', dest='test',
-                        default=False, help='run tests')
-    parser.add_argument(
-        '-T', '--test-coverage', action='store_true',
-        default=False, help='run tests and check for 100%% coverage')
-
-parser.add_argument('files', nargs='*')
-args = parser.parse_args()
+            build_dir)
 
-# Run our meagre tests
-if HAVE_TESTS and args.test:
-    ret_code = run_tests(args.processes, args)
-    sys.exit(ret_code)
 
-elif HAVE_TESTS and args.test_coverage:
-    RunTestCoverage()
+def run_dtoc():
+    epilog = 'Generate C code from devicetree files. See of-plat.rst for details'
 
-else:
-    dtb_platdata.run_steps(args.files, args.dtb_file, args.include_disabled,
-                           args.output,
-                           [args.c_output_dir, args.h_output_dir],
-                           args.phase, instantiate=args.instantiate)
+    parser = ArgumentParser(epilog=epilog)
+    parser.add_argument('-B', '--build-dir', type=str, default='b',
+            help='Directory containing the build output')
+    parser.add_argument('-c', '--c-output-dir', action='store',
+                      help='Select output directory for C files')
+    parser.add_argument(
+        '-C', '--h-output-dir', action='store',
+        help='Select output directory for H files (defaults to --c-output-di)')
+    parser.add_argument('-d', '--dtb-file', action='store',
+                      help='Specify the .dtb input file')
+    parser.add_argument(
+        '-i', '--instantiate', action='store_true', default=False,
+        help='Instantiate devices to avoid needing device_bind()')
+    parser.add_argument('--include-disabled', action='store_true',
+                      help='Include disabled nodes')
+    parser.add_argument('-o', '--output', action='store',
+                      help='Select output filename')
+    parser.add_argument(
+        '-p', '--phase', type=str,
+        help='set phase of U-Boot this invocation is for (spl/tpl)')
+    parser.add_argument('-P', '--processes', type=int,
+                      help='set number of processes to use for running tests')
+    if HAVE_TESTS:
+        parser.add_argument('-t', '--test', action='store_true', dest='test',
+                            default=False, help='run tests')
+        parser.add_argument(
+            '-T', '--test-coverage', action='store_true',
+            default=False, help='run tests and check for 100%% coverage')
+    parser.add_argument('files', nargs='*')
+    args = parser.parse_args()
+
+    # Run our meagre tests
+    if HAVE_TESTS and args.test:
+        ret_code = run_tests(args.processes, args)
+        sys.exit(ret_code)
+
+    elif HAVE_TESTS and args.test_coverage:
+        RunTestCoverage(args.build_dir)
+
+    else:
+        dtb_platdata.run_steps(args.files, args.dtb_file, args.include_disabled,
+                               args.output,
+                               [args.c_output_dir, args.h_output_dir],
+                               args.phase, instantiate=args.instantiate)
+
+
+if __name__ == '__main__':
+    run_dtoc()