def test_validation(caplog, bc_builder: BuildConfiguration.Builder) -> None:
    def mk_dummy_subsys(_options_scope: str,
                        goal: bool = False) -> Type[Subsystem]:
        class DummySubsystem(GoalSubsystem if goal else Subsystem
                             ):  # type: ignore[misc]
            options_scope = _options_scope

        return DummySubsystem

    def mk_dummy_tgt(_alias: str) -> Type[Target]:
        class DummyTarget(Target):
            alias = _alias
            core_fields = tuple()  # type: ignore[var-annotated]

        return DummyTarget

    bc_builder.register_subsystems(
        "_dummy_for_test_",
        (
            mk_dummy_subsys("foo"),
            mk_dummy_subsys("Bar-bar"),
            mk_dummy_subsys("baz"),
            mk_dummy_subsys("qux", goal=True),
            mk_dummy_subsys("global"),
        ),
    )
    bc_builder.register_target_types(
        "_dummy_for_test_",
        (mk_dummy_tgt("bar_bar"), mk_dummy_tgt("qux"), mk_dummy_tgt("global")))
    with pytest.raises(TypeError) as e:
        bc_builder.create()
    assert (
        "Naming collision: `Bar-bar`/`bar_bar` is registered as a subsystem and a "
        "target type." in caplog.text)
    assert "Naming collision: `qux` is registered as a goal and a target type." in caplog.text
    assert (
        "Naming collision: `global` is registered as a reserved name, a subsystem "
        "and a target type." in caplog.text)
    assert "Found naming collisions" in str(e)
def test_register_subsystems(bc_builder: BuildConfiguration.Builder) -> None:
    def mk_dummy_subsys(_options_scope: str) -> Type[Subsystem]:
        class DummySubsystem(Subsystem):
            options_scope = _options_scope

        return DummySubsystem

    foo = mk_dummy_subsys("foo")
    bar = mk_dummy_subsys("bar")
    baz = mk_dummy_subsys("baz")
    bc_builder.register_subsystems("backend1", [foo, bar])
    bc_builder.register_subsystems("backend2", [bar, baz])
    bc_builder.register_subsystems("backend3", [baz])
    bc = bc_builder.create()

    assert bc.subsystem_to_providers == FrozenDict({
        foo: ("backend1", ),
        bar: ("backend1", "backend2"),
        baz: (
            "backend2",
            "backend3",
        ),
    })
Esempio n. 3
0
def register_builtin_goals(
        build_configuration: BuildConfiguration.Builder) -> None:
    build_configuration.register_subsystems("pants.goal", builtin_goals())