Skip to content

feat: add `labgrid_config_toolchain`

Matthew Clarkson requested to merge config into main

This adds a significant refactor of the project.

An issue has been found that prevents a LabGrid configuration being loaded because the Python dependencies for the configuration are not available.

This manifests in the current end-to-end Docker tests as the DockerDriver not being able to find the docker module.

The issue is that we need a py_library dependency for the resolved LabGrid configuration for the target platform. However, where the toolchain gets resolved in labgrid_genrule is too high up the rule graph. The resolution needs to happen within the passed in Python tool.

This patch provides three lazily resolved labels:

  • //labgrid/config:src (aliased as //labgrid/config)
  • //labgrid/config:deps
  • //labgrid/manager:src (aliased as //labgrid/manager)

A script that is provided to labgrid_genrule can do:

py_binary(
    name = "something",
    srcs = ["something.py"],
    deps = ["@rules_labgrid//labgrid/config:deps"],
)

When the tool loads the LabGrid configuration from LG_ENV, it is guranteed to have the correct Python dependencies available.

The crucial feature is that the labels are extract their values from two toolchains. Two are required otherwise there is a circular dependency between the manager and the configuration.

  • //labgrid/toolchain/config:type
  • //labgrid/toolchain/manager:type

To do the lazy resolution of the toolchain, we do a configuration trick to transition further down the stack back into the target/exec combo that labgrid_genrule is in. This is contained under //labgrid/cfg. The way this works is:

  • labgrid_genrule uses //labgrid/cfg/store.bzl to perform an incoming transition.
  • That transition stores the current platform in //labgrid/cfg:platform
  • Later, the /labgrid/{config,manager} targets use the //labgrid/cfg/incoming.bzl transition to put //labgrid/cfg:platform back into the target platform
  • Those rules then resolve the toolchains to get the registered information for the LabGrid target platform

As of this patch, the Docker end-to-end test shows an example of the usage of labgrid_config_toolchain. bazelisk test docker:test has the same operation as before.

Edited by Matthew Clarkson

Merge request reports