Python API Reference#
pw_build: Integrations for Bazel, GN, and CMake
pw_build.runfiles_manager#
A library that bridges runfiles management between Bazel and bootstrap.
- class pw_build.runfiles_manager.RunfilesManager#
A class that helps manage runtime file resources.
Projects that use bootstrap get their files from the currently activated environment. In contrast, Bazel-based projects will get their files from Bazel’s runfiles mechanism.
This class bridges those differences, and simplifies the process of writing tools that work in both environments. Every resource is associated with a key used to retrieve the resource, and the resources must be registered twice: once for Bazel-based projects, and once for other projects that run from a shell environment bootstrapped by pw_env_setup. To ensure consistency, if a resource is used by one environment, an error will be emitted if it was never registered for the other environment.
If a file is exclusive to one of the two environments, it may be tagged as
exclusive=True
to suppress the error emitted if a resource isn’t properly registered for the other environment. Attempting to access a resourceexclusive
to a different environment will still raise an error.This class is also a
pw_cli.tool_runner.ToolRunner
, and may be used to launch subprocess actions.- __init__()#
- add_bazel_file(key: str, import_path: str, exclusive: bool = False) None #
Maps a non-executable file resource to the provided key.
Files added through this mechanism will be available when running from the Bazel build. Unless you specify
exclusive=True
, you must also register this file withpw_build.runfiles_manager.RunfilesManager.add_bootstrapped_file()
before attempting to use it.The
import_path
is the import path of thepw_py_importable_runfile
rule that provides the desired file.
- add_bazel_tool(tool_name: str, import_path: str, exclusive: bool = False) None #
Maps a runnable tool to the provided tool name.
Files added through this mechanism will be available when running from the Bazel build. Unless you specify
exclusive=True
, you must also register this file withpw_build.runfiles_manager.RunfilesManager.add_bootstrapped_tool()
before attempting to use it.The
import_path
is the import path of thepw_py_importable_runfile
rule that provides the desired file.
- add_bootstrapped_file(key: str, path_or_env: str, exclusive: bool = False) None #
Maps a non-executable file resource to the provided key.
Files added through this mechanism will be available from an activated environment constructed via pw_env_setup. Unless you specify
exclusive=True
, you must also register this file withpw_build.runfiles_manager.RunfilesManager.add_bazel_file()
before attempting to use it.Environment variables may be expanded using
${PW_FOO}
within the path expression.
- add_bootstrapped_tool(
- tool_name: str,
- path_or_env: str,
- from_shell_path: bool = False,
- exclusive: bool = False,
Maps a runnable tool to the provided tool name.
Files added through this mechanism will be available from an activated environment constructed via pw_env_setup. Unless you specify
exclusive=True
, you must also register this tool withpw_build.runfiles_manager.RunfilesManager.add_bazel_tool()
before attempting to use it.Environment variables may be expanded using
${PW_FOO}
within the path expression. Iffrom_shell_path=True
is enabled, the active shellPATH
is searched for the requested tool, and environment variables will not be expanded.
- get(key: str) Path #
Retrieves the
Path
to the resource at the requested key.