diff options
60 files changed, 506 insertions, 680 deletions
diff --git a/util/flash_ec b/util/flash_ec index a297d84a20..d92a002d01 100755 --- a/util/flash_ec +++ b/util/flash_ec @@ -272,18 +272,6 @@ function dut_control_get_or_die { : ${BOARD:=${FLAGS_board}} -# Find the Zephyr project directory for the specified board. Zephyr projects -# organized under ./zephyr/projects and always contain the file zmake.yaml -mapfile -t zephyr_projects < <(find zephyr/projects/ -type f -name "zmake.yaml") -for i in "${zephyr_projects[@]}"; do - zephyr_project_dir=$(dirname "${i}") - zephyr_project_name=$(basename "${zephyr_project_dir}") - if [[ "${BOARD}" = "${zephyr_project_name}" ]]; then - ZEPHYR_DIR="${zephyr_project_dir}" - break - fi -done - in_array() { local n=$# local value=${!n} @@ -701,7 +689,7 @@ if [[ -n "${EC_DIR}" ]]; then if [ "${FLAGS_ro}" = ${FLAGS_TRUE} ] ; then LOCAL_BUILD="${EC_DIR}/build/${BOARD}/RO/${EC_FILE}" elif [ "${FLAGS_zephyr}" = ${FLAGS_TRUE} ] ; then - LOCAL_BUILD="${EC_DIR}/build/${ZEPHYR_DIR}/output/${EC_FILE}" + LOCAL_BUILD="${EC_DIR}/build/zephyr/${BOARD}/output/${EC_FILE}" else LOCAL_BUILD="${EC_DIR}/build/${BOARD}/${EC_FILE}" fi @@ -1448,7 +1436,7 @@ function flash_npcx_uut() { "$(dirname "$IMG")/chip/npcx/spiflashfw" \ "$(dirname "$IMG")" \ "${EC_DIR}/build/${BOARD}/chip/npcx/spiflashfw" \ - "${EC_DIR}/build/${ZEPHYR_DIR}/output" \ + "${EC_DIR}/build/zephyr/${BOARD}/output" \ "$(dirname "$LOCAL_BUILD")" \ "$(dirname "$EMERGE_BUILD")" ; do diff --git a/zephyr/firmware_builder.py b/zephyr/firmware_builder.py index 446ad20bee..b8b8756416 100755 --- a/zephyr/firmware_builder.py +++ b/zephyr/firmware_builder.py @@ -99,18 +99,14 @@ def bundle_firmware(opts): bundle_dir = get_bundle_dir(opts) zephyr_dir = pathlib.Path(__file__).parent platform_ec = zephyr_dir.resolve().parent - for project in zmake.project.find_projects(zephyr_dir): - build_dir = zmake.util.resolve_build_dir(platform_ec, - project.project_dir, None) + for project in zmake.project.find_projects(zephyr_dir).values(): + build_dir = platform_ec / "build" / "zephyr" / project.config.name artifacts_dir = build_dir / 'output' # TODO(kmshelton): Remove once the build command does not rely # on a pre-defined list of targets. if not artifacts_dir.is_dir(): continue - project_identifier = '_'.join( - project.project_dir. - parts[project.project_dir.parts.index('projects') + 1:]) - tarball_name = '{}.firmware.tbz2'.format(project_identifier) + tarball_name = '{}.firmware.tbz2'.format(project.config.name) tarball_path = bundle_dir.joinpath(tarball_name) cmd = ['tar', 'cvfj', tarball_path, '.'] subprocess.run(cmd, cwd=artifacts_dir, check=True) diff --git a/zephyr/projects/brya/brya/zmake.yaml b/zephyr/projects/asurada/hayato/BUILD.py index 851b7f8a3f..a8d71628b2 100644 --- a/zephyr/projects/brya/brya/zmake.yaml +++ b/zephyr/projects/asurada/hayato/BUILD.py @@ -2,12 +2,8 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -board: brya -dts-overlays: - - gpio.dts -supported-toolchains: - - coreboot-sdk - - zephyr -supported-zephyr-versions: - - v2.7 -output-type: npcx +register_binman_project( + "hayato", + zephyr_board="asurada", + dts_overlays=["battery.dts", "gpio.dts", "motionsense.dts", "pwm.dts"], +) diff --git a/zephyr/projects/asurada/hayato/zmake.yaml b/zephyr/projects/asurada/hayato/zmake.yaml deleted file mode 100644 index 3564019276..0000000000 --- a/zephyr/projects/asurada/hayato/zmake.yaml +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright 2021 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. - -board: asurada -dts-overlays: - - battery.dts - - gpio.dts - - motionsense.dts - - pwm.dts -supported-toolchains: - - coreboot-sdk - - zephyr -supported-zephyr-versions: - - v2.7 -output-type: binman diff --git a/zephyr/projects/kohaku/zmake.yaml b/zephyr/projects/brya/brya/BUILD.py index 5875a955b0..ba0d2fd369 100644 --- a/zephyr/projects/kohaku/zmake.yaml +++ b/zephyr/projects/brya/brya/BUILD.py @@ -2,10 +2,8 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -board: kohaku -supported-toolchains: - - coreboot-sdk - - zephyr -supported-zephyr-versions: - - v2.7 -output-type: npcx +register_npcx_project( + "brya", + zephyr_board="brya", + dts_overlays=["gpio.dts"], +) diff --git a/zephyr/test/ec_app/zmake.yaml b/zephyr/projects/corsola/kingler/BUILD.py index e28a79e670..07adc8b3d6 100644 --- a/zephyr/test/ec_app/zmake.yaml +++ b/zephyr/projects/corsola/kingler/BUILD.py @@ -2,11 +2,8 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -board: native_posix -supported-zephyr-versions: - - v2.7 -supported-toolchains: - - llvm - - host -output-type: elf -is-test: true +register_npcx_project( + "kingler", + zephyr_board="npcx9", + dts_overlays=["battery.dts", "gpio.dts", "i2c.dts"], +) diff --git a/zephyr/projects/corsola/kingler/zmake.yaml b/zephyr/projects/corsola/kingler/zmake.yaml deleted file mode 100644 index 581cc87521..0000000000 --- a/zephyr/projects/corsola/kingler/zmake.yaml +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2021 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. - -board: npcx9 -dts-overlays: - - battery.dts - - gpio.dts - - i2c.dts -supported-toolchains: - - coreboot-sdk - - zephyr -supported-zephyr-versions: - - v2.7 -output-type: npcx diff --git a/zephyr/projects/corsola/krabby/BUILD.py b/zephyr/projects/corsola/krabby/BUILD.py new file mode 100644 index 0000000000..03c86a5013 --- /dev/null +++ b/zephyr/projects/corsola/krabby/BUILD.py @@ -0,0 +1,9 @@ +# Copyright 2021 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. + +register_binman_project( + "krabby", + zephyr_board="it8xxx2", + dts_overlays=["battery.dts", "gpio.dts", "motionsense.dts", "pwm.dts"], +) diff --git a/zephyr/projects/corsola/krabby/zmake.yaml b/zephyr/projects/corsola/krabby/zmake.yaml deleted file mode 100644 index c31e34eccb..0000000000 --- a/zephyr/projects/corsola/krabby/zmake.yaml +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright 2021 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. - -board: it8xxx2 -dts-overlays: - - battery.dts - - gpio.dts - - motionsense.dts - - pwm.dts -supported-toolchains: - - coreboot-sdk - - zephyr -supported-zephyr-versions: - - v2.7 -output-type: binman diff --git a/zephyr/test/accel_cal/zmake.yaml b/zephyr/projects/guybrush/BUILD.py index e28a79e670..f4e30d2dc0 100644 --- a/zephyr/test/accel_cal/zmake.yaml +++ b/zephyr/projects/guybrush/BUILD.py @@ -2,11 +2,8 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -board: native_posix -supported-zephyr-versions: - - v2.7 -supported-toolchains: - - llvm - - host -output-type: elf -is-test: true +register_npcx_project( + "guybrush", + zephyr_board="npcx9", + dts_overlays=["battery.dts", "gpio.dts", "i2c.dts"], +) diff --git a/zephyr/projects/guybrush/zmake.yaml b/zephyr/projects/guybrush/zmake.yaml deleted file mode 100644 index 581cc87521..0000000000 --- a/zephyr/projects/guybrush/zmake.yaml +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2021 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. - -board: npcx9 -dts-overlays: - - battery.dts - - gpio.dts - - i2c.dts -supported-toolchains: - - coreboot-sdk - - zephyr -supported-zephyr-versions: - - v2.7 -output-type: npcx diff --git a/zephyr/projects/herobrine/herobrine_npcx9/BUILD.py b/zephyr/projects/herobrine/herobrine_npcx9/BUILD.py new file mode 100644 index 0000000000..dbb5e6c087 --- /dev/null +++ b/zephyr/projects/herobrine/herobrine_npcx9/BUILD.py @@ -0,0 +1,16 @@ +# Copyright 2021 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. + +register_npcx_project( + "herobrine_npcx9", + zephyr_board="herobrine_npcx9", + dts_overlays=[ + "gpio.dts", + "battery.dts", + "i2c.dts", + "motionsense.dts", + "switchcap.dts", + "usbc.dts", + ], +) diff --git a/zephyr/projects/herobrine/herobrine_npcx9/zmake.yaml b/zephyr/projects/herobrine/herobrine_npcx9/zmake.yaml deleted file mode 100644 index fa290fe6d4..0000000000 --- a/zephyr/projects/herobrine/herobrine_npcx9/zmake.yaml +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright 2021 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. - -board: herobrine_npcx9 -dts-overlays: - - gpio.dts - - battery.dts - - i2c.dts - - motionsense.dts - - switchcap.dts - - usbc.dts -supported-toolchains: - - coreboot-sdk - - zephyr -supported-zephyr-versions: - - v2.7 -output-type: npcx diff --git a/zephyr/projects/it8xxx2_evb/zmake.yaml b/zephyr/projects/it8xxx2_evb/BUILD.py index f39dda1238..545bc9c939 100644 --- a/zephyr/projects/it8xxx2_evb/zmake.yaml +++ b/zephyr/projects/it8xxx2_evb/BUILD.py @@ -2,10 +2,7 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -board: it8xxx2_evb -supported-toolchains: - - coreboot-sdk - - zephyr -supported-zephyr-versions: - - v2.7 -output-type: raw +register_raw_project( + "it8xxx2_evb", + zephyr_board="it8xxx2_evb", +) diff --git a/zephyr/projects/kohaku/BUILD.py b/zephyr/projects/kohaku/BUILD.py new file mode 100644 index 0000000000..b21d4e9453 --- /dev/null +++ b/zephyr/projects/kohaku/BUILD.py @@ -0,0 +1,8 @@ +# Copyright 2021 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. + +register_npcx_project( + "kohaku", + zephyr_board="kohaku", +) diff --git a/zephyr/projects/npcx_evb/npcx7/BUILD.py b/zephyr/projects/npcx_evb/npcx7/BUILD.py new file mode 100644 index 0000000000..70d91a3b23 --- /dev/null +++ b/zephyr/projects/npcx_evb/npcx7/BUILD.py @@ -0,0 +1,9 @@ +# Copyright 2021 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. + +register_npcx_project( + "npcx7", + zephyr_board="npcx7_evb", + dts_overlays=["gpio.dts", "pwm.dts", "fan.dts", "keyboard.dts"], +) diff --git a/zephyr/projects/npcx_evb/npcx7/zmake.yaml b/zephyr/projects/npcx_evb/npcx7/zmake.yaml deleted file mode 100644 index cbc95f36c8..0000000000 --- a/zephyr/projects/npcx_evb/npcx7/zmake.yaml +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright 2021 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. - -board: npcx7_evb -dts-overlays: - - gpio.dts - - pwm.dts - - fan.dts - - keyboard.dts -supported-toolchains: - - coreboot-sdk - - zephyr -supported-zephyr-versions: - - v2.7 -output-type: npcx diff --git a/zephyr/projects/npcx_evb/npcx9/BUILD.py b/zephyr/projects/npcx_evb/npcx9/BUILD.py new file mode 100644 index 0000000000..d42039d19f --- /dev/null +++ b/zephyr/projects/npcx_evb/npcx9/BUILD.py @@ -0,0 +1,9 @@ +# Copyright 2021 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. + +register_npcx_project( + "npcx9", + zephyr_board="npcx9_evb", + dts_overlays=["gpio.dts", "pwm.dts", "fan.dts", "keyboard.dts"], +) diff --git a/zephyr/projects/npcx_evb/npcx9/zmake.yaml b/zephyr/projects/npcx_evb/npcx9/zmake.yaml deleted file mode 100644 index b71dc4b8f6..0000000000 --- a/zephyr/projects/npcx_evb/npcx9/zmake.yaml +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright 2021 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. - -board: npcx9_evb -dts-overlays: - - gpio.dts - - pwm.dts - - fan.dts - - keyboard.dts -supported-toolchains: - - coreboot-sdk - - zephyr -supported-zephyr-versions: - - v2.7 -output-type: npcx diff --git a/zephyr/projects/posix-ec/BUILD.py b/zephyr/projects/posix-ec/BUILD.py new file mode 100644 index 0000000000..38cc621739 --- /dev/null +++ b/zephyr/projects/posix-ec/BUILD.py @@ -0,0 +1,5 @@ +# Copyright 2021 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. + +register_host_project("posix-ec") diff --git a/zephyr/projects/posix-ec/zmake.yaml b/zephyr/projects/posix-ec/zmake.yaml deleted file mode 100644 index ce14ef9f7d..0000000000 --- a/zephyr/projects/posix-ec/zmake.yaml +++ /dev/null @@ -1,7 +0,0 @@ -board: native_posix -supported-toolchains: - - llvm - - host -supported-zephyr-versions: - - v2.7 -output-type: elf diff --git a/zephyr/projects/trogdor/lazor/BUILD.py b/zephyr/projects/trogdor/lazor/BUILD.py new file mode 100644 index 0000000000..e7dff809af --- /dev/null +++ b/zephyr/projects/trogdor/lazor/BUILD.py @@ -0,0 +1,15 @@ +# Copyright 2021 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. + +register_npcx_project( + "lazor", + zephyr_board="trogdor", + dts_overlays=[ + "battery.dts", + "gpio.dts", + "keyboard.dts", + "led.dts", + "motionsense.dts", + ], +) diff --git a/zephyr/projects/trogdor/lazor/zmake.yaml b/zephyr/projects/trogdor/lazor/zmake.yaml deleted file mode 100644 index e93b82da09..0000000000 --- a/zephyr/projects/trogdor/lazor/zmake.yaml +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2021 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. - -board: trogdor -dts-overlays: - - battery.dts - - gpio.dts - - keyboard.dts - - led.dts - - motionsense.dts -supported-toolchains: - - coreboot-sdk - - zephyr -supported-zephyr-versions: - - v2.7 -output-type: npcx diff --git a/zephyr/projects/trogdor/trogdor/BUILD.py b/zephyr/projects/trogdor/trogdor/BUILD.py new file mode 100644 index 0000000000..fd6dc1113f --- /dev/null +++ b/zephyr/projects/trogdor/trogdor/BUILD.py @@ -0,0 +1,9 @@ +# Copyright 2021 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. + +register_npcx_project( + "trogdor", + zephyr_board="trogdor", + dts_overlays=["gpio.dts", "battery.dts", "motionsense.dts"], +) diff --git a/zephyr/projects/trogdor/trogdor/zmake.yaml b/zephyr/projects/trogdor/trogdor/zmake.yaml deleted file mode 100644 index fbd8ff3382..0000000000 --- a/zephyr/projects/trogdor/trogdor/zmake.yaml +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2021 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. - -board: trogdor -dts-overlays: - - gpio.dts - - battery.dts - - motionsense.dts -supported-toolchains: - - coreboot-sdk - - zephyr -supported-zephyr-versions: - - v2.7 -output-type: npcx diff --git a/zephyr/projects/volteer/delbin/BUILD.py b/zephyr/projects/volteer/delbin/BUILD.py new file mode 100644 index 0000000000..02508eedb3 --- /dev/null +++ b/zephyr/projects/volteer/delbin/BUILD.py @@ -0,0 +1,9 @@ +# Copyright 2021 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. + +register_npcx_project( + "delbin", + zephyr_board="volteer", + dts_overlays=["gpio.dts", "motionsense.dts"], +) diff --git a/zephyr/projects/volteer/delbin/zmake.yaml b/zephyr/projects/volteer/delbin/zmake.yaml deleted file mode 100644 index 25480e3c7f..0000000000 --- a/zephyr/projects/volteer/delbin/zmake.yaml +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright 2021 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. - -board: volteer -dts-overlays: - - gpio.dts - - motionsense.dts -supported-toolchains: - - coreboot-sdk - - zephyr -supported-zephyr-versions: - - v2.7 -output-type: npcx diff --git a/zephyr/projects/volteer/volteer/BUILD.py b/zephyr/projects/volteer/volteer/BUILD.py new file mode 100644 index 0000000000..705ddde5bb --- /dev/null +++ b/zephyr/projects/volteer/volteer/BUILD.py @@ -0,0 +1,19 @@ +# Copyright 2021 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. + +register_npcx_project( + "volteer", + zephyr_board="volteer", + dts_overlays=[ + "bb_retimer.dts", + "cbi_eeprom.dts", + "fan.dts", + "gpio.dts", + "keyboard.dts", + "motionsense.dts", + "pwm.dts", + "pwm_leds.dts", + "usbc.dts", + ], +) diff --git a/zephyr/projects/volteer/volteer/zmake.yaml b/zephyr/projects/volteer/volteer/zmake.yaml deleted file mode 100644 index d8b2ce7a61..0000000000 --- a/zephyr/projects/volteer/volteer/zmake.yaml +++ /dev/null @@ -1,21 +0,0 @@ -# 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. - -board: volteer -dts-overlays: - - bb_retimer.dts - - cbi_eeprom.dts - - fan.dts - - gpio.dts - - keyboard.dts - - motionsense.dts - - pwm.dts - - pwm_leds.dts - - usbc.dts -supported-toolchains: - - coreboot-sdk - - zephyr -supported-zephyr-versions: - - v2.7 -output-type: npcx diff --git a/zephyr/test/accel_cal/BUILD.py b/zephyr/test/accel_cal/BUILD.py new file mode 100644 index 0000000000..bb50fd4301 --- /dev/null +++ b/zephyr/test/accel_cal/BUILD.py @@ -0,0 +1,5 @@ +# Copyright 2021 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. + +register_host_test("accel_cal") diff --git a/zephyr/test/base32/BUILD.py b/zephyr/test/base32/BUILD.py new file mode 100644 index 0000000000..67e7c50089 --- /dev/null +++ b/zephyr/test/base32/BUILD.py @@ -0,0 +1,5 @@ +# Copyright 2021 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. + +register_host_test("base32") diff --git a/zephyr/test/base32/zmake.yaml b/zephyr/test/base32/zmake.yaml deleted file mode 100644 index fa16329e9c..0000000000 --- a/zephyr/test/base32/zmake.yaml +++ /dev/null @@ -1,12 +0,0 @@ -# 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. - -board: native_posix -supported-zephyr-versions: - - v2.7 -supported-toolchains: - - llvm - - host -output-type: elf -is-test: true diff --git a/zephyr/test/crc/BUILD.py b/zephyr/test/crc/BUILD.py new file mode 100644 index 0000000000..17136be0ce --- /dev/null +++ b/zephyr/test/crc/BUILD.py @@ -0,0 +1,5 @@ +# Copyright 2021 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. + +register_host_test("crc") diff --git a/zephyr/test/crc/zmake.yaml b/zephyr/test/crc/zmake.yaml deleted file mode 100644 index fa16329e9c..0000000000 --- a/zephyr/test/crc/zmake.yaml +++ /dev/null @@ -1,12 +0,0 @@ -# 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. - -board: native_posix -supported-zephyr-versions: - - v2.7 -supported-toolchains: - - llvm - - host -output-type: elf -is-test: true diff --git a/zephyr/test/drivers/BUILD.py b/zephyr/test/drivers/BUILD.py new file mode 100644 index 0000000000..1653103526 --- /dev/null +++ b/zephyr/test/drivers/BUILD.py @@ -0,0 +1,5 @@ +# Copyright 2021 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. + +register_host_test("drivers", dts_overlays=["overlay.dts"]) diff --git a/zephyr/test/drivers/zmake.yaml b/zephyr/test/drivers/zmake.yaml deleted file mode 100644 index 14239fbd4b..0000000000 --- a/zephyr/test/drivers/zmake.yaml +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright 2021 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. - -board: native_posix -supported-zephyr-versions: - - v2.7 -supported-toolchains: - - llvm - - host -output-type: elf -is-test: true -dts-overlays: - - overlay.dts diff --git a/zephyr/test/ec_app/BUILD.py b/zephyr/test/ec_app/BUILD.py new file mode 100644 index 0000000000..48d072fe19 --- /dev/null +++ b/zephyr/test/ec_app/BUILD.py @@ -0,0 +1,5 @@ +# Copyright 2021 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. + +register_host_test("ec_app") diff --git a/zephyr/test/hooks/BUILD.py b/zephyr/test/hooks/BUILD.py new file mode 100644 index 0000000000..6b20daea30 --- /dev/null +++ b/zephyr/test/hooks/BUILD.py @@ -0,0 +1,5 @@ +# Copyright 2021 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. + +register_host_test("hooks") diff --git a/zephyr/test/hooks/zmake.yaml b/zephyr/test/hooks/zmake.yaml deleted file mode 100644 index fa16329e9c..0000000000 --- a/zephyr/test/hooks/zmake.yaml +++ /dev/null @@ -1,12 +0,0 @@ -# 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. - -board: native_posix -supported-zephyr-versions: - - v2.7 -supported-toolchains: - - llvm - - host -output-type: elf -is-test: true diff --git a/zephyr/test/i2c/BUILD.py b/zephyr/test/i2c/BUILD.py new file mode 100644 index 0000000000..150926dc69 --- /dev/null +++ b/zephyr/test/i2c/BUILD.py @@ -0,0 +1,5 @@ +# Copyright 2021 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. + +register_host_test("i2c", dts_overlays=["overlay.dts"]) diff --git a/zephyr/test/i2c/zmake.yaml b/zephyr/test/i2c/zmake.yaml deleted file mode 100644 index d3ba38ccfa..0000000000 --- a/zephyr/test/i2c/zmake.yaml +++ /dev/null @@ -1,14 +0,0 @@ -# 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. - -board: native_posix -supported-zephyr-versions: - - v2.7 -supported-toolchains: - - llvm - - host -output-type: elf -is-test: true -dts-overlays: - - overlay.dts diff --git a/zephyr/test/i2c_dts/BUILD.py b/zephyr/test/i2c_dts/BUILD.py new file mode 100644 index 0000000000..ec93d8b6f7 --- /dev/null +++ b/zephyr/test/i2c_dts/BUILD.py @@ -0,0 +1,5 @@ +# Copyright 2021 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. + +register_host_test("i2c_dts", dts_overlays=["overlay.dts"]) diff --git a/zephyr/test/i2c_dts/zmake.yaml b/zephyr/test/i2c_dts/zmake.yaml deleted file mode 100644 index 2430527011..0000000000 --- a/zephyr/test/i2c_dts/zmake.yaml +++ /dev/null @@ -1,14 +0,0 @@ -# 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. - -board: native_posix -supported-zephyr-versions: - - v2.7 -output-type: elf -supported-toolchains: - - llvm - - host -is-test: true -dts-overlays: - - overlay.dts diff --git a/zephyr/test/system/BUILD.py b/zephyr/test/system/BUILD.py new file mode 100644 index 0000000000..1aecdeb37d --- /dev/null +++ b/zephyr/test/system/BUILD.py @@ -0,0 +1,5 @@ +# Copyright 2021 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. + +register_host_test("system", dts_overlays=["overlay.dts"]) diff --git a/zephyr/test/system/zmake.yaml b/zephyr/test/system/zmake.yaml deleted file mode 100644 index 2430527011..0000000000 --- a/zephyr/test/system/zmake.yaml +++ /dev/null @@ -1,14 +0,0 @@ -# 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. - -board: native_posix -supported-zephyr-versions: - - v2.7 -output-type: elf -supported-toolchains: - - llvm - - host -is-test: true -dts-overlays: - - overlay.dts diff --git a/zephyr/test/tasks/BUILD.py b/zephyr/test/tasks/BUILD.py new file mode 100644 index 0000000000..1f49d4b41d --- /dev/null +++ b/zephyr/test/tasks/BUILD.py @@ -0,0 +1,5 @@ +# Copyright 2021 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. + +register_host_test("tasks") diff --git a/zephyr/test/tasks/zmake.yaml b/zephyr/test/tasks/zmake.yaml deleted file mode 100644 index fa16329e9c..0000000000 --- a/zephyr/test/tasks/zmake.yaml +++ /dev/null @@ -1,12 +0,0 @@ -# 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. - -board: native_posix -supported-zephyr-versions: - - v2.7 -supported-toolchains: - - llvm - - host -output-type: elf -is-test: true diff --git a/zephyr/zmake/setup.py b/zephyr/zmake/setup.py index 4328dc48d7..51001c6695 100644 --- a/zephyr/zmake/setup.py +++ b/zephyr/zmake/setup.py @@ -24,8 +24,8 @@ setuptools.setup( # requirements files see: # https://packaging.python.org/en/latest/requirements.html install_requires=[ - "jsonschema>=3.2.0", - "pyyaml>=3.13", + # Required until chroot upgrades to Python 3.7+. + "dataclasses>=0.6; python_version < '3.7'", ], # To provide executable scripts, use entry points in preference to the # "scripts" keyword. Entry points provide cross-platform support and allow diff --git a/zephyr/zmake/tests/test_project.py b/zephyr/zmake/tests/test_project.py index 2442ceedf6..461e04459c 100644 --- a/zephyr/zmake/tests/test_project.py +++ b/zephyr/zmake/tests/test_project.py @@ -11,28 +11,13 @@ import hypothesis.strategies as st import pytest import zmake.modules +import zmake.output_packers import zmake.project board_names = st.text(alphabet=set(string.ascii_lowercase) | {"_"}, min_size=1) sets_of_board_names = st.lists(st.lists(board_names, unique=True)) -class TemporaryProject(tempfile.TemporaryDirectory): - """A temporary project wrapper. - - Args: - config: The config dictionary to be used with the project. - """ - - def __init__(self, config): - self.config = config - super().__init__() - - def __enter__(self): - project_path = pathlib.Path(super().__enter__()) - return zmake.project.Project(project_path, config_dict=self.config) - - @hypothesis.given(sets_of_board_names) @hypothesis.settings(deadline=None) def test_find_dts_overlays(modules): @@ -67,21 +52,22 @@ def test_find_dts_overlays(modules): board_file_mapping[board] = files | {file_name} for board, expected_dts_files in board_file_mapping.items(): - with TemporaryProject( - { - "board": board, - "output-type": "elf", - "supported-toolchains": ["llvm"], - "supported-zephyr-versions": ["v2.6"], - } - ) as project: - config = project.find_dts_overlays(dict(enumerate(module_paths))) - - actual_dts_files = set( - config.cmake_defs.get("DTC_OVERLAY_FILE", "").split(";") + project = zmake.project.Project( + zmake.project.ProjectConfig( + name=board, + zephyr_board=board, + output_packer=zmake.output_packers.ElfPacker, + supported_toolchains=["llvm"], + supported_zephyr_versions=["v2.7"], + project_dir=pathlib.Path("/fakebuild"), ) + ) + config = project.find_dts_overlays(dict(enumerate(module_paths))) + actual_dts_files = set( + config.cmake_defs.get("DTC_OVERLAY_FILE", "").split(";") + ) - assert actual_dts_files == set(map(str, expected_dts_files)) + assert actual_dts_files == set(map(str, expected_dts_files)) setup_modules_and_dispatch(modules, testcase) @@ -101,16 +87,18 @@ def test_prune_modules(modules): for name in zmake.modules.known_modules } - with TemporaryProject( - { - "board": "native_posix", - "output-type": "elf", - "supported-toolchains": ["coreboot-sdk"], - "supported-zephyr-versions": ["v2.6"], - "modules": modules, - } - ) as project: - assert set(project.prune_modules(module_paths)) == set(modules) + project = zmake.project.Project( + zmake.project.ProjectConfig( + name="prunetest", + zephyr_board="native_posix", + output_packer=zmake.output_packers.ElfPacker, + supported_toolchains=["coreboot-sdk"], + supported_zephyr_versions=["v2.7"], + project_dir=pathlib.Path("/fake"), + modules=modules, + ), + ) + assert set(project.prune_modules(module_paths)) == set(modules) def test_prune_modules_unavailable(): @@ -122,17 +110,19 @@ def test_prune_modules_unavailable(): "hal_stm32": pathlib.Path("/mod/halstm"), } - with TemporaryProject( - { - "board": "native_posix", - "output-type": "elf", - "supported-toolchains": ["coreboot-sdk"], - "supported-zephyr-versions": ["v2.6"], - "modules": ["hal_stm32", "cmsis"], - } - ) as project: - with pytest.raises(KeyError): - project.prune_modules(module_paths) + project = zmake.project.Project( + zmake.project.ProjectConfig( + name="prunetest", + zephyr_board="native_posix", + output_packer=zmake.output_packers.ElfPacker, + supported_toolchains=["coreboot-sdk"], + supported_zephyr_versions=["v2.7"], + project_dir=pathlib.Path("/fake"), + modules=["hal_stm32", "cmsis"], + ), + ) + with pytest.raises(KeyError): + project.prune_modules(module_paths) def test_find_projects_empty(tmp_path): @@ -141,33 +131,65 @@ def test_find_projects_empty(tmp_path): assert len(projects) == 0 -YAML_FILE = """ -supported-zephyr-versions: - - v2.6 -supported-toolchains: - - coreboot-sdk -output-type: npcx +CONFIG_FILE_1 = """ +register_raw_project("one", zephyr_board="one") +register_host_test("two") +register_npcx_project("three", zephyr_board="three") +register_binman_project("four", zephyr_board="four") +""" + +CONFIG_FILE_2 = """ +register_raw_project( + "five", + zephyr_board="foo", + dts_overlays=[here / "gpio.dts"], +) """ def test_find_projects(tmp_path): """Test the find_projects method when there are projects.""" - dir = tmp_path.joinpath("one") - dir.mkdir() - dir.joinpath("zmake.yaml").write_text("board: one\n" + YAML_FILE) - tmp_path.joinpath("two").mkdir() - dir = tmp_path.joinpath("two/a") - dir.mkdir() - dir.joinpath("zmake.yaml").write_text("board: twoa\nis-test: true\n" + YAML_FILE) - dir = tmp_path.joinpath("two/b") - dir.mkdir() - dir.joinpath("zmake.yaml").write_text("board: twob\n" + YAML_FILE) - projects = list(zmake.project.find_projects(tmp_path)) - projects.sort(key=lambda x: x.project_dir) - assert len(projects) == 3 - assert projects[0].project_dir == tmp_path.joinpath("one") - assert projects[1].project_dir == tmp_path.joinpath("two/a") - assert projects[2].project_dir == tmp_path.joinpath("two/b") - assert not projects[0].config.is_test - assert projects[1].config.is_test - assert not projects[2].config.is_test + cf1_dir = tmp_path / "cf1" + cf1_dir.mkdir() + (cf1_dir / "BUILD.py").write_text(CONFIG_FILE_1) + + cf2_bb_dir = tmp_path / "cf2_bb" + cf2_bb_dir.mkdir() + cf2_dir = cf2_bb_dir / "cf2" + cf2_dir.mkdir() + (cf2_dir / "BUILD.py").write_text(CONFIG_FILE_2) + + projects = zmake.project.find_projects(tmp_path) + assert len(projects) == 5 + assert projects["one"].config.project_dir == cf1_dir + assert not projects["one"].config.is_test + + assert projects["two"].config.project_dir == cf1_dir + assert projects["two"].config.zephyr_board == "native_posix" + assert projects["two"].config.is_test + + assert projects["three"].config.project_dir == cf1_dir + assert not projects["three"].config.is_test + assert projects["three"].config.zephyr_board == "three" + + assert projects["four"].config.project_dir == cf1_dir + assert not projects["four"].config.is_test + assert projects["four"].config.zephyr_board == "four" + + assert projects["five"].config.project_dir == cf2_dir + assert not projects["five"].config.is_test + assert projects["five"].config.zephyr_board == "foo" + + +def test_find_projects_name_conflict(tmp_path): + """When two projects define the same name, that should be an error.""" + cf1_dir = tmp_path / "cf1" + cf1_dir.mkdir() + (cf1_dir / "BUILD.py").write_text(CONFIG_FILE_2) + + cf2_dir = tmp_path / "cf2" + cf2_dir.mkdir() + (cf2_dir / "BUILD.py").write_text(CONFIG_FILE_2) + + with pytest.raises(KeyError): + zmake.project.find_projects(tmp_path) diff --git a/zephyr/zmake/tests/test_toolchains.py b/zephyr/zmake/tests/test_toolchains.py index 515f54a112..85e8484880 100644 --- a/zephyr/zmake/tests/test_toolchains.py +++ b/zephyr/zmake/tests/test_toolchains.py @@ -7,6 +7,7 @@ import pathlib import pytest +import zmake.output_packers import zmake.project as project import zmake.toolchains as toolchains @@ -62,18 +63,19 @@ def zephyr_exists(mockfs): @pytest.fixture def fake_project(tmp_path): return project.Project( - tmp_path, - config_dict={ - "board": "foo", - "supported-zephyr-versions": ["v2.6"], - "supported-toolchains": [ + project.ProjectConfig( + name="foo", + zephyr_board="foo", + supported_zephyr_versions=["v2.6"], + supported_toolchains=[ "coreboot-sdk", "host", "llvm", "zephyr", ], - "output-type": "raw", - }, + output_packer=zmake.output_packers.RawBinPacker, + project_dir=tmp_path, + ), ) diff --git a/zephyr/zmake/tests/test_util.py b/zephyr/zmake/tests/test_util.py index 0c4cd4dda5..438c5efcf0 100644 --- a/zephyr/zmake/tests/test_util.py +++ b/zephyr/zmake/tests/test_util.py @@ -3,7 +3,6 @@ # found in the LICENSE file. import pathlib -import re import tempfile import hypothesis @@ -13,57 +12,6 @@ import pytest import zmake.util as util # Strategies for use with hypothesis -relative_path = st.from_regex( - regex=re.compile(r"\A\w{1,255}(/\w{1,255}){0,15}\Z", re.ASCII) -) - - -@hypothesis.given(relative_path, relative_path, relative_path) -@hypothesis.settings(deadline=60000) -def test_resolve_build_dir_with_build_dir( - platform_ec_subdir, project_subdir, build_subdir -): - with tempfile.TemporaryDirectory() as temp_dir_name: - platform_ec_dir = pathlib.Path(temp_dir_name) / platform_ec_subdir - build_dir = util.resolve_build_dir( - platform_ec_dir=platform_ec_dir, - project_dir=platform_ec_dir / project_subdir, - build_dir=platform_ec_dir / build_subdir, - ) - - assert build_dir == platform_ec_dir / build_subdir - - -@hypothesis.given(relative_path, relative_path) -@hypothesis.settings(deadline=60000) -def test_resolve_build_dir_invalid_project(platform_ec_subdir, project_subdir): - try: - with tempfile.TemporaryDirectory() as temp_dir_name: - platform_ec_dir = pathlib.Path(temp_dir_name) / platform_ec_subdir - util.resolve_build_dir( - platform_ec_dir=platform_ec_dir, - project_dir=platform_ec_dir / project_subdir, - build_dir=None, - ) - pytest.fail() - except Exception: - pass - - -@hypothesis.given(relative_path, relative_path) -@hypothesis.settings(deadline=60000) -def test_resolve_build_dir_from_project(platform_ec_subdir, project_subdir): - with tempfile.TemporaryDirectory() as temp_dir_name: - platform_ec_dir = pathlib.Path(temp_dir_name) / platform_ec_subdir - project_dir = platform_ec_dir / project_subdir - project_dir.mkdir(parents=True) - (project_dir / "zmake.yaml").touch() - build_dir = util.resolve_build_dir( - platform_ec_dir=platform_ec_dir, project_dir=project_dir, build_dir=None - ) - assert build_dir == platform_ec_dir / "build" / project_subdir - - version_integers = st.integers(min_value=0) version_tuples = st.tuples(version_integers, version_integers, version_integers) diff --git a/zephyr/zmake/tests/test_version.py b/zephyr/zmake/tests/test_version.py index a238a8ac02..9ca5b1e78a 100644 --- a/zephyr/zmake/tests/test_version.py +++ b/zephyr/zmake/tests/test_version.py @@ -8,6 +8,7 @@ import unittest.mock as mock import pytest +import zmake.output_packers import zmake.project import zmake.version as version @@ -51,13 +52,14 @@ def _setup_example_repos(tmp_path): project_path.mkdir() project = zmake.project.Project( - project_path, - config_dict={ - "board": "foo", - "output-type": "raw", - "supported-toolchains": ["coreboot-sdk"], - "supported-zephyr-versions": ["v2.6"], - }, + zmake.project.ProjectConfig( + name="prj", + zephyr_board="foo", + output_packer=zmake.output_packers.RawBinPacker, + supported_toolchains=["coreboot-sdk"], + supported_zephyr_versions=["v2.6"], + project_dir=project_path, + ), ) # Has one commit. zephyr_base = tmp_path / "zephyr_base" diff --git a/zephyr/zmake/tests/test_zmake.py b/zephyr/zmake/tests/test_zmake.py index 163159b9c5..3816d92626 100644 --- a/zephyr/zmake/tests/test_zmake.py +++ b/zephyr/zmake/tests/test_zmake.py @@ -18,6 +18,7 @@ from testfixtures import LogCapture import zmake.build_config import zmake.jobserver import zmake.multiproc as multiproc +import zmake.output_packers import zmake.project import zmake.toolchains import zmake.zmake as zm @@ -33,10 +34,15 @@ class FakeProject: def __init__(self): self.packer = mock.Mock() self.packer.pack_firmware = mock.Mock(return_value=[]) - self.project_dir = pathlib.Path("FakeProjectDir") - self.config = mock.Mock() - self.config.supported_zephyr_versions = [(2, 5)] + self.config = zmake.project.ProjectConfig( + name="fakeproject", + zephyr_board="fakeboard", + supported_toolchains=["llvm"], + supported_zephyr_versions=["v2.5"], + output_packer=zmake.output_packers.ElfPacker, + project_dir=pathlib.Path("FakeProjectDir"), + ) @staticmethod def iter_builds(): @@ -142,13 +148,16 @@ VERSION_TWEAK = 0 EXTRAVERSION = """ ) + (pathlib.Path(tmpname) / "project_name.txt").write_text("fakeproject") zephyr_base.resolve = mock.Mock(return_value=pathlib.Path(tmpname)) with patch("zmake.version.get_version_string", return_value="123"): - with patch.object(zmake.project, "Project", return_value=FakeProject()): + with patch.object( + zmake.project, + "find_projects", + return_value={"fakeproject": FakeProject()}, + ): if use_configure: - zmk.configure( - pathlib.Path(tmpname), build_dir=pathlib.Path("build") - ) + zmk.configure("fakeproject", build_dir=pathlib.Path("build")) else: with patch("zmake.version.write_version_header", autospec=True): zmk.build(pathlib.Path(tmpname)) diff --git a/zephyr/zmake/zmake/__main__.py b/zephyr/zmake/zmake/__main__.py index ea639584cc..ad4a7d96f0 100644 --- a/zephyr/zmake/zmake/__main__.py +++ b/zephyr/zmake/zmake/__main__.py @@ -200,7 +200,8 @@ def main(argv=None): help="Test the .elf file after configuration", ) configure.add_argument( - "project_dir", type=pathlib.Path, help="Path to the project to build" + "project_name_or_dir", + help="Path to the project to build", ) configure.add_argument( "-c", diff --git a/zephyr/zmake/zmake/configlib.py b/zephyr/zmake/zmake/configlib.py new file mode 100644 index 0000000000..dca9a4eedf --- /dev/null +++ b/zephyr/zmake/zmake/configlib.py @@ -0,0 +1,40 @@ +# Copyright 2021 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. + +"""This module defines helpers accessible to all BUILD.py files.""" + +import zmake.output_packers + + +def _register_project(name, **kwargs): + kwargs.setdefault("project_dir", here) # noqa: F821 + register_project(name, **kwargs) # noqa: F821 + + +def register_host_project(name, **kwargs): + kwargs.setdefault("zephyr_board", "native_posix") + kwargs.setdefault("supported_toolchains", ["llvm", "host"]) + kwargs.setdefault("output_packer", zmake.output_packers.ElfPacker) + _register_project(name, **kwargs) + + +def register_host_test(name, **kwargs): + kwargs.setdefault("is_test", True) + register_host_project(name, **kwargs) + + +def register_raw_project(name, **kwargs): + kwargs.setdefault("supported_toolchains", ["coreboot-sdk", "zephyr"]) + kwargs.setdefault("output_packer", zmake.output_packers.RawBinPacker) + _register_project(name, **kwargs) + + +def register_binman_project(name, **kwargs): + kwargs.setdefault("output_packer", zmake.output_packers.BinmanPacker) + register_raw_project(name, **kwargs) + + +def register_npcx_project(name, **kwargs): + kwargs.setdefault("output_packer", zmake.output_packers.NpcxPacker) + register_binman_project(name, **kwargs) diff --git a/zephyr/zmake/zmake/project.py b/zephyr/zmake/zmake/project.py index 7ffe4ebc19..62a3b7dd00 100644 --- a/zephyr/zmake/zmake/project.py +++ b/zephyr/zmake/zmake/project.py @@ -3,24 +3,14 @@ # found in the LICENSE file. """Module for project config wrapper object.""" +import dataclasses import logging import pathlib -import warnings - -import yaml import zmake.build_config as build_config +import zmake.configlib as configlib import zmake.modules as modules -import zmake.output_packers as packers import zmake.toolchains as toolchains -import zmake.util as util - -# The version of jsonschema in the chroot has a bunch of -# DeprecationWarnings that fire when we import it. Suppress these -# during the import to keep the noise down. -with warnings.catch_warnings(): - warnings.simplefilter("ignore") - import jsonschema def module_dts_overlay_name(modpath, board_name): @@ -36,121 +26,87 @@ def module_dts_overlay_name(modpath, board_name): return modpath / "zephyr" / "dts" / "board-overlays" / "{}.dts".format(board_name) -def find_projects(root_dir): - """Finds all zmake projects in root_dir. +def load_config_file(path): + """Load a BUILD.py config file and create associated projects. Args: - root_dir: the root dir as a pathlib.Path object + path: A pathlib.Path to the BUILD.py file. - Yields: - Project: The next project found. + Returns: + A list of Project objects specified by the file. """ - logging.info("Finding zmake targets under '%s'.", root_dir) - for path in pathlib.Path(root_dir).rglob("zmake.yaml"): - yield Project(path.parent) + projects = [] + def register_project(name, **kwargs): + projects.append(Project(ProjectConfig(name=name, **kwargs))) -class ProjectConfig: - """An object wrapping zmake.yaml.""" - - validator = jsonschema.Draft7Validator - schema = { - "type": "object", - "required": [ - "board", - "output-type", - "supported-toolchains", - "supported-zephyr-versions", - ], - "properties": { - "supported-zephyr-versions": { - "type": "array", - "items": { - "type": "string", - "enum": ["v2.6", "v2.7", "v2.8"], - }, - "minItems": 1, - "uniqueItems": True, - }, - "board": { - "type": "string", - }, - "modules": { - "type": "array", - "items": { - "type": "string", - "enum": list(modules.known_modules), - }, - }, - "output-type": { - "type": "string", - "enum": list(packers.packer_registry), - }, - "supported-toolchains": { - "type": "array", - "items": { - "type": "string", - "enum": list(toolchains.support_classes), - }, - }, - "is-test": { - "type": "boolean", - }, - "dts-overlays": { - "type": "array", - "items": { - "type": "string", - }, - }, - }, + # The Python environment passed to the config file. + config_globals = { + "register_project": register_project, + "here": path.parent.resolve(), } - def __init__(self, config_dict): - self.validator.check_schema(self.schema) - jsonschema.validate(config_dict, self.schema, cls=self.validator) - self.config_dict = config_dict + # First, load the global helper functions. + code = compile( + pathlib.Path(configlib.__file__).read_bytes(), + configlib.__file__, + "exec", + ) + exec(code, config_globals) - @property - def supported_zephyr_versions(self): - return [ - util.parse_zephyr_version(x) - for x in self.config_dict["supported-zephyr-versions"] - ] + # Next, load the BUILD.py + logging.info("Loading config file %s", path) + code = compile(path.read_bytes(), str(path), "exec") + exec(code, config_globals) + logging.info("Config file %s defines %s projects", path, len(projects)) + return projects - @property - def board(self): - return self.config_dict["board"] - @property - def modules(self): - return self.config_dict.get("modules", list(modules.known_modules)) +def find_projects(root_dir): + """Finds all zmake projects in root_dir. - @property - def output_packer(self): - return packers.packer_registry[self.config_dict["output-type"]] + Args: + root_dir: the root dir as a pathlib.Path object - @property - def supported_toolchains(self): - return self.config_dict["supported-toolchains"] + Returns: + A dictionary mapping project names to Project objects. + """ + logging.info("Finding zmake targets under '%s'.", root_dir) + found_projects = {} + for path in pathlib.Path(root_dir).rglob("BUILD.py"): + for project in load_config_file(path): + if project.config.name in found_projects: + raise KeyError( + "Duplicate project defined: {} (in {})".format( + project.config.name, path + ) + ) + found_projects[project.config.name] = project + return found_projects - @property - def is_test(self): - return self.config_dict.get("is-test", False) - @property - def dts_overlays(self): - return self.config_dict.get("dts-overlays", []) +@dataclasses.dataclass +class ProjectConfig: + name: str + zephyr_board: str + supported_toolchains: "list[str]" + output_packer: type + supported_zephyr_versions: "list[str]" = dataclasses.field( + default_factory=lambda: ["v2.7"], + ) + modules: "list[str]" = dataclasses.field( + default_factory=lambda: modules.known_modules, + ) + is_test: bool = dataclasses.field(default=False) + dts_overlays: "list[str]" = dataclasses.field(default_factory=list) + project_dir: pathlib.Path = dataclasses.field(default_factory=pathlib.Path) class Project: """An object encapsulating a project directory.""" - def __init__(self, project_dir, config_dict=None): - self.project_dir = project_dir.resolve() - if not config_dict: - with open(self.project_dir / "zmake.yaml") as f: - config_dict = yaml.safe_load(f) - self.config = ProjectConfig(config_dict) + def __init__(self, config): + self.config = config self.packer = self.config.output_packer(self) def iter_builds(self): @@ -159,8 +115,8 @@ class Project: Yields: 2-tuples of a build configuration name and a BuildConfig. """ - conf = build_config.BuildConfig(cmake_defs={"BOARD": self.config.board}) - prj_conf = self.project_dir / "prj.conf" + conf = build_config.BuildConfig(cmake_defs={"BOARD": self.config.zephyr_board}) + prj_conf = self.config.project_dir / "prj.conf" if prj_conf.is_file(): conf |= build_config.BuildConfig(kconfig_files=[prj_conf]) for build_name, packer_config in self.packer.configs(): @@ -178,11 +134,11 @@ class Project: """ overlays = [] for module_path in modules.values(): - dts_path = module_dts_overlay_name(module_path, self.config.board) + dts_path = module_dts_overlay_name(module_path, self.config.zephyr_board) if dts_path.is_file(): overlays.append(dts_path.resolve()) - overlays.extend(self.project_dir / f for f in self.config.dts_overlays) + overlays.extend(self.config.dts_overlays) if overlays: return build_config.BuildConfig( @@ -218,7 +174,7 @@ class Project: except KeyError as e: raise KeyError( "The {!r} module is required by the {} project, but is not " - "available.".format(module, self.project_dir) + "available.".format(module, self.config.project_dir) ) from e return result diff --git a/zephyr/zmake/zmake/toolchains.py b/zephyr/zmake/zmake/toolchains.py index 6e25301b7d..88b7c16e46 100644 --- a/zephyr/zmake/zmake/toolchains.py +++ b/zephyr/zmake/zmake/toolchains.py @@ -26,7 +26,7 @@ class GenericToolchain: # know if it's installed. Simply return False to indicate not # installed. An unknown toolchain would only be used if -t # was manually passed to zmake, and is not valid to put in a - # zmake.yaml file. + # BUILD.py file. return False def get_build_config(self): diff --git a/zephyr/zmake/zmake/util.py b/zephyr/zmake/zmake/util.py index 0908993267..ca75f1b55e 100644 --- a/zephyr/zmake/zmake/util.py +++ b/zephyr/zmake/zmake/util.py @@ -213,36 +213,3 @@ def log_multi_line(logger, level, message): for line in message.splitlines(): if line: logger.log(level, line) - - -def resolve_build_dir(platform_ec_dir, project_dir, build_dir): - """Resolve the build directory using platform/ec/build/... as default. - - Args: - platform_ec_dir: The path to the chromiumos source's platform/ec - directory. - project_dir: The directory of the project. - build_dir: The directory to build in (may be None). - Returns: - The resolved build directory (using build_dir if not None). - """ - if build_dir: - return build_dir - - if not pathlib.Path.exists(project_dir / "zmake.yaml"): - raise OSError("Invalid configuration") - - # Resolve project_dir to absolute path. - project_dir = project_dir.resolve() - - # Compute the path of project_dir relative to platform_ec_dir. - project_relative_path = pathlib.Path.relative_to(project_dir, platform_ec_dir) - - # Make sure that the project_dir is a subdirectory of platform_ec_dir. - if platform_ec_dir / project_relative_path != project_dir: - raise OSError( - "Can't resolve project directory {} which is not a subdirectory" - " of the platform/ec directory {}".format(project_dir, platform_ec_dir) - ) - - return platform_ec_dir / "build" / project_relative_path diff --git a/zephyr/zmake/zmake/version.py b/zephyr/zmake/zmake/version.py index 47aba6d804..178909c088 100644 --- a/zephyr/zmake/zmake/version.py +++ b/zephyr/zmake/zmake/version.py @@ -90,7 +90,6 @@ def get_version_string(project, zephyr_base, modules, static=False): the build for the OS. """ major_version, minor_version, *_ = util.read_zephyr_version(zephyr_base) - project_id = project.project_dir.parts[-1] num_commits = 0 if static: @@ -116,7 +115,7 @@ def get_version_string(project, zephyr_base, modules, static=False): ) return "{}_v{}.{}.{}-{}".format( - project_id, major_version, minor_version, num_commits, vcs_hashes + project.config.name, major_version, minor_version, num_commits, vcs_hashes ) diff --git a/zephyr/zmake/zmake/zmake.py b/zephyr/zmake/zmake/zmake.py index 0fa30640c9..5d24e32ecb 100644 --- a/zephyr/zmake/zmake/zmake.py +++ b/zephyr/zmake/zmake/zmake.py @@ -206,7 +206,7 @@ class Zmake: def configure( self, - project_dir, + project_name_or_dir, build_dir=None, toolchain=None, ignore_unsupported_zephyr_version=False, @@ -215,10 +215,47 @@ class Zmake: bringup=False, coverage=False, ): - """Set up a build directory to later be built by "zmake build".""" - project = zmake.project.Project(project_dir) - supported_versions = project.config.supported_zephyr_versions + """Locate a project by name or directory and then call _configure.""" + root_dir = pathlib.Path(project_name_or_dir) + if not root_dir.is_dir(): + root_dir = self.module_paths["ec"] / "zephyr" + found_projects = zmake.project.find_projects(root_dir) + if len(found_projects) == 1: + # Likely passed directory path, wants to build only + # project from there. + project = next(iter(found_projects.values())) + else: + try: + project = found_projects[project_name_or_dir] + except KeyError as e: + raise KeyError("No project named {}".format(project_name_or_dir)) from e + return self._configure( + project=project, + build_dir=build_dir, + toolchain=toolchain, + ignore_unsupported_zephyr_version=ignore_unsupported_zephyr_version, + build_after_configure=build_after_configure, + test_after_configure=test_after_configure, + bringup=bringup, + coverage=coverage, + ) + def _configure( + self, + project, + build_dir=None, + toolchain=None, + ignore_unsupported_zephyr_version=False, + build_after_configure=False, + test_after_configure=False, + bringup=False, + coverage=False, + ): + """Set up a build directory to later be built by "zmake build".""" + supported_versions = [ + util.parse_zephyr_version(v) + for v in project.config.supported_zephyr_versions + ] zephyr_base = self.locate_zephyr_base(max(supported_versions)).resolve() # Ignore the patchset from the Zephyr version. @@ -230,17 +267,16 @@ class Zmake: ): raise ValueError( "The Zephyr OS version (v{}.{}) is not supported by the " - "project. You may wish to either configure zmake.yaml to " + "project. You may wish to either configure BUILD.py to " "support this version, or pass " "--ignore-unsupported-zephyr-version.".format(*zephyr_version) ) # Resolve build_dir if needed. - build_dir = util.resolve_build_dir( - platform_ec_dir=self.module_paths["ec"], - project_dir=project_dir, - build_dir=build_dir, - ) + if not build_dir: + build_dir = ( + self.module_paths["ec"] / "build" / "zephyr" / project.config.name + ) # Make sure the build directory is clean. if os.path.exists(build_dir): self.logger.info("Clearing old build directory %s", build_dir) @@ -288,9 +324,9 @@ class Zmake: if not generated_include_dir.exists(): generated_include_dir.mkdir() processes = [] - self.logger.info("Building %s in %s.", project_dir, build_dir) + self.logger.info("Building %s in %s.", project.config.name, build_dir) for build_name, build_config in project.iter_builds(): - self.logger.info("Configuring %s:%s.", project_dir, build_name) + self.logger.info("Configuring %s:%s.", project.config.name, build_name) config = ( base_config | toolchain_config @@ -302,7 +338,7 @@ class Zmake: kconfig_file = build_dir / "kconfig-{}.conf".format(build_name) proc = config.popen_cmake( self.jobserver, - project_dir, + project.config.project_dir, output_dir, kconfig_file, stdin=subprocess.DEVNULL, @@ -311,7 +347,7 @@ class Zmake: encoding="utf-8", errors="replace", ) - job_id = "{}:{}".format(project_dir, build_name) + job_id = "{}:{}".format(project.config.name, build_name) zmake.multiproc.log_output( self.logger, logging.DEBUG, @@ -335,8 +371,10 @@ class Zmake: if proc.wait(): raise OSError(get_process_failure_msg(proc)) - # Create symlink to project - util.update_symlink(project_dir, build_dir / "project") + # To reconstruct a Project object later, we need to know the + # name and project directory. + (build_dir / "project_name.txt").write_text(project.config.name) + util.update_symlink(project.config.project_dir, build_dir / "project") if test_after_configure: rv = self.test(build_dir=build_dir) @@ -393,7 +431,8 @@ class Zmake: dirs = {} build_dir = build_dir.resolve() - project = zmake.project.Project(build_dir / "project") + found_projects = zmake.project.find_projects(build_dir / "project") + project = found_projects[(build_dir / "project_name.txt").read_text()] # Compute the version string. version_string = zmake.version.get_version_string( @@ -477,7 +516,8 @@ class Zmake: self.build(build_dir, output_files_out=output_files) # If the project built but isn't a test, just bail. - project = zmake.project.Project(build_dir / "project") + found_projects = zmake.project.find_projects(build_dir / "project") + project = found_projects[(build_dir / "project_name.txt").read_text()] if not project.config.is_test: return 0 @@ -514,17 +554,19 @@ class Zmake: def testall(self): """Test all the valid test targets""" tmp_dirs = [] - for project in zmake.project.find_projects(self.module_paths["ec"] / "zephyr"): + for project in zmake.project.find_projects( + self.module_paths["ec"] / "zephyr" + ).values(): is_test = project.config.is_test temp_build_dir = tempfile.mkdtemp( - suffix="-{}".format(os.path.basename(project.project_dir.as_posix())), + suffix="-{}".format(project.config.name), prefix="zbuild-", ) tmp_dirs.append(temp_build_dir) # Configure and run the test. self.executor.append( - func=lambda: self.configure( - project_dir=project.project_dir, + func=lambda: self._configure( + project=project, build_dir=pathlib.Path(temp_build_dir), build_after_configure=True, test_after_configure=is_test, @@ -601,9 +643,9 @@ class Zmake: return 0 def _coverage_compile_only(self, project, build_dir, lcov_file): - self.logger.info("Building %s in %s", project.project_dir, build_dir) - rv = self.configure( - project_dir=project.project_dir, + self.logger.info("Building %s in %s", project.config.name, build_dir) + rv = self._configure( + project=project, build_dir=build_dir, build_after_configure=False, test_after_configure=False, @@ -628,7 +670,8 @@ class Zmake: ) # Use ninja to compile the all.libraries target. - build_project = zmake.project.Project(build_dir / "project") + found_projects = zmake.project.find_projects(build_dir / "project") + build_project = found_projects[(build_dir / "project_name.txt").read_text()] procs = [] dirs = {} @@ -679,10 +722,10 @@ class Zmake: lcov_file, is_configured=False, ): - self.logger.info("Running test %s in %s", project.project_dir, build_dir) + self.logger.info("Running test %s in %s", project.config.name, build_dir) if not is_configured: - rv = self.configure( - project_dir=project.project_dir, + rv = self._configure( + project=project, build_dir=build_dir, build_after_configure=True, test_after_configure=True, @@ -699,9 +742,9 @@ class Zmake: """Builds all targets with coverage enabled, and then runs the tests.""" all_lcov_files = [] root_dir = self.module_paths["ec"] / "zephyr" - for project in zmake.project.find_projects(root_dir): + for project in zmake.project.find_projects(root_dir).values(): is_test = project.config.is_test - rel_path = project.project_dir.relative_to(root_dir) + rel_path = project.config.project_dir.relative_to(root_dir) project_build_dir = pathlib.Path(build_dir).joinpath(rel_path) lcov_file = pathlib.Path(build_dir).joinpath( str(rel_path).replace("/", "_") + ".info" |