summaryrefslogtreecommitdiff
path: root/zephyr/zmake
diff options
context:
space:
mode:
authorRob Barnes <robbarnes@google.com>2021-08-20 14:36:21 +0000
committerRob Barnes <robbarnes@google.com>2021-08-20 15:25:53 +0000
commit93adb802c1a626fbb73d762124e90be4fee08a8b (patch)
tree8ba2b19cf7a2ec4d24dde1424bfcd46d4865e231 /zephyr/zmake
parent8270698e589f14239b4942a42b27132af497410b (diff)
downloadchrome-ec-93adb802c1a626fbb73d762124e90be4fee08a8b.tar.gz
Revert "zephyr: pull in the version string from zmake"
This reverts commit 10809eb023d475681b45863e68d906fae4667eda. Reason for revert: Causing build errors b/197287679 Original change's description: > zephyr: pull in the version string from zmake > > Zmake computes a version string and stores it in FRID/FWID, but this > was never plumbed all the way out into the version functionality in > the OS, which was reporting the version generated by > util/getversion.sh. > > Add a mechanism to generate the version header from zmake and replace > the getversion.sh generation with that. > > BUG=b:184832251 > BRANCH=none > TEST=provided unit tests > TEST=get this version string on posix-ec: > posix-ec_v2.6.73347-cmsis:c3bd20,ec:c814a9,hal_stm32:f8ff8d,os:efe095 > 2021-08-18 14:10:18 jrosenth@germania > > Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> > Change-Id: Idec1c5f8b5f014126706e4fdc1f3d158edf40a63 > Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3104625 > Reviewed-by: Denis Brockus <dbrockus@chromium.org> Bug: b:184832251 Change-Id: Ifcc4830e3097c8dc8126bb76adfeb3ce75a7a667 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3110293 Auto-Submit: Rob Barnes <robbarnes@google.com> Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Commit-Queue: Jack Rosenthal <jrosenth@chromium.org> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Diffstat (limited to 'zephyr/zmake')
-rw-r--r--zephyr/zmake/tests/test_util.py15
-rw-r--r--zephyr/zmake/tests/test_version.py81
-rw-r--r--zephyr/zmake/tests/test_zmake.py3
-rw-r--r--zephyr/zmake/zmake/util.py23
-rw-r--r--zephyr/zmake/zmake/version.py43
-rw-r--r--zephyr/zmake/zmake/zmake.py12
6 files changed, 1 insertions, 176 deletions
diff --git a/zephyr/zmake/tests/test_util.py b/zephyr/zmake/tests/test_util.py
index 0524a153fd..15f92f58ab 100644
--- a/zephyr/zmake/tests/test_util.py
+++ b/zephyr/zmake/tests/test_util.py
@@ -87,18 +87,3 @@ def test_read_kconfig_autoconf_value(value):
f.write("#define TEST {}".format(value))
read_value = util.read_kconfig_autoconf_value(path, "TEST")
assert int(read_value) == value
-
-
-@pytest.mark.parametrize(
- ["input_str", "expected_result"],
- [
- ("", '""'),
- ("TROGDOR ABC-123", '"TROGDOR ABC-123"'),
- ("hello world", '"hello world"'),
- ("hello\nworld", r'"hello\nworld"'),
- ('hello"world', r'"hello\"world"'),
- ("hello\\world", '"hello\\\\world"'),
- ],
-)
-def test_c_str(input_str, expected_result):
- assert util.c_str(input_str) == expected_result
diff --git a/zephyr/zmake/tests/test_version.py b/zephyr/zmake/tests/test_version.py
index 8fb4a09435..ff8e366736 100644
--- a/zephyr/zmake/tests/test_version.py
+++ b/zephyr/zmake/tests/test_version.py
@@ -2,11 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import datetime
import subprocess
-import unittest.mock as mock
-
-import pytest
import zmake.project
import zmake.version as version
@@ -100,80 +96,3 @@ def test_version_string_static(tmp_path):
version.get_version_string(project, zephyr_base, modules, static=True)
== "prj_v2.6.0-STATIC"
)
-
-
-@pytest.fixture
-def fake_user_hostname():
- with mock.patch("getpass.getuser", return_value="toukmond", autospec=True):
- with mock.patch("platform.node", return_value="pokey", autospec=True):
- yield
-
-
-@pytest.fixture
-def fake_date():
- fixed_date = datetime.datetime(2021, 6, 28, 3, 18, 53)
- with mock.patch("datetime.datetime") as mock_datetime:
- mock_datetime.now.return_value = fixed_date
- yield
-
-
-HEADER_VERSION_STR = "trogdor_v2.6.1004-cmsis:0dead0,hal_stm32:0beef0,os:ad00da"
-EXPECTED_HEADER = (
- "/* This file is automatically generated by zmake */\n"
- '#define VERSION "trogdor_v2.6.1004-cmsis:0dead0,hal_stm32:0beef0,os:ad00da"\n'
- '#define CROS_EC_VERSION32 "trogdor_v2.6.1004-cmsis:0dead0,"\n'
- '#define BUILDER "toukmond@pokey"\n'
- '#define DATE "2021-06-28 03:18:53"\n'
-)
-HEADER_VERSION_STR_STATIC = "trogdor_v2.6.0-STATIC"
-EXPECTED_HEADER_STATIC = (
- "/* This file is automatically generated by zmake */\n"
- '#define VERSION "trogdor_v2.6.0-STATIC"\n'
- '#define CROS_EC_VERSION32 "trogdor_v2.6.0-STATIC"\n'
- '#define BUILDER "reproducible@build"\n'
- '#define DATE "STATIC_VERSION_DATE"\n'
-)
-
-
-def test_header_gen(fake_user_hostname, fake_date, tmp_path):
- # Test the simple case (static=False, no existing header).
- output_file = tmp_path / "ec_version.h"
- version.write_version_header(HEADER_VERSION_STR, output_file)
- assert output_file.read_text() == EXPECTED_HEADER
-
-
-def test_header_gen_reproducible_build(tmp_path):
- # With static=True this time.
- output_file = tmp_path / "ec_version.h"
- version.write_version_header(HEADER_VERSION_STR_STATIC, output_file, static=True)
- assert output_file.read_text() == EXPECTED_HEADER_STATIC
-
-
-def test_header_gen_exists_not_changed(fake_user_hostname, fake_date, tmp_path):
- # Test we don't overwrite if no changes needed.
- output_file = tmp_path / "ec_version.h"
-
- # First time, write and record mtime.
- version.write_version_header(HEADER_VERSION_STR, output_file)
- expected_mtime = output_file.stat().st_mtime
-
- # Do another write (contents should be unchanged).
- version.write_version_header(HEADER_VERSION_STR, output_file)
-
- # Assert we didn't write again.
- assert output_file.stat().st_mtime == expected_mtime
-
-
-def test_header_gen_exists_needs_changes(fake_user_hostname, fake_date, tmp_path):
- # Test we overwrite when it exists already and changes are needed.
- output_file = tmp_path / "ec_version.h"
-
- # First time, write and save contents.
- version.write_version_header(HEADER_VERSION_STR, output_file)
- original_contents = output_file.read_text()
-
- # Do another write (contents should be changed).
- version.write_version_header(HEADER_VERSION_STR_STATIC, output_file, static=True)
-
- # Assert we overwrote.
- assert output_file.read_text() != original_contents
diff --git a/zephyr/zmake/tests/test_zmake.py b/zephyr/zmake/tests/test_zmake.py
index f7978764f8..a5c132dbaa 100644
--- a/zephyr/zmake/tests/test_zmake.py
+++ b/zephyr/zmake/tests/test_zmake.py
@@ -141,8 +141,7 @@ EXTRAVERSION =
pathlib.Path(tmpname), build_dir=pathlib.Path("build")
)
else:
- with patch("zmake.version.write_version_header", autospec=True):
- zmk.build(pathlib.Path(tmpname))
+ zmk.build(pathlib.Path(tmpname))
multiproc.wait_for_log_end()
recs = [rec.getMessage() for rec in cap.records]
diff --git a/zephyr/zmake/zmake/util.py b/zephyr/zmake/zmake/util.py
index 455cb7c9d6..18d03dd7f0 100644
--- a/zephyr/zmake/zmake/util.py
+++ b/zephyr/zmake/zmake/util.py
@@ -9,29 +9,6 @@ import re
import shlex
-def c_str(input_str):
- """Make a string that can be included as a literal in C source code.
-
- Args:
- input_str: The string to process.
-
- Returns:
- A string which can be included in C source code.
- """
-
- def c_chr(char):
- # Convert a char in a string to the C representation. Per the
- # C standard, we can use all characters but quote, newline,
- # and backslash directly with no replacements.
- return {
- '"': r"\"",
- "\n": r"\n",
- "\\": "\\\\",
- }.get(char, char)
-
- return '"{}"'.format("".join(map(c_chr, input_str)))
-
-
def locate_cros_checkout():
"""Find the path to the ChromiumOS checkout.
diff --git a/zephyr/zmake/zmake/version.py b/zephyr/zmake/zmake/version.py
index 2d505769f2..404c05cb74 100644
--- a/zephyr/zmake/zmake/version.py
+++ b/zephyr/zmake/zmake/version.py
@@ -2,11 +2,7 @@
# 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
@@ -118,42 +114,3 @@ 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)
diff --git a/zephyr/zmake/zmake/zmake.py b/zephyr/zmake/zmake/zmake.py
index 0d3dbb6450..45e23fd904 100644
--- a/zephyr/zmake/zmake/zmake.py
+++ b/zephyr/zmake/zmake/zmake.py
@@ -235,7 +235,6 @@ class Zmake:
self.logger.info("Clearing old build directory %s", build_dir)
shutil.rmtree(build_dir)
- generated_include_dir = build_dir / "include"
base_config = zmake.build_config.BuildConfig(
environ_defs={"ZEPHYR_BASE": str(zephyr_base), "PATH": "/usr/bin"},
cmake_defs={
@@ -243,7 +242,6 @@ class Zmake:
"SYSCALL_INCLUDE_DIRS": str(
self.module_paths["ec"] / "zephyr" / "include" / "drivers"
),
- "ZMAKE_INCLUDE_DIR": str(generated_include_dir),
},
)
@@ -276,8 +274,6 @@ class Zmake:
if not build_dir.exists():
build_dir = build_dir.mkdir()
- if not generated_include_dir.exists():
- generated_include_dir.mkdir()
processes = []
self.logger.info("Building %s in %s.", project_dir, build_dir)
for build_name, build_config in project.iter_builds():
@@ -379,14 +375,6 @@ class Zmake:
zmake.modules.locate_from_directory(build_dir / "modules"),
)
- # The version header needs to generated during the build phase
- # instead of configure, as the tree may have changed since
- # configure was run.
- zmake.version.write_version_header(
- version_string,
- build_dir / "include" / "ec_version.h",
- )
-
for build_name, build_config in project.iter_builds():
with self.jobserver.get_job():
dirs[build_name] = build_dir / "build-{}".format(build_name)