blob: c9703a41c0008e09946da8261624f7c60e3ef752 [file] [log] [blame]
# Copyright 2022 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from recipe_engine import recipe_api
# [finished actions/remaining actions](running actions)
DEFAULT_NINJA_STATUS = "[%%f/%%t](%%r) "
class NinjaApi(recipe_api.RecipeApi):
"""APIs for interacting with Ninja.
NOTE: Recipes that use the Fuchsia build system should use the
`build` recipe module, which uses `fint` instead of running GN and
Ninja directly. Only recipes that build code outside of a Fuchsia
checkout should use this `ninja` module.
"""
def __call__(
self,
step_name,
ninja_args=(),
build_dir=None,
ninja_jobs=None,
ninja_status=DEFAULT_NINJA_STATUS,
**kwargs,
):
step_test_data = lambda: self.m.raw_io.test_api.output_text(
"[1/1](1) CXX a.o\nerror info\n"
)
cmd = [
self.path,
]
if build_dir:
cmd += ["-C", build_dir]
# TODO(atyfto): Consider creating separate helper functions for build,
# test, and install.
if ninja_jobs:
cmd += [f"-j{ninja_jobs}"]
cmd.extend(ninja_args)
with self.m.context(env={"NINJA_STATUS": ninja_status}):
return self.m.step(
step_name,
cmd,
step_test_data=step_test_data,
**kwargs,
)
@property
def path(self):
return self.m.cipd_ensure(
self.resource("cipd.ensure"),
"fuchsia/third_party/ninja/${platform}",
)