# Copyright (C) 2026 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.
import subprocess import dataclasses from enum import Enum from pathlib import Path from .env import BuildContext from .config import get_build_vars from .constants import NINJA_BIN_PATH from interface.errors import ToolError
class NinjaTargetNotFoundError(ToolError): """Raised when a Ninja target is not found.""" pass
def query_ninja_target(ctx: BuildContext, target: str) -> NinjaQuery: """
Queries the Ninja graph for a specific target.
Use this to inspect dependencies (input) and outputs of a specific Ninja graph node (target).
Returns the explicit and implicit dependencies and output files.
Args:
target: The Ninja graph node (target) to query. This is usually a file path or a phony target name. """
cmd = _get_ninja_runner(ctx) + ["-t", "query", target]
def depends_on(ctx: BuildContext, source: str, target: str) -> tuple[bool, list[str]]: """
Checks if `target` (the consumer) depends on `source` (the input).
Use this to verify if one file or target depends on another within the build graph.
Returns a boolean (Trueif path exists) and the dependency chain if found.
Args:
source: The source Ninja target (potential dependency).
target: The destination Ninja target (potential dependent). """ # ninja -t path <output_target> <input_target> # target is the output/consumer. source is the input/dependency.
cmd = _get_ninja_runner(ctx) + ["-t", "path", target, source]
try:
process = subprocess.run(
cmd,
env=env,
cwd=android_build_top,
capture_output=True,
text=True,
check=True
) # If successful, a path exists
chain = [line.strip() for line in process.stdout.splitlines() if line.strip()] returnTrue, chain
except subprocess.CalledProcessError: # Ninja returns non-zero if no path found or target missing returnFalse, []
def get_command(ctx: BuildContext, target: str, last_n: int = 1) -> list[str]: """
Retrieves the build command(s) for a given target.
Use this to inspect the exact compiler flags, search paths, and tools used to generate an artifact.
Returns a list of the last 'last_n' commands in the sequence required to build the target.
Args:
target: The Ninja target whose build command should be retrieved.
last_n: The number of last commands to retrieve from the sequence (default: 1). """
cmd = _get_ninja_runner(ctx) + ["-t", "commands", target]
try:
process = subprocess.run(
cmd,
env=env,
cwd=android_build_top,
capture_output=True,
text=True,
check=True
)
lines = [line.strip() for line in process.stdout.splitlines() if line.strip()] return lines[-last_n:]
except subprocess.CalledProcessError as e: raise ToolError(f"Ninja commands query failed: {e.stderr.strip()}")
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet am 2026-06-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.