Skip to content

Commit 18681b7

Browse files
keith-zephyrChromeos LUCI
authored and
Chromeos LUCI
committed
zmake: add support for static versions
Add a the option "--static" to zmake configure/build. This is passed through to the generate_ec_version.py script to generate static version information for reproducible builds. Note that Zephyr builds require zephyrproject-rtos/zephyr#48195 to compare correctly. BUG=none BRANCH=none TEST=zmake testall TEST=zmake build herobrine -B /tmp/zephyr-rev1 --static TEST=zmake build herobrine -B /tmp/zephyr-rev2 --static TEST=cmp /tmp/zephyr-rev1/herobrine/output/zephyr.bin \ /tmp/zephyr-rev2/herobrine/output/zephyr.bin Signed-off-by: Keith Short <[email protected]> Change-Id: I07361f21c865e2b233ebdb2dc730d25afe13a843 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3786857 Reviewed-by: Abe Levkoy <[email protected]>
1 parent 107a9ad commit 18681b7

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

zephyr/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ add_custom_target(
565565
"--base" "${ZEPHYR_BASE}"
566566
"--name" "${CMAKE_PROJECT_NAME}"
567567
"--module" "${ZEPHYR_MODULES}"
568+
${EXTRA_EC_VERSION_FLAGS}
568569
)
569570
add_dependencies(app ec_version_header)
570571

zephyr/zmake/README.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Chromium OS's meta-build tool for Zephyr
3535

3636
### zmake configure
3737

38-
**Usage:** `zmake configure [-h] [-t TOOLCHAIN] [--bringup] [--clobber] [--allow-warnings] [-B BUILD_DIR] [-c] [--extra-cflags EXTRA_CFLAGS] [--delete-intermediates] (-a | --host-tests-only | --boards-only | project_name [project_name ...])`
38+
**Usage:** `zmake configure [-h] [-t TOOLCHAIN] [--bringup] [--clobber] [--static] [--allow-warnings] [-B BUILD_DIR] [-c] [--extra-cflags EXTRA_CFLAGS] [--delete-intermediates] (-a | --host-tests-only | --boards-only | project_name [project_name ...])`
3939

4040
#### Positional Arguments
4141

@@ -51,6 +51,7 @@ Chromium OS's meta-build tool for Zephyr
5151
| `-t TOOLCHAIN`, `--toolchain TOOLCHAIN` | Name of toolchain to use |
5252
| `--bringup` | Enable bringup debugging features |
5353
| `--clobber` | Delete existing build directories, even if configuration is unchanged |
54+
| `--static` | Generate static version information for reproducible builds |
5455
| `--allow-warnings` | Do not treat warnings as errors |
5556
| `-B BUILD_DIR`, `--build-dir BUILD_DIR` | Root build directory, project files will be in ${build_dir}/${project_name} |
5657
| `-c`, `--coverage` | Enable CONFIG_COVERAGE Kconfig. |
@@ -62,7 +63,7 @@ Chromium OS's meta-build tool for Zephyr
6263

6364
### zmake build
6465

65-
**Usage:** `zmake build [-h] [-t TOOLCHAIN] [--bringup] [--clobber] [--allow-warnings] [-B BUILD_DIR] [-c] [--extra-cflags EXTRA_CFLAGS] [--delete-intermediates] (-a | --host-tests-only | --boards-only | project_name [project_name ...])`
66+
**Usage:** `zmake build [-h] [-t TOOLCHAIN] [--bringup] [--clobber] [--static] [--allow-warnings] [-B BUILD_DIR] [-c] [--extra-cflags EXTRA_CFLAGS] [--delete-intermediates] (-a | --host-tests-only | --boards-only | project_name [project_name ...])`
6667

6768
#### Positional Arguments
6869

