blob: 1bac9ac541efdce0c208b96311df117829de929d [file] [log] [blame]
# Copyright 2020 The LUCI Authors. All rights reserved.
# Use of this source code is governed under the Apache License, Version 2.0
# that can be found in the LICENSE file.
"""Legacy Annotation module provides support for running a command emitting
legacy @@@annotation@@@ in the new luciexe mode.
The output annotations is converted to a build proto and all steps in the build
will appear as the child steps of the launched cmd/step in the current running
build (using the Merge Step feature from luciexe protocol). This is the
replacement for allow_subannotation feature in the legacy annotate mode.
"""
from future.utils import iteritems
from google.protobuf import json_format as jsonpb
from recipe_engine import recipe_api
from recipe_engine.engine_types import ResourceCost as _ResourceCost
from recipe_engine.util import Placeholder
from PB.go.chromium.org.luci.buildbucket.proto import build as build_pb2
class LegacyAnnotationApi(recipe_api.RecipeApiPlain):
concurrency_client = recipe_api.RequireClient('concurrency')
step_client = recipe_api.RequireClient('step')
def __call__(self, name, cmd,
timeout=None, step_test_data=None, cost=_ResourceCost()):
"""Runs cmd that is emitting legacy @@@annotation@@@.
Currently, it will run the command as sub_build if running in luciexe
mode or simulation mode. Otherwise, it will fall back to launch a step
with allow_subannotation set to true.
"""
# concurrency is enabled when running recipe in bbagent/luciexe mode.
run_kitchen_mode = not self.concurrency_client.supports_concurrency
if self._test_data.enabled:
run_kitchen_mode = self._test_data.get('simulate_kitchen', False)
if run_kitchen_mode:
# TODO(yiwzhang): Remove after bbagent is fully rolled out.
self.m.step._validate_cmd_list(cmd)
with self.m.context(env_prefixes={'PATH': self.m.step._prefix_path}):
env_prefixes = self.m.context.env_prefixes
return self.m.step._run_or_raise_step(self.step_client.StepConfig(
name=name,
cmd=cmd,
cost=self.m.step._normalize_cost(cost),
cwd=self.m.step._normalize_cwd(self.m.context.cwd),
env=self.m.context.env,
env_prefixes=self.m.step._to_env_affix(env_prefixes),
env_suffixes=self.m.step._to_env_affix(self.m.context.env_suffixes),
allow_subannotations=True,
timeout=timeout,
luci_context=self.m.context.luci_context,
infra_step=self.m.context.infra_step,
step_test_data=step_test_data,
))
run_annotations_luciexe = self.m.cipd.ensure_tool(
'infra/tools/run_annotations/${platform}', 'latest')
cmd = [run_annotations_luciexe, '--'] + cmd
if step_test_data:
_step_test_data = step_test_data
step_test_data = lambda: self.test_api.success_step + _step_test_data()
else: # pragma: no cover
step_test_data = lambda: self.test_api.success_step
ret = self.m.step.sub_build(name, cmd, build_pb2.Build(),
timeout=timeout,
step_test_data=step_test_data,
cost=cost)
ret.presentation.properties.update(
jsonpb.MessageToDict(ret.step.sub_build.output.properties))
return ret