Esempio n. 1
0
def rules():
    return [
        # goals
        *check.rules(),
        *export.rules(),
        *fmt.rules(),
        *generate_lockfiles.rules(),
        *lint.rules(),
        *update_build_files.rules(),
        *package.rules(),
        *publish.rules(),
        *repl.rules(),
        *run.rules(),
        *tailor.rules(),
        *test.rules(),
        *bsp_rules(),
        # util_rules
        *anonymous_telemetry.rules(),
        *archive.rules(),
        *config_files.rules(),
        *distdir.rules(),
        *external_tool.rules(),
        *git.rules(),
        *source_files.rules(),
        *source_root.rules(),
        *stats_aggregator.rules(),
        *stripped_source_files.rules(),
        *subprocess_environment.rules(),
        *system_binaries.rules(),
        *target_type_rules(),
    ]
Esempio n. 2
0
def setup_bsp_server():
    with setup_pipes() as pipes:
        context = BSPContext()
        rule_runner = RuleRunner(rules=bsp_rules(), extra_session_values={BSPContext: context})
        conn = BSPConnection(
            rule_runner.scheduler,
            rule_runner.union_membership,
            context,
            pipes.inbound_reader,
            pipes.outbound_writer,
        )

        def run_bsp_server():
            conn.run()

        bsp_thread = Thread(target=run_bsp_server)
        bsp_thread.daemon = True
        bsp_thread.start()

        client_reader = JsonRpcStreamReader(pipes.outbound_reader)
        client_writer = JsonRpcStreamWriter(pipes.inbound_writer)
        endpoint = Endpoint({}, lambda msg: client_writer.write(msg))

        def run_client():
            client_reader.listen(lambda msg: endpoint.consume(msg))

        client_thread = Thread(target=run_client)
        client_thread.daemon = True
        client_thread.start()

        try:
            yield endpoint
        finally:
            client_reader.close()
            client_writer.close()
Esempio n. 3
0
def rule_runner() -> RuleRunner:
    return RuleRunner(
        rules=[
            *bsp_rules(),
            *java_bsp_rules.rules(),
            *javac.rules(),
            *jvm_tool.rules(),
            *jvm_util_rules.rules(),
            *jdk_rules.rules(),
            QueryRule(BSPBuildTargets, ()),
            QueryRule(Targets, [BuildTargetIdentifier]),
        ],
        target_types=[JavaSourceTarget],
        objects={"parametrize": Parametrize},
    )
Esempio n. 4
0
def setup_bsp_server(
    rule_runner: RuleRunner | None = None, *, notification_names: set[str] | None = None
):
    rule_runner = rule_runner or RuleRunner(rules=bsp_rules())
    notification_names = notification_names or set()
    stdio_destination = native_engine.stdio_thread_get_destination()

    with setup_pipes() as pipes:
        context = BSPContext()
        rule_runner.set_session_values({BSPContext: context})
        conn = BSPConnection(
            rule_runner.scheduler,
            rule_runner.union_membership,
            context,
            pipes.server_reader,
            pipes.server_writer,
        )

        def run_bsp_server():
            native_engine.stdio_thread_set_destination(stdio_destination)
            conn.run()

        bsp_thread = Thread(target=run_bsp_server)
        bsp_thread.daemon = True
        bsp_thread.start()

        client_reader = JsonRpcStreamReader(pipes.client_reader)
        client_writer = JsonRpcStreamWriter(pipes.client_writer)
        notifications = Notifications([])
        endpoint = Endpoint(
            {name: functools.partial(notifications._record, name) for name in notification_names},
            lambda msg: client_writer.write(msg),
        )

        def run_client():
            client_reader.listen(lambda msg: endpoint.consume(msg))

        client_thread = Thread(target=run_client)
        client_thread.daemon = True
        client_thread.start()

        try:
            yield endpoint, notifications
        finally:
            client_reader.close()
            client_writer.close()
Esempio n. 5
0
def jvm_rule_runner() -> RuleRunner:
    rule_runner = RuleRunner(
        rules=[
            *bsp_rules(),
            *java_bsp_rules(),
            *scala_bsp_rules(),
            *config_files.rules(),
            *coursier_fetch_rules(),
            *lockfile.rules(),
            *classpath.rules(),
            *coursier_setup_rules(),
            *external_tool_rules(),
            *scala_dep_inf_rules(),
            *javac_rules(),
            *jdk_rules.rules(),
            *scalac_rules(),
            *source_files.rules(),
            *scala_target_types_rules(),
            *java_target_types_rules(),
            *util_rules(),
            *testutil.rules(),
            *stripped_source_files.rules(),
        ],
        target_types=[
            JavaSourcesGeneratorTarget,
            JvmArtifactTarget,
            ScalatestTestsGeneratorTarget,
        ],
    )
    rule_runner.set_options(
        args=[
            "--experimental-bsp-groups-config-files=bsp-groups.toml",
        ],
        env_inherit=PYTHON_BOOTSTRAP_ENV,
    )
    return rule_runner