cos_kernel: Use patch command instead of git am

When we build our kernel with portage, we apply patches with `eapply`.
This internally uses the `patch` command, which allows some context
fuzzing. This generally makes patches easier to maintain than if patches
were applied with `git am`, which doesn't fuzz by default and has less
safe fuzzing behavior if enabled.

In order to make this tool better match the behavior of our ebuilds, we
should use the patch tool instead of `git am`. This will result in all
of the patches being applied in one big commit. This makes the code a
bit more complex, but should reduce the toil of trying to make patches
match exactly without fuzzing.

Tested with the main-R121-cos-6.6 kernel by:

1. `cos-kernel build --patches=irdma` -> applied patches correctly and
   creates commit, leaving directory clean.
2. `cos-kernel build --patches=idpf` -> fails and cleans up directory
   (idpf patches depend on irdma).
3. Modify google/patches/idpf/0003 to corrupt it, then run
   `cos-kernel build --patches=irdma --patches=idpf` -> fails, leaves
   directory untouched, and outputs command which correctly cleans up
   directory when run.

BUG=b/527927014
TEST=presubmit, see above

Change-Id: Ib98050d97fcb4d08a4519040ed952d21a8d1e85a
Reviewed-on: https://cos-review.googlesource.com/c/cos/tools/+/185286
Tested-by: Kevin Berry <kpberry@google.com>
Reviewed-by: Derek Taylor <ddtaylor@google.com>
Cloud-Build: 228075978874@cloudbuild.gserviceaccount.com <228075978874@cloudbuild.gserviceaccount.com>
3 files changed
tree: e3c969870efca2cf51bdfb27ca7fc811882f92f4
  1. coverage/
  2. release/
  3. src/
  4. testing/
  5. vendor/
  6. .bazelignore
  7. .gitignore
  8. BUILD.bazel
  9. cloudbuild.yaml
  10. CONTRIBUTING.md
  11. deps.bzl
  12. go.mod
  13. go.sum
  14. LICENSE
  15. postsubmit-cloudbuild.yaml
  16. README.md
  17. run_builds.sh
  18. run_unit_tests.sh
  19. WORKSPACE
README.md

Tools for Container-Optimized OS

This is a repository of various tools developed for Container-Optimized OS. Examples include cos-gpu-installer, cos-toolbox, etc.

See CONTRIBUTING.md for how to contribute.