Source code for batools.pcommands4

# Released under the MIT License. See LICENSE for details.
#
"""A nice collection of ready-to-use pcommands for this package."""

from __future__ import annotations  # Docs-generation hack.

# Note: import as little as possible here at the module level to
# keep launch times fast for small snippets.
from efrotools import pcommand


[docs] def ios_sim_run() -> None: """Build an iOS/tvOS scheme for the simulator and run it there. Usage: ``tools/pcommand ios_sim_run <project> <scheme> <config> <ios|tvos>``. Honors the ``IOS_SIM_DEVICE`` (name/udid; default auto-picks the newest available) and ``IOS_LOG_SUBSYSTEM`` env vars. Powers ``make ios`` / ``make tvos`` -- the Simulator analogue of ``make mac``. """ from efro.error import CleanError from batools import iossim args = pcommand.get_args() if len(args) != 4: raise CleanError('Expected <project> <scheme> <config> <ios|tvos>.') iossim.run( project=args[0], scheme=args[1], configuration=args[2], platform=args[3], )
[docs] def ios_sim_log() -> None: """Stream engine os_log from the booted iOS/tvOS sim. Usage: ``tools/pcommand ios_sim_log [device-udid]`` (default ``booted``). Mirrors ``make android-log``. """ import os from batools import iossim args = pcommand.get_args() udid = args[0] if args else 'booted' iossim.stream_log( udid, os.environ.get('IOS_LOG_SUBSYSTEM', iossim.DEFAULT_LOG_SUBSYSTEM), )
[docs] def assetworkspace() -> None: """Get/put an asset-package source workspace via a fast local cache. Maintains a persistent local checkout of a cloud asset-package source workspace under ``.cache/asset_package_sources/<NAME>/`` (gitignored; bacloud syncs only diffs, so repeat gets are fast) and wraps ``bacloud workspace get``/``put`` against it. bacloud itself guards against mid-air collisions: a ``get`` stashes the workspace's snapshot id in a ``.bacloudstate.json`` and a ``put`` is rejected if the workspace has changed since (``put --force`` overrides). So the only discipline is the standard cycle: ``get`` -> edit the files under the printed path -> ``put``. Subcommands:: assetworkspace get <NAME> assetworkspace put <NAME> [--force] assetworkspace path <NAME> ``<NAME>`` is the case-sensitive cloud workspace name (e.g. ``BaBuiltinAssets``); ``path`` just prints the cache dir (no network). """ import os import subprocess from efro.error import CleanError args = pcommand.get_args() if len(args) < 2: raise CleanError( 'Expected: <subcommand> <workspace-name> [flags].' ' Subcommands: get, put, path.' ) subcmd, name = args[0], args[1] flags = args[2:] ws_dir = os.path.join( pcommand.PROJROOT, '.cache', 'asset_package_sources', name ) bacloud = os.path.join(pcommand.PROJROOT, 'tools', 'bacloud') if subcmd == 'path': print(ws_dir) return if subcmd not in ('get', 'put'): raise CleanError(f'Unknown subcommand {subcmd!r}; use get, put, path.') if subcmd == 'get': os.makedirs(ws_dir, exist_ok=True) elif not os.path.isdir(ws_dir): raise CleanError( f'No local cache for {name!r} at {ws_dir};' f' run `assetworkspace get {name}` first.' ) cmd = [bacloud, 'workspace', subcmd, ws_dir, '--workspace', name] if subcmd == 'put' and '--force' in flags: cmd.append('--force') try: subprocess.run(cmd, check=True) except subprocess.CalledProcessError as exc: raise CleanError( f'bacloud workspace {subcmd} failed for {name!r}.' ) from exc verb = 'synced to' if subcmd == 'get' else 'pushed from' print(f'Workspace {name!r} {verb} {ws_dir}')
# Docs-generation hack; import some stuff that we likely only forward-declared # in our actual source code so that docs tools can find it. from typing import (Coroutine, Any, Literal, Callable, Generator, Awaitable, Sequence, Self) import asyncio from concurrent.futures import Future from pathlib import Path from enum import Enum