Esempio n. 1
0
    def setup_graph_extended(
        build_configuration: BuildConfiguration,
        execution_options: ExecutionOptions,
        *,
        executor: PyExecutor,
        pants_ignore_patterns: list[str],
        use_gitignore: bool,
        local_store_options: LocalStoreOptions,
        local_execution_root_dir: str,
        named_caches_dir: str,
        use_deprecated_python_macros: bool,
        ca_certs_path: str | None = None,
        build_root: str | None = None,
        include_trace_on_error: bool = True,
        engine_visualize_to: str | None = None,
        watch_filesystem: bool = True,
    ) -> GraphScheduler:
        build_root_path = build_root or get_buildroot()

        rules = build_configuration.rules
        union_membership: UnionMembership
        registered_target_types = RegisteredTargetTypes.create(
            build_configuration.target_types)

        execution_options = execution_options or DEFAULT_EXECUTION_OPTIONS

        @rule
        def parser_singleton() -> Parser:
            return Parser(
                build_root=build_root_path,
                target_type_aliases=registered_target_types.aliases,
                object_aliases=build_configuration.registered_aliases,
                use_deprecated_python_macros=use_deprecated_python_macros,
            )

        @rule
        def build_configuration_singleton() -> BuildConfiguration:
            return build_configuration

        @rule
        def registered_target_types_singleton() -> RegisteredTargetTypes:
            return registered_target_types

        @rule
        def union_membership_singleton() -> UnionMembership:
            return union_membership

        @rule
        def build_root_singleton() -> BuildRoot:
            return cast(BuildRoot, BuildRoot.instance)

        # Create a Scheduler containing graph and filesystem rules, with no installed goals.
        rules = FrozenOrderedSet((
            *collect_rules(locals()),
            *build_files.rules(),
            *fs.rules(),
            *environment.rules(),
            *desktop.rules(),
            *graph.rules(),
            *options_parsing.rules(),
            *process.rules(),
            *system_binaries.rules(),
            *platform.rules(),
            *changed_rules(),
            *streaming_workunit_handler_rules(),
            *specs_calculator.rules(),
            *rules,
        ))

        goal_map = EngineInitializer._make_goal_map_from_rules(rules)

        union_membership = UnionMembership.from_rules((
            *build_configuration.union_rules,
            *(r for r in rules if isinstance(r, UnionRule)),
        ))

        rules = FrozenOrderedSet((
            *rules,
            # Install queries for each Goal.
            *(QueryRule(goal_type, GraphSession.goal_param_types)
              for goal_type in goal_map.values()),
            # Install queries for each request/response pair used by the BSP support.
            # Note: These are necessary because the BSP support is a built-in goal that makes
            # synchronous requests into the engine.
            *(QueryRule(impl.response_type, (impl.request_type, Workspace))
              for impl in union_membership.get(BSPHandlerMapping)),
            QueryRule(Snapshot, [PathGlobs]),  # Used by the SchedulerService.
        ))

        def ensure_absolute_path(v: str) -> str:
            return Path(v).resolve().as_posix()

        def ensure_optional_absolute_path(v: str | None) -> str | None:
            if v is None:
                return None
            return ensure_absolute_path(v)

        scheduler = Scheduler(
            ignore_patterns=pants_ignore_patterns,
            use_gitignore=use_gitignore,
            build_root=build_root_path,
            local_execution_root_dir=ensure_absolute_path(
                local_execution_root_dir),
            named_caches_dir=ensure_absolute_path(named_caches_dir),
            ca_certs_path=ensure_optional_absolute_path(ca_certs_path),
            rules=rules,
            union_membership=union_membership,
            executor=executor,
            execution_options=execution_options,
            local_store_options=local_store_options,
            include_trace_on_error=include_trace_on_error,
            visualize_to_dir=engine_visualize_to,
            watch_filesystem=watch_filesystem,
        )

        return GraphScheduler(scheduler, goal_map)
Esempio n. 2
0
    def setup_graph_extended(
        build_configuration: BuildConfiguration,
        execution_options: ExecutionOptions,
        native: Native,
        *,
        executor: PyExecutor,
        pants_ignore_patterns: List[str],
        use_gitignore: bool,
        local_store_dir: str,
        local_execution_root_dir: str,
        named_caches_dir: str,
        ca_certs_path: Optional[str] = None,
        build_root: Optional[str] = None,
        include_trace_on_error: bool = True,
        native_engine_visualize_to: Optional[str] = None,
    ) -> GraphScheduler:
        build_root = build_root or get_buildroot()

        rules = build_configuration.rules
        union_membership = UnionMembership.from_rules(
            build_configuration.union_rules)
        registered_target_types = RegisteredTargetTypes.create(
            build_configuration.target_types)

        execution_options = execution_options or DEFAULT_EXECUTION_OPTIONS

        @rule
        def parser_singleton() -> Parser:
            return Parser(
                target_type_aliases=registered_target_types.aliases,
                object_aliases=build_configuration.registered_aliases,
            )

        @rule
        def build_configuration_singleton() -> BuildConfiguration:
            return build_configuration

        @rule
        def registered_target_types_singleton() -> RegisteredTargetTypes:
            return registered_target_types

        @rule
        def union_membership_singleton() -> UnionMembership:
            return union_membership

        @rule
        def build_root_singleton() -> BuildRoot:
            return cast(BuildRoot, BuildRoot.instance)

        # Create a Scheduler containing graph and filesystem rules, with no installed goals.
        rules = FrozenOrderedSet((
            *collect_rules(locals()),
            *build_files.rules(),
            *fs.rules(),
            *environment.rules(),
            *desktop.rules(),
            *graph.rules(),
            *options_parsing.rules(),
            *process.rules(),
            *platform.rules(),
            *changed_rules(),
            *streaming_workunit_handler_rules(),
            *specs_calculator.rules(),
            *rules,
        ))
        goal_map = EngineInitializer._make_goal_map_from_rules(rules)
        rules = FrozenOrderedSet((
            *rules,
            # Install queries for each Goal.
            *(QueryRule(goal_type, GraphSession.goal_param_types)
              for goal_type in goal_map.values()),
            QueryRule(Snapshot, [PathGlobs]),  # Used by the SchedulerService.
        ))

        def ensure_absolute_path(v: str) -> str:
            return Path(v).resolve().as_posix()

        def ensure_optional_absolute_path(v: Optional[str]) -> Optional[str]:
            if v is None:
                return None
            return ensure_absolute_path(v)

        scheduler = Scheduler(
            native=native,
            ignore_patterns=pants_ignore_patterns,
            use_gitignore=use_gitignore,
            build_root=build_root,
            local_store_dir=ensure_absolute_path(local_store_dir),
            local_execution_root_dir=ensure_absolute_path(
                local_execution_root_dir),
            named_caches_dir=ensure_absolute_path(named_caches_dir),
            ca_certs_path=ensure_optional_absolute_path(ca_certs_path),
            rules=rules,
            union_membership=union_membership,
            executor=executor,
            execution_options=execution_options,
            include_trace_on_error=include_trace_on_error,
            visualize_to_dir=native_engine_visualize_to,
        )

        return GraphScheduler(scheduler, goal_map)