@@ -78,6 +79,7 @@ Chromium OS's meta-build tool for Zephyr
7879
| `-t TOOLCHAIN`, `--toolchain TOOLCHAIN` | Name of toolchain to use |
7980
| `--bringup` | Enable bringup debugging features |
8081
| `--clobber` | Delete existing build directories, even if configuration is unchanged |
82+
| `--static` | Generate static version information for reproducible builds |
8183
| `--allow-warnings` | Do not treat warnings as errors |
8284
| `-B BUILD_DIR`, `--build-dir BUILD_DIR` | Root build directory, project files will be in ${build_dir}/${project_name} |
8385
| `-c`, `--coverage` | Enable CONFIG_COVERAGE Kconfig. |
@@ -106,7 +108,7 @@ Chromium OS's meta-build tool for Zephyr
106108

107109
### zmake test
108110

109-
**Usage:** `zmake test [-h] [--no-rebuild] [-t TOOLCHAIN] [--bringup] [--clobber] [--allow-warnings] [-B BUILD_DIR] [-c] [--extra-cflags EXTRA_CFLAGS] [--delete-intermediates] (-a | --host-tests-only | --boards-only | project_name [project_name ...])`
111+
**Usage:** `zmake test [-h] [--no-rebuild] [-t TOOLCHAIN] [--bringup] [--clobber] [--static] [--allow-warnings] [-B BUILD_DIR] [-c] [--extra-cflags EXTRA_CFLAGS] [--delete-intermediates] (-a | --host-tests-only | --boards-only | project_name [project_name ...])`
110112

111113
#### Positional Arguments
112114

@@ -123,6 +125,7 @@ Chromium OS's meta-build tool for Zephyr
123125
| `-t TOOLCHAIN`, `--toolchain TOOLCHAIN` | Name of toolchain to use |
124126
| `--bringup` | Enable bringup debugging features |
125127
| `--clobber` | Delete existing build directories, even if configuration is unchanged |
128+
| `--static` | Generate static version information for reproducible builds |
126129
| `--allow-warnings` | Do not treat warnings as errors |
127130
| `-B BUILD_DIR`, `--build-dir BUILD_DIR` | Root build directory, project files will be in ${build_dir}/${project_name} |
128131
| `-c`, `--coverage` | Enable CONFIG_COVERAGE Kconfig. |
@@ -134,7 +137,7 @@ Chromium OS's meta-build tool for Zephyr
134137

135138
### zmake testall
136139

137-
**Usage:** `zmake testall [-h] [--clobber] [-B BUILD_DIR]`
140+
**Usage:** `zmake testall [-h] [--clobber] [-B BUILD_DIR] [--static]`
138141

139142
#### Optional Arguments
140143

@@ -143,6 +146,7 @@ Chromium OS's meta-build tool for Zephyr
143146
| `-h`, `--help` | show this help message and exit |
144147
| `--clobber` | Delete existing build directories, even if configuration is unchanged |
145148
| `-B BUILD_DIR`, `--build-dir BUILD_DIR` | Build directory |
149+
| `--static` | Generate static version information for reproducible builds |
146150

147151
### zmake generate-readme
148152

zephyr/zmake/zmake/__main__.py

+12
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ def get_argparser():
228228
testall.add_argument(
229229
"-B", "--build-dir", type=pathlib.Path, help="Build directory"
230230
)
231+
testall.add_argument(
232+
"--static",
233+
action="store_true",
234+
dest="static_version",
235+
help="Generate static version information for reproducible builds",
236+
)
231237

