[PATCH] bsp-builder: Fix mailer options exception

Alex White alex.white at oarcorp.com
Mon Sep 20 16:07:36 UTC 2021


This changes the object holding the command line arguments from an
argparse.Namespace to an rtemstoolkit.options.command_line. This matches
the type expected by rtemstoolkit.mailer.mail.__init__ and is the type
used in tester/rt/test.py and run.py.
---
 tester/rt/check.py | 151 +++++++++++++++++++++++++--------------------
 1 file changed, 84 insertions(+), 67 deletions(-)

diff --git a/tester/rt/check.py b/tester/rt/check.py
index c01c25d..982b65e 100755
--- a/tester/rt/check.py
+++ b/tester/rt/check.py
@@ -54,6 +54,8 @@ from rtemstoolkit import rtems
 from rtemstoolkit import textbox
 from rtemstoolkit import version
 
+import tester.rt.options
+
 #
 # Group loggin entries together.
 #
@@ -1153,55 +1155,40 @@ def run(args):
         description += 'can build based on tier, architecture, or BSP. You can control '
         description += 'the profile of build with various build configuration settings.'
 
-        argsp = argparse.ArgumentParser(prog = 'rtems-bsp-builder',
-                                        description = description)
-        argsp.add_argument('--prefix', help = 'Prefix to build the BSP.',
-                           type = str)
-        argsp.add_argument('--rtems-tools', help = 'The RTEMS tools directory.',
-                           type = str)
-        argsp.add_argument('--rtems', help = 'The RTEMS source tree.',
-                           type = str)
-        argsp.add_argument('--build-path', help = 'Path to build in.',
-                           type = str)
-        argsp.add_argument('--log', help = 'Log file.', type = str)
-        argsp.add_argument('--config-report', help = 'Report the configuration.',
-                           type = str, default = None,
-                           choices = ['all', 'profiles', 'builds', 'archs'])
-        argsp.add_argument('--warnings-report', help = 'Report the warnings to a file.',
-                           type = str, default = None)
-        argsp.add_argument('--failures-report', help = 'Report the failures to a file.',
-                           type = str, default = None)
-        argsp.add_argument('--stop-on-error', help = 'Stop on an error.',
-                           action = 'store_true')
-        argsp.add_argument('--no-clean', help = 'Do not clean the build output.',
-                           action = 'store_true')
-        argsp.add_argument('--profiles', help = 'Build the listed profiles (profile,profile,..).',
-                           type = str, default = 'tier-1')
-        argsp.add_argument('--arch', help = 'Build the architectures (arch,arch,..).',
-                           type = str)
-        argsp.add_argument('--bsp', help = 'Build the BSPs (arch/bsp,arch/bsp,..).',
-                           type = str)
-        argsp.add_argument('--build', help = 'Build name to build (see --config-report).',
-                           type = str, default='all')
-        argsp.add_argument('--jobs', help = 'Number of jobs to run.',
-                           type = str, default = '1/%d' % (host.cpus()))
-        argsp.add_argument('--dry-run', help = 'Do not run the actual builds.',
-                           action = 'store_true')
-        mailer.add_arguments(argsp)
-
-        opts = argsp.parse_args(args[1:])
+        optargs = {
+            '--prefix': 'Prefix to build the BSP.',
+            '--rtems-tools': 'The RTEMS tools directory.',
+            '--rtems': 'The RTEMS source tree.',
+            '--build-path': 'Path to build in.',
+            '--log': 'Log file.',
+            '--config-report': 'Report the configuration.',
+            '--warnings-report': 'Report the warnings to a file.',
+            '--failures-report': 'Report the failures to a file.',
+            '--stop-on-error': 'Stop on an error.',
+            '--no-clean': 'Do not clean the build output.',
+            '--profiles': 'Build the listed profiles (profile,profile,..).',
+            '--arch': 'Build the architectures (arch,arch,..).',
+            '--bsp': 'Build the BSPs (arch/bsp,arch/bsp,..).',
+            '--build': 'Build name to build (see --config-report).',
+            '--jobs': 'Number of jobs to run.',
+            '--dry-run': 'Do not run the actual builds.'
+        }
+        mailer.append_options(optargs)
+        opts = tester.rt.options.load(args, optargs = optargs)
+
         mail = None
-        if opts.mail:
+        if opts.find_arg('--mail'):
             mail = mailer.mail(opts)
             # Request these now to generate any errors.
             from_addr = mail.from_address()
             smtp_host = mail.smtp_host()
