# 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 json import subprocess from pathlib import Path from typing import Optional from interface.errors import ToolError from .constants import ENVSETUP_PATH
# Validate that restricted keys are not in env_overrides
restricted_keys = {"TARGET_PRODUCT", "TARGET_RELEASE", "TARGET_BUILD_VARIANT"} if self.env_overrides:
found_restricted = restricted_keys.intersection(self.env_overrides.keys()) if found_restricted: raise ToolError(
f"The following environment variables are reserved and cannot be passed in env_vars: {', '.join(sorted(found_restricted))}. " "Please use the top-level arguments (product, release, variant) instead."
)
# The script is in api/, so the sdk root is one level up
sdk_root = Path(__file__).parent.parent
self.cache_dir = sdk_root / ".cache"
self.cache_file = self.cache_dir / f"env_{product}_{release}_{variant}.json"
# The repo root is 6 levels up from the script
self.repo_root = sdk_root.parent.parent.parent.parent.parent
def save(self, env: dict[str, str]) -> None: """Saves the environment to the cache file."""
self.cache_dir.mkdir(parents=True, exist_ok=True) with open(self.cache_file, "w") as f:
json.dump(env, f)
def get_env(self, force_refresh: bool = False) -> dict[str, str]: """
Gets the build environment for a given EnvSnapshot.
Args:
force_refresh: IfTrue, forces a refresh of the environment cache.
Returns:
A dictionary representing the environment. """
ifnot force_refresh and self.is_cache_fresh():
env = self.load() if env: return env
return self.refresh()
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.