Build API: Add validation decorators.
Simplify the easy proto validation tasks by providing decorators
that can handle the simple validation cases.
BUG=None
TEST=run_tests
Change-Id: Ib799d43c7d0dca5312a58771ff67b610e9ff4f2c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/1669636
Reviewed-by: Alex Klein <saklein@chromium.org>
Tested-by: Alex Klein <saklein@chromium.org>
Commit-Queue: Alex Klein <saklein@chromium.org>
Auto-Submit: Alex Klein <saklein@chromium.org>
diff --git a/api/controller/sysroot.py b/api/controller/sysroot.py
index 2a43183..8276629 100644
--- a/api/controller/sysroot.py
+++ b/api/controller/sysroot.py
@@ -8,6 +8,7 @@
from __future__ import print_function
from chromite.api import controller
+from chromite.api import validate
from chromite.api.controller import controller_util
from chromite.lib import build_target_util
from chromite.lib import cros_build_lib
@@ -19,6 +20,7 @@
_ACCEPTED_LICENSES = '@CHROMEOS'
+@validate.require('build_target.name')
def Create(input_proto, output_proto):
"""Create or replace a sysroot."""
update_chroot = not input_proto.flags.chroot_current
@@ -27,9 +29,6 @@
build_target_name = input_proto.build_target.name
profile = input_proto.profile.name or None
- if not build_target_name:
- cros_build_lib.Die('The build target must be provided.')
-
build_target = build_target_util.BuildTarget(name=build_target_name,
profile=profile)
run_configs = sysroot.SetupBoardRunConfig(
@@ -45,17 +44,14 @@
output_proto.sysroot.build_target.name = build_target_name
+@validate.require('sysroot.path', 'sysroot.build_target.name')
def InstallToolchain(input_proto, output_proto):
+ """Install the toolchain into a sysroot."""
compile_source = input_proto.flags.compile_source
sysroot_path = input_proto.sysroot.path
build_target_name = input_proto.sysroot.build_target.name
- if not sysroot_path:
- cros_build_lib.Die('sysroot.path is required.')
- if not build_target_name:
- cros_build_lib.Die('sysroot.build_target.name is required.')
-
build_target = build_target_util.BuildTarget(name=build_target_name)
target_sysroot = sysroot_lib.Sysroot(sysroot_path)
run_configs = sysroot.SetupBoardRunConfig(usepkg=not compile_source,
@@ -77,7 +73,9 @@
return controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE
+@validate.require('sysroot.path', 'sysroot.build_target.name')
def InstallPackages(input_proto, output_proto):
+ """Install packages into a sysroot, building as necessary and permitted."""
compile_source = input_proto.flags.compile_source
event_file = input_proto.flags.event_file
@@ -85,11 +83,6 @@
build_target_name = input_proto.sysroot.build_target.name
packages = map(controller_util.PackageInfoToString, input_proto.packages)
- if not build_target_name:
- cros_build_lib.Die('Build target name is required.')
- if not sysroot_path:
- cros_build_lib.Die('Sysroot path is required')
-
build_target = build_target_util.BuildTarget(build_target_name)
target_sysroot = sysroot_lib.Sysroot(sysroot_path)