diff options
author | Jack Rosenthal <jrosenth@chromium.org> | 2021-01-08 12:30:48 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-01-09 03:28:08 +0000 |
commit | 2fa27104aa0e97f3c750aa3b04acfc76db5e7123 (patch) | |
tree | 7271f546938af224721a621ebeee2a1369048e0e /zephyr/zmake/zmake/build_config.py | |
parent | 407a3cfc7c7423b3f03289b094bc1dfd2082a3c4 (diff) | |
download | chrome-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/build_config.py')
-rw-r--r-- | zephyr/zmake/zmake/build_config.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/zephyr/zmake/zmake/build_config.py b/zephyr/zmake/zmake/build_config.py new file mode 100644 index 0000000000..eaa579a777 --- /dev/null +++ b/zephyr/zmake/zmake/build_config.py @@ -0,0 +1,75 @@ +# 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. +"""Encapsulation of a build configuration.""" + + +import zmake.util as util + + +class BuildConfig: + """A container for build configurations. + + A build config is a tuple of environment variables, cmake + variables, kconfig definitons, and kconfig files. + """ + def __init__(self, environ_defs={}, cmake_defs={}, kconfig_defs={}, + kconfig_files=[]): + self.environ_defs = dict(environ_defs) + self.cmake_defs = dict(cmake_defs) + self.kconfig_defs = dict(kconfig_defs) + self.kconfig_files = kconfig_files + + def popen_cmake(self, jobclient, project_dir, build_dir, kconfig_path=None, + **kwargs): + """Run Cmake with this config using a jobclient. + + Args: + jobclient: A JobClient instance. + project_dir: The project directory. + build_dir: Directory to use for Cmake build. + kconfig_path: The path to write out Kconfig definitions. + kwargs: forwarded to popen. + """ + kconfig_files = list(self.kconfig_files) + if kconfig_path: + util.write_kconfig_file(kconfig_path, self.kconfig_defs) + kconfig_files.append(kconfig_path) + elif self.kconfig_defs: + raise ValueError( + 'Cannot start Cmake on a config with Kconfig items without a ' + 'kconfig_path') + + if kconfig_files: + base_config = BuildConfig(environ_defs=self.environ_defs, + cmake_defs=self.cmake_defs) + conf_file_config = BuildConfig( + cmake_defs={'CONF_FILE': ';'.join( + str(p.resolve()) for p in kconfig_files)}) + return (base_config | conf_file_config).popen_cmake( + jobclient, project_dir, build_dir, **kwargs) + + kwargs['env'] = dict(**kwargs.get('env', {}), **self.environ_defs) + return jobclient.popen( + ['/usr/bin/cmake', '-S', project_dir, '-B', build_dir, '-GNinja', + *('-D{}={}'.format(*pair) for pair in self.cmake_defs.items())], + **kwargs) + + def __or__(self, other): + """Combine two BuildConfig instances.""" + if not isinstance(other, BuildConfig): + raise TypeError("Unsupported operation | for {} and {}".format( + type(self), type(other))) + + return BuildConfig( + environ_defs=dict(**self.environ_defs, **other.environ_defs), + cmake_defs=dict(**self.cmake_defs, **other.cmake_defs), + kconfig_defs=dict(**self.kconfig_defs, **other.kconfig_defs), + kconfig_files=list({*self.kconfig_files, *other.kconfig_files})) + + def __repr__(self): + return 'BuildConfig({})'.format(', '.join( + '{}={!r}'.format(name, getattr(self, name)) + for name in ['environ_defs', 'cmake_defs', 'kconfig_defs', + 'kconfig_files'] + if getattr(self, name))) |