232238
generate_readme = sub.add_parser(
233239
"generate-readme",
@@ -268,6 +274,12 @@ def add_common_configure_args(sub_parser: argparse.ArgumentParser):
268274
dest="clobber",
269275
help="Delete existing build directories, even if configuration is unchanged",
270276
)
277+
sub_parser.add_argument(
278+
"--static",
279+
action="store_true",
280+
dest="static_version",
281+
help="Generate static version information for reproducible builds",
282+
)
271283
sub_parser.add_argument(
272284
"--allow-warnings",
273285
action="store_true",

zephyr/zmake/zmake/zmake.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ def configure( # pylint: disable=too-many-arguments,too-many-locals
250250
extra_cflags=None,
251251
delete_intermediates=False,
252252
boards_only=False,
253+
static_version=False,
253254
):
254255
"""Locate and configure the specified projects."""
255256
# Resolve build_dir if needed.
@@ -281,6 +282,7 @@ def configure( # pylint: disable=too-many-arguments,too-many-locals
281282
extra_cflags=extra_cflags,
282283
multiproject=len(projects) > 1,
283284
delete_intermediates=delete_intermediates,
285+
static_version=static_version,
284286
)
285287
)
286288
if self._sequential:
@@ -326,6 +328,7 @@ def build( # pylint: disable=too-many-arguments
326328
extra_cflags=None,
327329
delete_intermediates=False,
328330
boards_only=False,
331+
static_version=False,
329332
):
330333
"""Locate and build the specified projects."""
331334
return self.configure(
@@ -342,6 +345,7 @@ def build( # pylint: disable=too-many-arguments
342345
build_after_configure=True,
343346
delete_intermediates=delete_intermediates,
344347
boards_only=boards_only,
348+
static_version=static_version,
345349
)
346350

347351
def test( # pylint: disable=too-many-arguments,too-many-locals
@@ -359,6 +363,7 @@ def test( # pylint: disable=too-many-arguments,too-many-locals
359363
no_rebuild=False,
360364
delete_intermediates=False,
361365
boards_only=False,
366+
static_version=False,
362367
):
363368
"""Locate and build the specified projects."""
364369
if not no_rebuild:
@@ -376,6 +381,7 @@ def test( # pylint: disable=too-many-arguments,too-many-locals
376381
test_after_configure=True,
377382
delete_intermediates=delete_intermediates,
378383
boards_only=boards_only,
384+
static_version=static_version,
379385
)
380386
# Resolve build_dir if needed.
381387
if not build_dir:
@@ -435,6 +441,7 @@ def testall( # pylint: disable=too-many-arguments
435441
bringup=False,
436442
coverage=False,
437443
allow_warnings=False,
444+
static_version=False,
438445
):
439446
"""Locate and build all the projects."""
440447
return self.test(
@@ -446,6 +453,7 @@ def testall( # pylint: disable=too-many-arguments
446453
coverage=coverage,
447454
allow_warnings=allow_warnings,
448455
all_projects=True,
456+
static_version=static_version,
449457
)
450458

451459
def _configure(
@@ -462,6 +470,7 @@ def _configure(
462470
extra_cflags=None,
463471
multiproject=False,
464472
delete_intermediates=False,
473+
static_version=False,
465474
):
466475
# pylint: disable=too-many-arguments,too-many-locals,too-many-branches
467476
# pylint: disable=too-many-statements
@@ -497,6 +506,11 @@ def _configure(
497506
),
498507
"ZMAKE_INCLUDE_DIR": str(generated_include_dir),
499508
"ZMAKE_PROJECT_NAME": project.config.project_name,
509+
**(
510+
{"EXTRA_EC_VERSION_FLAGS": "--static"}
511+
if static_version
512+
else {}
513+
),
500514
},
501515
)
502516

@@ -645,6 +659,7 @@ def _configure(
645659
coverage=coverage,
646660
output_files_out=output_files,
647661
multiproject=multiproject,
662+
static_version=static_version,
648663
)
649664
if result:
650665
self.failed_projects.append(project.config.project_name)
@@ -687,6 +702,7 @@ def _build( # pylint: disable=too-many-arguments
687702
output_files_out=None,
688703
coverage=False,
689704
multiproject=False,
705+
static_version=False,
690706
):
691707
# pylint: disable=too-many-locals,too-many-branches
692708
"""Build a pre-configured build directory."""
@@ -730,13 +746,17 @@ def wait_and_check_success(procs, writers):
730746
project.config.project_name,
731747
build_dir / "zephyr_base",
732748
zmake.modules.locate_from_directory(build_dir / "modules"),
749+
static=static_version,
733750
)
734751

735752
# The version header needs to generated during the build phase
736753
# instead of configure, as the tree may have changed since
737754
# configure was run.
738755
zmake.version.write_version_header(
739-
version_string, build_dir / "include" / "ec_version.h", "zmake"
756+
version_string,
757+
build_dir / "include" / "ec_version.h",
758+
"zmake",
759+
static=static_version,
740760
)
741761

742762
gcov = "gcov.sh-not-found"

0 commit comments

Comments
 (0)