diff options
author | Jack Rosenthal <jrosenth@chromium.org> | 2021-08-20 10:23:55 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-08-20 17:36:11 +0000 |
commit | 4c1cdd23cb35964608f0a2666f933987b4573899 (patch) | |
tree | 52a8b6531745e8893839d2c5a8f36331a882f061 /zephyr/zmake/zmake/version.py | |
parent | 93adb802c1a626fbb73d762124e90be4fee08a8b (diff) | |
download | chrome-ec-4c1cdd23cb35964608f0a2666f933987b4573899.tar.gz |
Reland "zephyr: pull in the version string from zmake"
This reverts commit 93adb802c1a626fbb73d762124e90be4fee08a8b.
This commit was reverted due to build failures with the
chromeos-zephyr ebuild. The root cause of the build failures was that
the ebuild uses different working directories between the configure
and build phases, and so the path to the include directory we generate
during the configure phase won't work in the build phase.
Use the full path here so that we can run the diffrerent phases in
different working directories.
Diff from original commit:
Change-Id: Idcbd0c0546f9fcb12fcd66c617e024b8aa2a893a
> --- a/zephyr/zmake/zmake/zmake.py
> +++ b/zephyr/zmake/zmake/zmake.py
> @@ -235,7 +235,7 @@ class Zmake:
> self.logger.info("Clearing old build directory %s", build_dir)
> shutil.rmtree(build_dir)
>
> - generated_include_dir = build_dir / "include"
> + generated_include_dir = (build_dir / "include").resolve()
> base_config = zmake.build_config.BuildConfig(
> environ_defs={"ZEPHYR_BASE": str(zephyr_base), "PATH": "/usr/bin"},
> cmake_defs={
BUG=b:197287679
BRANCH=none
TEST=emerge-volteer chromeos-zephyr
Signed-off-by: Jack Rosenthal <jrosenth@chromium.org>
Change-Id: I80cec7a1622edcecc670b7dbeed56dadcdf71555
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3111305
Commit-Queue: Yuval Peress <peress@chromium.org>
Reviewed-by: Yuval Peress <peress@chromium.org>
Diffstat (limited to 'zephyr/zmake/zmake/version.py')
-rw-r--r-- | zephyr/zmake/zmake/version.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/zephyr/zmake/zmake/version.py b/zephyr/zmake/zmake/version.py index 404c05cb74..2d505769f2 100644 --- a/zephyr/zmake/zmake/version.py +++ b/zephyr/zmake/zmake/version.py @@ -2,7 +2,11 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import datetime +import getpass +import io import os +import platform import subprocess import zmake.util as util @@ -114,3 +118,42 @@ def get_version_string(project, zephyr_base, modules, static=False): return "{}_v{}.{}.{}-{}".format( project_id, major_version, minor_version, num_commits, vcs_hashes ) + + +def write_version_header(version_str, output_path, static=False): + """Generate a version header and write it to the specified path. + + Generate a version header in the format expected by the EC build + system, and write it out only if the version header does not exist + or changes. We don't write in the case that the version header + does exist and was unchanged, which allows "zmake build" commands + on an unchanged tree to be an effective no-op. + + Args: + version_str: The version string to be used in the header, such + as one generated by get_version_string. + output_path: The file path to write at (a pathlib.Path + object). + static: If true, generate a header which does not include + information like the username, hostname, or date, allowing + the build to be reproducible. + """ + output = io.StringIO() + output.write("/* This file is automatically generated by zmake */\n") + + def add_def(name, value): + output.write("#define {} {}\n".format(name, util.c_str(value))) + + add_def("VERSION", version_str) + add_def("CROS_EC_VERSION32", version_str[:31]) + + if static: + add_def("BUILDER", "reproducible@build") + add_def("DATE", "STATIC_VERSION_DATE") + else: + add_def("BUILDER", "{}@{}".format(getpass.getuser(), platform.node())) + add_def("DATE", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) + + contents = output.getvalue() + if not output_path.exists() or output_path.read_text() != contents: + output_path.write_text(contents) |