zephyr/scripts/west_commands
Chris Friedt ad611395ee scripts: west_commands: add the west patch command
In smaller projects and organizations, forking Zephyr is usually
a tenable solution for development continuity, in the case that
bug-fixes or enhancements need to be applied to Zephyr to
unblock development.

In larger organizations, perhaps in the absence of healthy patch
management, technical debt management, and open-source policies,
forking and in-tree changes can quickly get out of hand.

In other organizations, it may simply be preferable to have a
zero-forking / upstream-first policy.

Regardless of the reason, this change adds a `west patch`
command that enables users to manage patches locally in their
modules, under version control, with complete transparence.

The format of the YAML file (detailed in a previous comit)
includes fields for filename, checksum, author, email, dates,
along with pr and issue links. There are fields indicating
whether the patch is upstreamble or whether it has been merged
upstream already. There is a custom field that is not validated
and can be used for any purpose.

Workflows can be created to notify maintainers when a merged
patch may be discarded after a version or a commit bump.

In Zephyr modules, the file resides conventionally under
`zephyr/patches.yml`, and patch files reside under
`zephyr/patches/`.

Sample usage applying patches (the `-v` argument for additional
detail):
```shell
west -v patch apply
reading patch file zephyr/run-tests-with-rtt-console.patch
checking patch integrity... OK
patching zephyr... OK
reading patch file zephyr/twister-rtt-support.patch
checking patch integrity... OK
patching zephyr... OK
reading patch file zephyr/multiple_icntl.patch
checking patch integrity... OK
patching zephyr... OK
reading patch file zephyr/move-bss-to-end.patch
checking patch integrity... OK
patching zephyr... OK
4 patches applied successfully \o/
```

Cleaning previously applied patches
```shell
west patch clean
```

After manually corrupting a patch file (the `-r` option will
automatically roll-back all changes if one patch fails)
```shell
west -v patch apply -r
reading patch file zephyr/run-tests-with-rtt-console.patch
checking patch integrity... OK
patching zephyr... OK
reading patch file zephyr/twister-rtt-support.patch
checking patch integrity... OK
patching zephyr... OK
reading patch file zephyr/multiple_icntl.patch
checking patch integrity... OK
patching zephyr... OK
reading patch file zephyr/move-bss-to-end.patch
checking patch integrity... FAIL
ERROR: sha256 mismatch for zephyr/move-bss-to-end.patch:
expect: 00e42e5d89f68f8b07e355821cfcf492faa2f96b506bbe87a9b35a823fd719cb
actual: b9900e0c9472a0aaae975370b478bb26945c068497fa63ff409b21d677e5b89f
Cleaning zephyr
FATAL ERROR: failed to apply patch zephyr/move-bss-to-end.patch
```

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-12-24 11:15:38 +01:00
..
completion scripts: west: commands: completion: add twister --log-level completion 2024-09-24 14:27:03 -05:00
fetchers
runners west: runners: bossac: Honor --erase flag 2024-12-22 18:20:30 +00:00
sdk commands: add the 'sdk' command to manage SDK. 2024-08-21 16:54:56 -04:00
tests west: runners: bossac: Honor --erase flag 2024-12-22 18:20:30 +00:00
zspdx python: Format trivial files where only newlines were missing 2024-11-21 20:10:51 +01:00
bindesc.py scripts: west_commands: bindesc: Remove deprecated west.log 2024-11-18 13:18:42 -05:00
blobs.py scripts: west_commands: blobs: Remove deprecated west.log 2024-11-18 13:18:42 -05:00
boards.py python: Format and sort imports 2024-11-25 10:07:13 +01:00
build.py west build: fix a leftover "log" reference in build.py 2024-11-06 10:07:13 -08:00
build_helpers.py
completion.py scripts: west_commands: completion: Remove deprecated west.log 2024-11-18 13:18:42 -05:00
debug.py cmake: flash: update cmake to support rtt target 2024-11-21 11:01:55 +00:00
export.py scripts: west_commands: export: Remove deprecated west.log 2024-11-18 13:18:42 -05:00
flash.py scripts: west: flash: Fix issue with loading outdated domain file 2024-06-13 17:53:00 +02:00
mypy.ini
packages.py scripts: west_commands: Add packages command 2024-11-25 12:16:43 +01:00
patch.py scripts: west_commands: add the west patch command 2024-12-24 11:15:38 +01:00
README.txt
robot.py West: Add west robot command 2024-05-28 12:54:52 +02:00
run_common.py scripts: west_commands: run: Add priority to run once config 2024-10-26 17:14:06 +02:00
run_tests.py
sdk.py commands: add the 'sdk' command to manage SDK. 2024-08-21 16:54:56 -04:00
shields.py python: Format and sort imports 2024-11-25 10:07:13 +01:00
sign.py west: rimage: generate TOML with all LLEXTs included 2024-12-17 11:35:32 +00:00
simulate.py West: Add west simulate command 2024-05-28 12:54:52 +02:00
spdx.py scripts: Fix CMake spelling 2024-10-30 16:32:24 -05:00
twister_cmd.py scripts: west_commands: twister_cmd: Remove deprecated west.log 2024-11-18 13:18:42 -05:00
zcmake.py
zephyr_ext_common.py scripts: west_commands: zephyr_ext_common: Remove deprecated west.log 2024-11-18 13:18:42 -05:00

This directory contains implementations for west commands which are
tightly coupled to the zephyr tree. This includes the build, flash,
and debug commands.

Before adding more here, consider whether you might want to put new
extensions in upstream west. For example, any commands which operate
on the multi-repo need to be in upstream west, not here. Try to limit
what goes in here to Zephyr-specific features.

When extending this code, please keep the unit tests (in tests/) up to
date. The mypy static type checker is also run on the runners package.

To run these tests locally on Windows, run:

   py -3 run_tests.py

On macOS and Linux:

   ./run_tests.py

Note that these tests are run as part of Zephyr's CI when submitting
an upstream pull request, and pull requests which break the tests
cannot be merged.

Thanks!