def setUp(self): super().setUp() init_subsystems([LibcDev, NativeToolchain], options={ "libc": { "enable_libc_search": True, }, }) self.platform = Platform.current self.toolchain = global_subsystem_instance(NativeToolchain) self.rules = native_backend_rules() + create_platform_rules() gcc_subsystem = global_subsystem_instance(GCC) self.gcc_version = gcc_subsystem.version() llvm_subsystem = global_subsystem_instance(LLVM) self.llvm_version = llvm_subsystem.version()
def setup_legacy_graph_extended( pants_ignore_patterns: List[str], use_gitignore: bool, local_store_dir: str, local_execution_root_dir: str, named_caches_dir: str, build_file_prelude_globs: Tuple[str, ...], options_bootstrapper: OptionsBootstrapper, build_configuration: BuildConfiguration, execution_options: ExecutionOptions, build_root: Optional[str] = None, native: Optional[Native] = None, glob_match_error_behavior: GlobMatchErrorBehavior = GlobMatchErrorBehavior.warn, build_ignore_patterns=None, exclude_target_regexps=None, subproject_roots=None, include_trace_on_error: bool = True, ) -> LegacyGraphScheduler: """Construct and return the components necessary for LegacyBuildGraph construction. :param local_store_dir: The directory to use for storing the engine's LMDB store in. :param local_execution_root_dir: The directory to use for local execution sandboxes. :param named_caches_dir: The base directory for named cache storage. :param build_file_prelude_globs: Globs to match files to be prepended to all BUILD files. :param build_root: A path to be used as the build root. If None, then default is used. :param native: An instance of the native-engine subsystem. :param options_bootstrapper: A `OptionsBootstrapper` object containing bootstrap options. :param build_configuration: The `BuildConfiguration` object to get build file aliases from. :param glob_match_error_behavior: How to behave if a glob specified for a target's sources or bundles does not expand to anything. :param list build_ignore_patterns: A list of paths ignore patterns used when searching for BUILD files, usually taken from the '--build-ignore' global option. :param list exclude_target_regexps: A list of regular expressions for excluding targets. :param list subproject_roots: Paths that correspond with embedded build roots under the current build root. :param include_trace_on_error: If True, when an error occurs, the error message will include the graph trace. :param execution_options: Option values for (remote) process execution. """ 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( ) build_file_aliases = build_configuration.registered_aliases() rules = build_configuration.rules() registered_target_types = RegisteredTargetTypes.create( build_configuration.target_types()) symbol_table = _legacy_symbol_table(build_file_aliases, registered_target_types) execution_options = execution_options or DEFAULT_EXECUTION_OPTIONS # Register "literal" subjects required for these rules. parser = LegacyPythonCallbacksParser(symbol_table, build_file_aliases) address_mapper = AddressMapper( parser=parser, prelude_glob_patterns=build_file_prelude_globs, build_ignore_patterns=build_ignore_patterns, exclude_target_regexps=exclude_target_regexps, subproject_roots=subproject_roots, ) @rule def glob_match_error_behavior_singleton() -> GlobMatchErrorBehavior: return glob_match_error_behavior @rule def build_configuration_singleton() -> BuildConfiguration: return build_configuration @rule def symbol_table_singleton() -> SymbolTable: return symbol_table @rule def registered_target_types_singleton() -> RegisteredTargetTypes: return registered_target_types @rule def union_membership_singleton() -> UnionMembership: return UnionMembership(build_configuration.union_rules()) @rule def build_root_singleton() -> BuildRoot: return cast(BuildRoot, BuildRoot.instance) # Create a Scheduler containing graph and filesystem rules, with no installed goals. The # LegacyBuildGraph will explicitly request the products it needs. rules = ( RootRule(Console), glob_match_error_behavior_singleton, build_configuration_singleton, symbol_table_singleton, registered_target_types_singleton, union_membership_singleton, build_root_singleton, *interactive_runner.rules(), *graph.rules(), *options_parsing.rules(), *process.rules(), *target.rules(), *create_legacy_graph_tasks(), *create_fs_rules(), *create_platform_rules(), *create_graph_rules(address_mapper), *structs_rules(), *changed_rules(), *binary_tool_rules(), *binary_util_rules(), *rules, ) goal_map = EngineInitializer._make_goal_map_from_rules(rules) union_rules = build_configuration.union_rules() scheduler = Scheduler( native=native, ignore_patterns=pants_ignore_patterns, use_gitignore=use_gitignore, build_root=build_root, local_store_dir=local_store_dir, local_execution_root_dir=local_execution_root_dir, named_caches_dir=named_caches_dir, rules=rules, union_rules=union_rules, 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)
def rules(cls): return (*native_backend_rules(), *create_platform_rules())
def setup_legacy_graph_extended( pants_ignore_patterns, local_store_dir, build_file_imports_behavior, options_bootstrapper, build_configuration, build_root=None, native=None, glob_match_error_behavior=None, build_ignore_patterns=None, exclude_target_regexps=None, subproject_roots=None, include_trace_on_error=True, execution_options=None, ): """Construct and return the components necessary for LegacyBuildGraph construction. :param list pants_ignore_patterns: A list of path ignore patterns for FileSystemProjectTree, usually taken from the '--pants-ignore' global option. :param local_store_dir: The directory to use for storing the engine's LMDB store in. :param build_file_imports_behavior: How to behave if a BUILD file being parsed tries to use import statements. Valid values: "allow", "warn", "error". :type build_file_imports_behavior: string :param str build_root: A path to be used as the build root. If None, then default is used. :param Native native: An instance of the native-engine subsystem. :param options_bootstrapper: A `OptionsBootstrapper` object containing bootstrap options. :type options_bootstrapper: :class:`pants.options.options_bootstrapper.OptionsBootstrapper` :param build_configuration: The `BuildConfiguration` object to get build file aliases from. :type build_configuration: :class:`pants.build_graph.build_configuration.BuildConfiguration` :param glob_match_error_behavior: How to behave if a glob specified for a target's sources or bundles does not expand to anything. :type glob_match_error_behavior: :class:`pants.option.global_options.GlobMatchErrorBehavior` :param list build_ignore_patterns: A list of paths ignore patterns used when searching for BUILD files, usually taken from the '--build-ignore' global option. :param list exclude_target_regexps: A list of regular expressions for excluding targets. :param list subproject_roots: Paths that correspond with embedded build roots under the current build root. :param bool include_trace_on_error: If True, when an error occurs, the error message will include the graph trace. :param execution_options: Option values for (remote) process execution. :type execution_options: :class:`pants.option.global_options.ExecutionOptions` :returns: A LegacyGraphScheduler. """ 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() build_file_aliases = build_configuration.registered_aliases() rules = build_configuration.rules() symbol_table = _legacy_symbol_table(build_file_aliases) project_tree = FileSystemProjectTree(build_root, pants_ignore_patterns) execution_options = execution_options or DEFAULT_EXECUTION_OPTIONS # Register "literal" subjects required for these rules. parser = LegacyPythonCallbacksParser( symbol_table, build_file_aliases, build_file_imports_behavior ) address_mapper = AddressMapper(parser=parser, build_ignore_patterns=build_ignore_patterns, exclude_target_regexps=exclude_target_regexps, subproject_roots=subproject_roots) @rule def glob_match_error_behavior_singleton() -> GlobMatchErrorBehavior: return glob_match_error_behavior or GlobMatchErrorBehavior.ignore @rule def build_configuration_singleton() -> BuildConfiguration: return build_configuration @rule def symbol_table_singleton() -> SymbolTable: return symbol_table @rule def union_membership_singleton() -> UnionMembership: return UnionMembership(build_configuration.union_rules()) @rule def build_root_singleton() -> BuildRoot: return BuildRoot.instance @rule async def single_build_file_address(specs: Specs) -> BuildFileAddress: build_file_addresses = await Get(BuildFileAddresses, Specs, specs) if len(build_file_addresses.dependencies) == 0: raise ResolveError("No targets were matched") if len(build_file_addresses.dependencies) > 1: potential_addresses = await Get(BuildFileAddresses, Specs, specs) targets = [bfa.to_address() for bfa in potential_addresses] output = '\n '.join(str(target) for target in targets) raise ResolveError( "Expected a single target, but was given multiple targets:\n" f"Did you mean one of:\n {output}" ) return build_file_addresses.dependencies[0] # Create a Scheduler containing graph and filesystem rules, with no installed goals. The # LegacyBuildGraph will explicitly request the products it needs. rules = ( [ RootRule(Console), glob_match_error_behavior_singleton, build_configuration_singleton, symbol_table_singleton, union_membership_singleton, build_root_singleton, single_build_file_address, ] + create_legacy_graph_tasks() + create_fs_rules() + create_interactive_runner_rules() + create_process_rules() + create_platform_rules() + create_graph_rules(address_mapper) + create_options_parsing_rules() + structs_rules() + rules ) goal_map = EngineInitializer._make_goal_map_from_rules(rules) union_rules = build_configuration.union_rules() scheduler = Scheduler( native, project_tree, local_store_dir, rules, union_rules, 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)
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)
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)