Bazel Macros and Rules#
ITF provides three public Bazel build definitions: the itf_target macro, which compiles a target file
during the build, the py_itf_test macro for declaring tests, and the py_itf_plugin rule for declaring the
Bazel target of a pack (or of a plain pytest plugin). The words are defined in the glossary of The ITF model: what things are called, where each fact lives, who decides.
itf_target#
Defined in //bazel:itf_target.bzl. Declare with:
load("@score_itf//:defs.bzl", "itf_target")
itf_target(
name = "ecu",
src = "ecu.itf.yaml",
overrides = ["lab2.itf.yaml"],
packs = ["@score_itf//score/itf/packs/docker", "@score_itf//score/itf/packs/ssh"],
srcs = ["policy.py"],
files = {"ITF_IMAGE_LOAD": "//images:load"}, # the target file says ${ITF_IMAGE_LOAD}
tools = {"ITF_TCPDUMP": "//tools:tcpdump"}, # built for the execution platform
)
The itf_target supplies every ${NAME} its target file uses: files for target-built files,
tools for execution-platform files, and env for other values. Its tests inherit them; a test’s own
env can still override a value. It also carries the
Python policy sources named by YAML policies: to its tests through ItfTargetInfo. For the snippet
above, explicitly declare policies: [./policy.py] in ecu.itf.yaml and invoke from the project root
containing that Python file. YAML selects policies; srcs only bundles the files. There is no required
basename, proximity or single-file restriction, and no planner --policy selection.
Relative paths are based on the YAML that declares them; absolute paths stay absolute. Inline YAML uses the invocation working directory. See Write tests for policy selection and merge rules. Direct Session, CLI and pytest share the same explicit selection; legacy handling stays in compat.
bazel build :ecu loads the packs, compiles the target file exactly as a test run does (both gates, nothing
constructed), writes ecu.plan.json and fails, printing ITF’s diagnostics, when the target file does not
compile or when a factory label names a pack that is not in packs.
Attribute |
Type |
Default |
Description |
|---|---|---|---|
|
label |
mandatory |
The target file (YAML). |
|
label list |
|
Override files: target files holding only what changes, merged by role in this order. |
|
label list |
|
Pack targets ( |
|
label list |
|
Files the target file includes ( |
|
label list |
|
Python source files named by YAML |
|
label list |
|
Directories of contract definitions (optional). |
|
string dict |
|
Values for the target file’s |
|
dict of name to label |
|
Built files the target file refers to: |
|
dict of name to label |
|
Host-executed tools, with the same environment/runfiles behavior as |
py_itf_test#
Defined in //bazel:py_itf_test.bzl. Declare with:
load("@score_itf//:defs.bzl", "py_itf_test")
Minimal example:
py_itf_test(
name = "test_example",
srcs = ["test_example.py"],
target = ":ecu", # an itf_target: the target file this test runs against
)
Attributes#
Attribute |
Type |
Default |
Description |
|---|---|---|---|
|
label list |
mandatory |
Test source files ( |
|
label list |
|
List of |
|
label |
none |
An |
|
label list |
|
Directories of contract definitions (YAML) loaded besides ITF’s own, for the test and its plan
( |
|
string list |
|
Extra CLI arguments passed to pytest. Supports
|
|
label list |
|
Data files built for target configuration (e.g. QEMU images,
config files). |
|
label list |
|
Data files built for the exec (host) configuration. |
|
label list |
|
Additional Python dependencies for the test binary. |
|
label |
|
Custom pytest configuration file. If omitted, the default
|
|
string dict |
|
Additional environment variables set for the test process.
|
|
string list |
|
Standard Bazel test tags (e.g. |
|
string |
|
Standard Bazel test timeout ( |
|
string |
|
Standard Bazel test size. |
py_itf_plugin#
Defined in //bazel:py_itf_plugin.bzl. Declare with:
load("@score_itf//bazel:py_itf_plugin.bzl", "py_itf_plugin")
Example, the Bazel target of a pack:
py_itf_plugin(
name = "my_plugin",
pack = "my", # the pack's name: the first part of its labels (my.exec)
enabled_plugins = ["my_plugin"],
py_library = "//path/to:my_plugin_lib",
visibility = ["//visibility:public"],
)
Attributes#
Attribute |
Type |
Default |
Description |
|---|---|---|---|
|
label |
mandatory |
The |
|
string |
|
The pack this target loads, as named in factory labels ( |
|
string list |
|
Pytest plugin module paths to activate (passed as |
|
string list |
|
Additional CLI arguments contributed to every test that uses this
plugin. Supports |
|
label list |
|
Data files built for target configuration that are required by the plugin at runtime. |
|
label list |
|
Data files built for exec (host) configuration required by the plugin. |
|
string dict |
|
Environment variables contributed by the plugin to every test that uses it. |