def _select_buildgraph_and_address_mapper(self, use_engine, path_ignore_patterns, build_ignore_patterns, daemon_buildgraph=None): """Selects a BuildGraph and AddressMapper to use then constructs them and returns them. :param bool use_engine: Whether or not to use the v2 engine to construct the BuildGraph. :param list path_ignore_patterns: The path ignore patterns from `--pants-ignore`. :param LegacyBuildGraph daemon_buildgraph: A cached graph to reuse, if available. :returns a tuple of the graph and the address mapper. """ if daemon_buildgraph is not None: # NB: The daemon may provide a buildgraph. In that case, we ignore the use_engine option, # since using the engine is implied by using the daemon. However, it is possible for the # daemon to pass a non-engine backed build graph instance, so we fall back to that. if isinstance(daemon_buildgraph, LegacyBuildGraph): return daemon_buildgraph, LegacyAddressMapper(daemon_buildgraph, self._root_dir) else: return daemon_buildgraph, daemon_buildgraph._address_mapper elif use_engine: root_specs = EngineInitializer.parse_commandline_to_spec_roots(options=self._options, build_root=self._root_dir) graph_helper = EngineInitializer.setup_legacy_graph(path_ignore_patterns) graph = graph_helper.create_graph(root_specs) return graph, LegacyAddressMapper(graph, self._root_dir) else: address_mapper = BuildFileAddressMapper(self._build_file_parser, get_project_tree(self._global_options), build_ignore_patterns, exclude_target_regexps=self._global_options.exclude_target_regexp) return MutableBuildGraph(address_mapper), address_mapper
def _init_graph(self, use_engine, pants_ignore_patterns, build_ignore_patterns, exclude_target_regexps, target_specs, graph_helper=None): """Determines the BuildGraph, AddressMapper and spec_roots for a given run. :param bool use_engine: Whether or not to use the v2 engine to construct the BuildGraph. :param list pants_ignore_patterns: The pants ignore patterns from '--pants-ignore'. :param list build_ignore_patterns: The build ignore patterns from '--build-ignore', applied during BUILD file searching. :param list exclude_target_regexps: Regular expressions for targets to be excluded. :param list target_specs: The original target specs. :param LegacyGraphHelper graph_helper: A LegacyGraphHelper to use for graph construction, if available. This would usually come from the daemon. :returns: A tuple of (BuildGraph, AddressMapper, spec_roots). """ # N.B. Use of the daemon implies use of the v2 engine. if graph_helper or use_engine: # The daemon may provide a `graph_helper`. If that's present, use it for graph construction. graph_helper = graph_helper or EngineInitializer.setup_legacy_graph( pants_ignore_patterns, build_ignore_patterns=build_ignore_patterns, exclude_target_regexps=exclude_target_regexps) target_roots = TargetRoots.create(options=self._options, build_root=self._root_dir, change_calculator=graph_helper.change_calculator) return graph_helper.create_build_graph(target_roots, self._root_dir) else: address_mapper = BuildFileAddressMapper( self._build_file_parser, get_project_tree(self._global_options), build_ignore_patterns, exclude_target_regexps) return MutableBuildGraph(address_mapper), address_mapper, target_specs
def _select_buildgraph(self, use_engine, path_ignore_patterns, cached_buildgraph=None): """Selects a BuildGraph to use then constructs and returns it. :param bool use_engine: Whether or not to use the v2 engine to construct the BuildGraph. :param list path_ignore_patterns: The path ignore patterns from `--pants-ignore`. :param LegacyBuildGraph cached_buildgraph: A cached graph to reuse, if available. """ if cached_buildgraph is not None: return cached_buildgraph elif use_engine: root_specs = EngineInitializer.parse_commandline_to_spec_roots(options=self._options, build_root=self._root_dir) graph_helper = EngineInitializer.setup_legacy_graph(path_ignore_patterns) return graph_helper.create_graph(root_specs) else: return MutableBuildGraph(self._address_mapper)
def graph_helper(self, symbol_table_cls=None): with temporary_dir() as work_dir: path_ignore_patterns = ['.*'] graph_helper = EngineInitializer.setup_legacy_graph(path_ignore_patterns, work_dir, symbol_table_cls=symbol_table_cls, native=self._native) yield graph_helper
def create_address_mapper(self, build_root): work_dir = os.path.join(build_root, '.pants.d') scheduler, engine, _, _ = EngineInitializer.setup_legacy_graph( [], work_dir, build_root=build_root, native=self._native ) return LegacyAddressMapper(scheduler, engine, build_root)
def graph_helper(self, symbol_table_cls=None): with temporary_dir() as work_dir: path_ignore_patterns = ['.*'] graph_helper = EngineInitializer.setup_legacy_graph( path_ignore_patterns, work_dir, symbol_table_cls=symbol_table_cls, native=self._native) yield graph_helper
def graph_helper(self, build_file_aliases=None): with temporary_dir() as work_dir: path_ignore_patterns = ['.*'] graph_helper = EngineInitializer.setup_legacy_graph( path_ignore_patterns, work_dir, build_file_aliases=build_file_aliases, native=self._native) yield graph_helper
def create_address_mapper(self, build_root): work_dir = os.path.join(build_root, '.pants.d') scheduler = EngineInitializer.setup_legacy_graph( [], work_dir, build_file_imports_behavior='allow', build_root=build_root, native=self._native).scheduler return LegacyAddressMapper(scheduler.new_session(), build_root)
def _init_graph(self, use_engine, pants_ignore_patterns, build_ignore_patterns, exclude_target_regexps, target_specs, workdir, graph_helper=None, subproject_build_roots=None): """Determine the BuildGraph, AddressMapper and spec_roots for a given run. :param bool use_engine: Whether or not to use the v2 engine to construct the BuildGraph. :param list pants_ignore_patterns: The pants ignore patterns from '--pants-ignore'. :param list build_ignore_patterns: The build ignore patterns from '--build-ignore', applied during BUILD file searching. :param str workdir: The pants workdir. :param list exclude_target_regexps: Regular expressions for targets to be excluded. :param list target_specs: The original target specs. :param LegacyGraphHelper graph_helper: A LegacyGraphHelper to use for graph construction, if available. This would usually come from the daemon. :returns: A tuple of (BuildGraph, AddressMapper, opt Scheduler, spec_roots). """ # N.B. Use of the daemon implies use of the v2 engine. if graph_helper or use_engine: # The daemon may provide a `graph_helper`. If that's present, use it for graph construction. if not graph_helper: native = Native.create(self._global_options) native.set_panic_handler() graph_helper = EngineInitializer.setup_legacy_graph( pants_ignore_patterns, workdir, self._global_options.build_file_imports, native=native, build_file_aliases=self._build_config.registered_aliases(), build_ignore_patterns=build_ignore_patterns, exclude_target_regexps=exclude_target_regexps, subproject_roots=subproject_build_roots, include_trace_on_error=self._options.for_global_scope( ).print_exception_stacktrace) target_roots = TargetRoots.create( options=self._options, build_root=self._root_dir, change_calculator=graph_helper.change_calculator) graph, address_mapper = graph_helper.create_build_graph( target_roots, self._root_dir) return graph, address_mapper, graph_helper.scheduler, target_roots.as_specs( ) else: spec_roots = TargetRoots.parse_specs(target_specs, self._root_dir) address_mapper = BuildFileAddressMapper( self._build_file_parser, get_project_tree(self._global_options), build_ignore_patterns, exclude_target_regexps, subproject_build_roots) return MutableBuildGraph( address_mapper), address_mapper, None, spec_roots
def _setup_legacy_graph_helper(native, bootstrap_options): """Initializes a `LegacyGraphHelper` instance.""" return EngineInitializer.setup_legacy_graph( bootstrap_options.pants_ignore, bootstrap_options.pants_workdir, native=native, build_ignore_patterns=bootstrap_options.build_ignore, exclude_target_regexps=bootstrap_options.exclude_target_regexp, subproject_roots=bootstrap_options.subproject_roots, )
def open_scheduler(self, specs, symbol_table_cls=None): path_ignore_patterns = ['.*'] target_roots = TargetRoots.create(options=self._make_setup_args(specs)) graph_helper = EngineInitializer.setup_legacy_graph( path_ignore_patterns, symbol_table_cls=symbol_table_cls, native=self._native) graph = graph_helper.create_build_graph(target_roots)[0] addresses = tuple(graph.inject_specs_closure(target_roots.as_specs())) yield graph, addresses, graph_helper.scheduler
def graph_helper(self, build_file_aliases=None, build_file_imports_behavior='allow', include_trace_on_error=True): with temporary_dir() as work_dir: path_ignore_patterns = ['.*'] graph_helper = EngineInitializer.setup_legacy_graph(path_ignore_patterns, work_dir, build_file_imports_behavior, build_file_aliases=build_file_aliases, native=self._native, include_trace_on_error=include_trace_on_error) yield graph_helper
def _select_buildgraph(self, use_engine, path_ignore_patterns, cached_buildgraph=None): """Selects a BuildGraph to use then constructs and returns it. :param bool use_engine: Whether or not to use the v2 engine to construct the BuildGraph. :param list path_ignore_patterns: The path ignore patterns from `--pants-ignore`. :param LegacyBuildGraph cached_buildgraph: A cached graph to reuse, if available. """ if cached_buildgraph is not None: return cached_buildgraph elif use_engine: root_specs = EngineInitializer.parse_commandline_to_spec_roots( options=self._options, build_root=self._root_dir) graph_helper = EngineInitializer.setup_legacy_graph( path_ignore_patterns) return graph_helper.create_graph(root_specs) else: return MutableBuildGraph(self._address_mapper)
def _setup_legacy_graph_helper(native, bootstrap_options): """Initializes a `LegacyGraphHelper` instance.""" return EngineInitializer.setup_legacy_graph( bootstrap_options.pants_ignore, bootstrap_options.pants_workdir, bootstrap_options.build_file_imports, native=native, build_ignore_patterns=bootstrap_options.build_ignore, exclude_target_regexps=bootstrap_options.exclude_target_regexp, subproject_roots=bootstrap_options.subproject_roots, )
def open_scheduler(self, specs, symbol_table_cls=None): path_ignore_patterns = ['.*'] target_roots = TargetRoots.create(options=self._make_setup_args(specs)) graph_helper = EngineInitializer.setup_legacy_graph(path_ignore_patterns, symbol_table_cls=symbol_table_cls, native=self._native) try: graph = graph_helper.create_build_graph(target_roots)[0] addresses = tuple(graph.inject_specs_closure(target_roots.as_specs())) yield graph, addresses, graph_helper.scheduler finally: graph_helper.engine.close()
def _init_graph(self, pants_ignore_patterns, build_ignore_patterns, exclude_target_regexps, target_specs, target_roots, workdir, graph_helper, subproject_build_roots): """Determine the BuildGraph, AddressMapper and spec_roots for a given run. :param list pants_ignore_patterns: The pants ignore patterns from '--pants-ignore'. :param list build_ignore_patterns: The build ignore patterns from '--build-ignore', applied during BUILD file searching. :param str workdir: The pants workdir. :param list exclude_target_regexps: Regular expressions for targets to be excluded. :param list target_specs: The original target specs. :param TargetRoots target_roots: The existing `TargetRoots` object, if any. :param LegacyGraphHelper graph_helper: A LegacyGraphHelper to use for graph construction, if available. This would usually come from the daemon. :returns: A tuple of (BuildGraph, AddressMapper, opt Scheduler, TargetRoots). """ # The daemon may provide a `graph_helper`. If that's present, use it for graph construction. if not graph_helper: native = Native.create(self._global_options) native.set_panic_handler() graph_helper = EngineInitializer.setup_legacy_graph( pants_ignore_patterns, workdir, self._global_options.build_file_imports, native=native, build_file_aliases=self._build_config.registered_aliases(), rules=self._build_config.rules(), build_ignore_patterns=build_ignore_patterns, exclude_target_regexps=exclude_target_regexps, subproject_roots=subproject_build_roots, include_trace_on_error=self._options.for_global_scope().print_exception_stacktrace ) target_roots = target_roots or TargetRootsCalculator.create( options=self._options, build_root=self._root_dir, change_calculator=graph_helper.change_calculator ) graph, address_mapper = graph_helper.create_build_graph(target_roots, self._root_dir) return graph, address_mapper, graph_helper.scheduler, target_roots
def _init_graph(self, pants_ignore_patterns, build_ignore_patterns, exclude_target_regexps, target_specs, target_roots, workdir, graph_helper, subproject_build_roots): """Determine the BuildGraph, AddressMapper and spec_roots for a given run. :param list pants_ignore_patterns: The pants ignore patterns from '--pants-ignore'. :param list build_ignore_patterns: The build ignore patterns from '--build-ignore', applied during BUILD file searching. :param str workdir: The pants workdir. :param list exclude_target_regexps: Regular expressions for targets to be excluded. :param list target_specs: The original target specs. :param TargetRoots target_roots: The existing `TargetRoots` object, if any. :param LegacyGraphSession graph_helper: A LegacyGraphSession to use for graph construction, if available. This would usually come from the daemon. :returns: A tuple of (BuildGraph, AddressMapper, SchedulerSession, TargetRoots). """ # The daemon may provide a `graph_helper`. If that's present, use it for graph construction. if not graph_helper: native = Native.create(self._global_options) native.set_panic_handler() graph_helper = EngineInitializer.setup_legacy_graph( pants_ignore_patterns, workdir, self._global_options.build_file_imports, native=native, build_file_aliases=self._build_config.registered_aliases(), rules=self._build_config.rules(), build_ignore_patterns=build_ignore_patterns, exclude_target_regexps=exclude_target_regexps, subproject_roots=subproject_build_roots, include_trace_on_error=self._options.for_global_scope( ).print_exception_stacktrace).new_session() target_roots = target_roots or TargetRootsCalculator.create( options=self._options, build_root=self._root_dir, change_calculator=graph_helper.change_calculator) graph, address_mapper = graph_helper.create_build_graph( target_roots, self._root_dir) return graph, address_mapper, graph_helper.scheduler_session, target_roots
def open_legacy_graph(options=None, path_ignore_patterns=None, symbol_table_cls=None): """A context manager that yields a usable, legacy LegacyBuildGraph by way of the v2 scheduler. :param Options options: An Options object to use for this run. :param list path_ignore_patterns: A list of path ignore patterns for FileSystemProjectTree, usually taken from the `--pants-ignore` global option. Defaults to: ['.*'] :param SymbolTable symbol_table_cls: A SymbolTable class to use for build file parsing, or None to use the default. :yields: A tuple of (graph, addresses, scheduler). """ path_ignore_patterns = path_ignore_patterns or ['.*'] target_roots = TargetRoots.create(options=options) graph_helper = EngineInitializer.setup_legacy_graph( path_ignore_patterns, symbol_table_cls=symbol_table_cls) try: graph = graph_helper.create_build_graph(target_roots)[0] addresses = tuple(graph.inject_specs_closure(target_roots.as_specs())) yield graph, addresses, graph_helper.scheduler finally: graph_helper.engine.close()
def create_address_mapper(self, build_root): scheduler, engine, _, _ = EngineInitializer.setup_legacy_graph([], build_root=build_root, native=self._native) return LegacyAddressMapper(scheduler, engine, build_root)
def create_address_mapper(self, build_root): work_dir = os.path.join(build_root, '.pants.d') scheduler, engine, _, _ = EngineInitializer.setup_legacy_graph( [], work_dir, build_root=build_root, native=self._native) return LegacyAddressMapper(scheduler, engine, build_root)
def open_scheduler(self, specs, symbol_table_cls=None): kwargs = self._make_setup_args(specs, symbol_table_cls=symbol_table_cls) with EngineInitializer.open_legacy_graph(**kwargs) as triple: yield triple