summaryrefslogtreecommitdiff
path: root/zephyr/zmake/zmake/__main__.py
diff options
context:
space:
mode:
authorJack Rosenthal <jrosenth@chromium.org>2021-01-08 12:30:48 -0700
committerCommit Bot <commit-bot@chromium.org>2021-01-09 03:28:08 +0000
commit2fa27104aa0e97f3c750aa3b04acfc76db5e7123 (patch)
tree7271f546938af224721a621ebeee2a1369048e0e /zephyr/zmake/zmake/__main__.py
parent407a3cfc7c7423b3f03289b094bc1dfd2082a3c4 (diff)
downloadchrome-ec-2fa27104aa0e97f3c750aa3b04acfc76db5e7123.tar.gz
zephyr: copy zmake to platform/ec
This copies zmake into platform/ec/zephyr/zmake, as explained in go/zephyr-fewer-repos. Follow-on CLs will be submitted to: - Update the chromeos-base/zephyr-build-tools ebuild to reference this directory instead of the one in zephyr-chrome. - Remove the copy of zmake in zephyr-chrome. Those interested in the git history of this code prior to it being moved to platform/ec can find it here: https://chromium.googlesource.com/chromiumos/platform/zephyr-chrome/+log/bacea2e3e62c41000e5bdb4ed6433f24386d14bf/util BUG=b:177003034 BRANCH=none TEST=emerge with new path (requires follow-on CL) Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: Ia957b3e35ce3b732968ebf8df603ef13298cc6b3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2618501 Reviewed-by: Yuval Peress <peress@chromium.org>
Diffstat (limited to 'zephyr/zmake/zmake/__main__.py')
-rw-r--r--zephyr/zmake/zmake/__main__.py122
1 files changed, 122 insertions, 0 deletions
diff --git a/zephyr/zmake/zmake/__main__.py b/zephyr/zmake/zmake/__main__.py
new file mode 100644
index 0000000000..1eab278cc3
--- /dev/null
+++ b/zephyr/zmake/zmake/__main__.py
@@ -0,0 +1,122 @@
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""The entry point into zmake."""
+import argparse
+import inspect
+import logging
+import pathlib
+import sys
+
+import zmake.multiproc as multiproc
+import zmake.util as util
+import zmake.zmake as zm
+
+
+def call_with_namespace(func, namespace):
+ """Call a function with arguments applied from a Namespace.
+
+ Args:
+ func: The callable to call.
+ namespace: The namespace to apply to the callable.
+
+ Returns:
+ The result of calling the callable.
+ """
+ kwds = {}
+ sig = inspect.signature(func)
+ names = [p.name for p in sig.parameters.values()]
+ for name, value in vars(namespace).items():
+ pyname = name.replace('-', '_')
+ if pyname in names:
+ kwds[pyname] = value
+ return func(**kwds)
+
+
+# Dictionary used to map log level strings to their corresponding int values.
+log_level_map = {
+ 'DEBUG': logging.DEBUG,
+ 'INFO': logging.INFO,
+ 'WARNING': logging.WARNING,
+ 'ERROR': logging.ERROR,
+ 'CRITICAL': logging.CRITICAL
+}
+
+
+def main(argv=None):
+ """The main function.
+
+ Args:
+ argv: Optionally, the command-line to parse, not including argv[0].
+
+ Returns:
+ Zero upon success, or non-zero upon failure.
+ """
+ if argv is None:
+ argv = sys.argv[1:]
+
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--checkout', type=pathlib.Path,
+ help='Path to ChromiumOS checkout')
+ parser.add_argument('-j', '--jobs', type=int,
+ help='Degree of multiprogramming to use')
+ parser.add_argument('-l', '--log-level', choices=list(log_level_map.keys()),
+ default='WARNING',
+ dest='log_level',
+ help='Set the logging level (default=WARNING)')
+ parser.add_argument('-L', '--no-log-label', action='store_true',
+ default=False,
+ help='Turn off logging labels')
+ sub = parser.add_subparsers(dest='subcommand', help='Subcommand')
+ sub.required = True
+
+ configure = sub.add_parser('configure')
+ configure.add_argument(
+ '--ignore-unsupported-zephyr-version', action='store_true',
+ help="Don't warn about using an unsupported Zephyr version")
+ configure.add_argument('-v', '--version', type=util.parse_zephyr_version,
+ help='Zephyr RTOS version')
+ configure.add_argument('-t', '--toolchain', help='Name of toolchain to use')
+ configure.add_argument('--zephyr-base', type=pathlib.Path,
+ help='Path to Zephyr source')
+ configure.add_argument('-B', '--build-dir', type=pathlib.Path,
+ required=True, help='Build directory')
+ configure.add_argument('-b', '--build', action='store_true',
+ dest='build_after_configure',
+ help='Run the build after configuration')
+ configure.add_argument('--test', action='store_true',
+ dest='test_after_configure',
+ help='Test the .elf file after configuration')
+ configure.add_argument('project_dir', type=pathlib.Path,
+ help='Path to the project to build')
+
+ build = sub.add_parser('build')
+ build.add_argument('build_dir', type=pathlib.Path,
+ help='The build directory used during configuration')
+
+ test = sub.add_parser('test')
+ test.add_argument('build_dir', type=pathlib.Path,
+ help='The build directory used during configuration')
+
+ testall = sub.add_parser('testall')
+ testall.add_argument('--fail-fast', action='store_true',
+ help='stop testing after the first error')
+
+ opts = parser.parse_args(argv)
+
+ if opts.no_log_label:
+ log_format = '%(message)s'
+ else:
+ log_format = '%(asctime)s - %(name)s/%(levelname)s: %(message)s'
+ logging.basicConfig(format=log_format, level=log_level_map.get(opts.log_level))
+
+ zmake = call_with_namespace(zm.Zmake, opts)
+ subcommand_method = getattr(zmake, opts.subcommand.replace('-', '_'))
+ result = call_with_namespace(subcommand_method, opts)
+ multiproc.wait_for_log_end()
+ return result
+
+
+if __name__ == '__main__':
+ sys.exit(main())