From 4583c00236efd4ee768ff874f92526c229891a05 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 23 Feb 2023 18:18:04 -0700 Subject: patman: Move library functions into a library directory The patman directory has a number of modules which are used by other tools in U-Boot. This makes it hard to package the tools using pypi since the common files must be copied along with the tool that uses them. To address this, move these files into a new u_boot_pylib library. This can be packaged separately and listed as a dependency of each tool. Signed-off-by: Simon Glass --- tools/dtoc/main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tools/dtoc/main.py') diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py index 5508759d4d5..fc9207d1b63 100755 --- a/tools/dtoc/main.py +++ b/tools/dtoc/main.py @@ -35,7 +35,7 @@ sys.path.insert(0, os.path.join(our_path, '../../build-sandbox_spl/scripts/dtc/pylibfdt')) from dtoc import dtb_platdata -from patman import test_util +from u_boot_pylib import test_util def run_tests(processes, args): """Run all the test we have for dtoc @@ -65,7 +65,8 @@ def RunTestCoverage(): """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', '*/fdt*', '*test*'], args.build_dir) + ['tools/patman/*.py', 'tools/u_boot_pylib/*','*/fdt*', '*test*'], + args.build_dir) if __name__ != '__main__': -- cgit v1.2.3 From ab9272b8042db7e3f26b495635c20cbbe439ce42 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 23 Feb 2023 18:18:14 -0700 Subject: dtoc: Hide the test options unless test code is available It doesn't make much sense to expose tests when dtoc is running outside of the U-Boot git checkout. Hide the option in this case. Signed-off-by: Simon Glass --- tools/dtoc/main.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'tools/dtoc/main.py') diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py index fc9207d1b63..91521661f46 100755 --- a/tools/dtoc/main.py +++ b/tools/dtoc/main.py @@ -23,6 +23,7 @@ see doc/driver-model/of-plat.rst from argparse import ArgumentParser import os +import pathlib import sys # Bring in the patman libraries @@ -37,6 +38,9 @@ sys.path.insert(0, os.path.join(our_path, from dtoc import dtb_platdata from u_boot_pylib import test_util +DTOC_DIR = pathlib.Path(__file__).parent +HAVE_TESTS = (DTOC_DIR / 'test_dtoc.py').exists() + def run_tests(processes, args): """Run all the test we have for dtoc @@ -93,19 +97,22 @@ 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') -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') +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 args.test: +if HAVE_TESTS and args.test: ret_code = run_tests(args.processes, args) sys.exit(ret_code) -elif args.test_coverage: +elif HAVE_TESTS and args.test_coverage: RunTestCoverage() else: -- cgit v1.2.3 From b3f5474077d60a1886f4ebb329387c108eca22d4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 23 Feb 2023 18:18:15 -0700 Subject: dtoc: Move the main code into a function Put this code into a function so it is easy for it be run when packaged. Signed-off-by: Simon Glass --- tools/dtoc/main.py | 100 ++++++++++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 48 deletions(-) (limited to 'tools/dtoc/main.py') diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py index 91521661f46..6c91450410e 100755 --- a/tools/dtoc/main.py +++ b/tools/dtoc/main.py @@ -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() -- cgit v1.2.3