def setup_graph_extended(
        options_bootstrapper: OptionsBootstrapper,
        build_configuration: BuildConfiguration,
        execution_options: ExecutionOptions,
        native: Native,
        *,
        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,
    ) -> GraphScheduler:
        build_root = build_root or get_buildroot()

        build_configuration = build_configuration or BuildConfigInitializer.get(
            options_bootstrapper)
        rules = build_configuration.rules
        union_membership = UnionMembership.from_rules(
            build_configuration.union_rules)
        registered_target_types = RegisteredTargetTypes.create(
            build_configuration.target_types)

        bootstrap_options = options_bootstrapper.bootstrap_options.for_global_scope(
        )
        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(),
            *desktop.rules(),
            *graph.rules(),
            *uuid.rules(),
            *options_parsing.rules(),
            *process.rules(),
            *create_platform_rules(),
            *changed_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,
            execution_options=execution_options,
            include_trace_on_error=include_trace_on_error,
            visualize_to_dir=bootstrap_options.native_engine_visualize_to,
        )

        return GraphScheduler(scheduler, goal_map)
Exemplo n.º 2
0
    def setup_legacy_graph_extended(
        options_bootstrapper: OptionsBootstrapper,
        build_configuration: BuildConfiguration,
        execution_options: ExecutionOptions,
        *,
        pants_ignore_patterns: List[str],
        use_gitignore: bool,
        local_store_dir: str,
        local_execution_root_dir: str,
        named_caches_dir: str,
        build_root: Optional[str] = None,
        native: Optional[Native] = None,
        glob_match_error_behavior:
        GlobMatchErrorBehavior = GlobMatchErrorBehavior.warn,
        build_patterns: Optional[Iterable[str]] = None,
        build_file_prelude_globs: Optional[Iterable[str]] = None,
        build_ignore_patterns: Optional[Iterable[str]] = None,
        tags: Optional[Iterable[str]] = None,
        exclude_target_regexps: Optional[Iterable[str]] = None,
        subproject_roots: Optional[Iterable[str]] = None,
        include_trace_on_error: bool = True,
    ) -> LegacyGraphScheduler:
        """Construct and return the components necessary for LegacyBuildGraph construction."""

        build_root = build_root or get_buildroot()
        build_configuration = build_configuration or BuildConfigInitializer.get(
            options_bootstrapper)

        bootstrap_options = options_bootstrapper.bootstrap_options.for_global_scope(
        )
        execution_options = execution_options or DEFAULT_EXECUTION_OPTIONS

        build_file_aliases = build_configuration.registered_aliases
        rules = build_configuration.rules
        union_membership = UnionMembership.from_rules(
            build_configuration.union_rules)

        registered_target_types = RegisteredTargetTypes.create(
            build_configuration.target_types)
        parser = Parser(target_type_aliases=registered_target_types.aliases,
                        object_aliases=build_file_aliases)
        address_mapper = AddressMapper(
            parser=parser,
            prelude_glob_patterns=build_file_prelude_globs,
            build_patterns=build_patterns,
            build_ignore_patterns=build_ignore_patterns,
            tags=tags,
            exclude_target_regexps=exclude_target_regexps,
            subproject_roots=subproject_roots,
        )

        @rule
        def address_mapper_singleton() -> AddressMapper:
            return address_mapper

        @rule
        def glob_match_error_behavior_singleton() -> GlobMatchErrorBehavior:
            return glob_match_error_behavior

        @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()),
            RootRule(Console),
            *build_files.rules(),
            *fs.rules(),
            *graph.rules(),
            *uuid.rules(),
            *options_parsing.rules(),
            *process.rules(),
            *create_platform_rules(),
            *changed_rules(),
            *rules,
        ))

        goal_map = EngineInitializer._make_goal_map_from_rules(rules)

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

        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),
            rules=rules,
            union_membership=union_membership,
            execution_options=execution_options,
            include_trace_on_error=include_trace_on_error,
            visualize_to_dir=bootstrap_options.native_engine_visualize_to,
        )

        return LegacyGraphScheduler(scheduler, build_file_aliases, goal_map)