-            if 'mail_to' in opts and opts.mail_to is not None:
-                to_addr = opts.mail_to
+            to_addr = opts.find_arg('--mail-to')
+            if to_addr:
+                to_addr = to_addr[1]
             else:
                 to_addr = 'build at rtems.org'
-        if opts.log is not None:
-            logf = opts.log
+        if opts.find_arg('--log') is not None:
+            logf = opts.find_arg('--log')[1]
         log.default = log.log([logf])
         log.notice(title())
         log.output(command_line())
@@ -1211,48 +1198,78 @@ def run(args):
                                                         smtp_host))
 
         config = rtems.configuration()
-        config.load(config_file, opts.build)
+        build = opts.find_arg('--build')
+        if build is not None:
+            build = build[1]
+        config.load(config_file, build)
 
-        if opts.config_report:
-            log.notice('Configuration Report: %s' % (opts.config_report))
+        config_report = opts.find_arg('--config-report')
+        if config_report is not None:
+            log.notice('Configuration Report: %s' % (config_report[1]))
             c_profiles = False
             c_builds = False
             c_archs = False
-            if opts.config_report == 'all':
+            if config_report[1] == 'all':
                 c_profiles = True
                 c_builds = True
                 c_archs = True
-            elif opts.config_report == 'profiles':
+            elif config_report[1] == 'profiles':
                 c_profiles = True
-            elif opts.config_report == 'builds':
+            elif config_report[1] == 'builds':
                 c_builds = True
-            elif opts.config_report == 'archs':
+            elif config_report[1] == 'archs':
                 c_archs = True
             log.notice(config.report(c_profiles, c_builds, c_archs))
             sys.exit(0)
 
-        if opts.rtems is None:
+        rtems_opt = opts.find_arg('--rtems')
+        if rtems_opt is None:
             raise error.general('No RTEMS source provided on the command line')
-        if opts.prefix is not None:
-            prefix = path.shell(opts.prefix)
-        if opts.rtems_tools is not None:
-            tools = path.shell(opts.rtems_tools)
-        if opts.build_path is not None:
-            build_dir = path.shell(opts.build_path)
-
-        options = { 'stop-on-error'   : opts.stop_on_error,
-                    'no-clean'        : opts.no_clean,
-                    'dry-run'         : opts.dry_run,
-                    'jobs'            : opts.jobs,
-                    'warnings-report' : opts.warnings_report,
-                    'failures-report' : opts.failures_report }
+        prefix_opt = opts.find_arg('--prefix')
+        if prefix_opt is not None:
+            prefix = path.shell(prefix_opt[1])
+        rtems_tools = opts.find_arg('--rtems-tools')
+        if rtems_tools is not None:
+            tools = path.shell(rtems_tools[1])
+        build_path = opts.find_arg('--build-path')
+        if build_path is not None:
+            build_dir = path.shell(build_path[1])
+
+        jobs = opts.find_arg('--jobs')
+        if jobs is not None:
+            jobs = jobs[1]
+        else:
+            jobs = '1/%d' % (host.cpus())
+        warnings_report = opts.find_arg('--warnings-report')
+        if warnings_report is not None:
+            warnings_report = warnings_report[1]
+        failures_report = opts.find_arg('--failures-report')
+        if failures_report is not None:
+            failures_report = failures_report[1]
+        options = { 'stop-on-error'   : opts.find_arg('--stop-on-error'),
+                    'no-clean'        : opts.no_clean(),
+                    'dry-run'         : opts.dry_run(),
+                    'jobs'            : jobs,
+                    'warnings-report' : warnings_report,
+                    'failures-report' : failures_report }
 
         b = builder(config, rtems_version(), prefix, tools,
-                    path.shell(opts.rtems), build_dir, options)
+                    path.shell(rtems_opt[1]), build_dir, options)
 
-        profiles = comma_split(opts.profiles)
-        archs = comma_split(opts.arch)
-        bsps = comma_split(opts.bsp)
+        profiles_opt = opts.find_arg('--profiles')
+        if profiles_opt is not None:
+            profiles_opt = profiles_opt[1]
+        else:
+            profiles_opt = 'tier-1'
+        arch_opt = opts.find_arg('--arch')
+        if arch_opt is not None:
+            arch_opt = arch_opt[1]
+        bsp_opt = opts.find_arg('--bsp')
+        if bsp_opt is not None:
+            bsp_opt = bsp_opt[1]
+        profiles = comma_split(profiles_opt)
+        archs = comma_split(arch_opt)
+        bsps = comma_split(bsp_opt)
 
         #
         # The default is build a profile.
-- 
2.27.0



More information about the devel mailing list