def run(self): global_options = self.options.for_global_scope() exiter = LocalExiter.wrap_global_exiter(self._run_tracker, self._repro) profiled = maybe_profiled(self.profile_path) with exiter, profiled: streaming_handlers = global_options.streaming_workunits_handlers report_interval = global_options.streaming_workunits_report_interval callbacks = Subsystem.get_streaming_workunit_callbacks( streaming_handlers) streaming_reporter = StreamingWorkunitHandler( self.graph_session.scheduler_session, callbacks=callbacks, report_interval_seconds=report_interval, ) if self.options.help_request: help_printer = HelpPrinter( options=self.options, union_membership=self.union_membership) help_output = help_printer.print_help() self._exiter.exit(help_output) v1 = global_options.v1 v2 = global_options.v2 with streaming_reporter.session(): try: engine_result = self._maybe_run_v2(v2) goal_runner_result = self._maybe_run_v1(v1) finally: run_tracker_result = self._finish_run() final_exit_code = self._compute_final_exit_code( engine_result, goal_runner_result, run_tracker_result) self._exiter.exit(final_exit_code)
def _maybe_handle_help(self): """Handle requests for `help` information.""" if self._options.help_request: help_printer = HelpPrinter(options=self._options, union_membership=self._union_membership) result = help_printer.print_help() return result
def _expand_goals_and_specs(self): goals = self.options.goals specs = self.options.target_specs fail_fast = self.options.for_global_scope().fail_fast for goal in goals: if self.address_mapper.from_cache(get_buildroot(), goal, must_exist=False).file_exists(): logger.warning(" Command-line argument '{0}' is ambiguous and was assumed to be " "a goal. If this is incorrect, disambiguate it with ./{0}.".format(goal)) if self.options.help_request: help_printer = HelpPrinter(self.options) help_printer.print_help() self._exiter(0) self.requested_goals = goals with self.run_tracker.new_workunit(name='setup', labels=[WorkUnitLabel.SETUP]): spec_parser = CmdLineSpecParser(self.root_dir, self.address_mapper, spec_excludes=self.spec_excludes, exclude_target_regexps=self.global_options.exclude_target_regexp) with self.run_tracker.new_workunit(name='parse', labels=[WorkUnitLabel.SETUP]): def filter_for_tag(tag): return lambda target: tag in map(str, target.tags) tag_filter = wrap_filters(create_filters(self.global_options.tag, filter_for_tag)) for spec in specs: for address in spec_parser.parse_addresses(spec, fail_fast): self.build_graph.inject_address_closure(address) tgt = self.build_graph.get_target(address) if tag_filter(tgt): self.targets.append(tgt) self.goals = [Goal.by_name(goal) for goal in goals]
def run(self, start_time: float) -> ExitCode: self._set_start_time(start_time) with maybe_profiled(self.profile_path): global_options = self.options.for_global_scope() streaming_handlers = global_options.streaming_workunits_handlers report_interval = global_options.streaming_workunits_report_interval callbacks = Subsystem.get_streaming_workunit_callbacks( streaming_handlers) streaming_reporter = StreamingWorkunitHandler( self.graph_session.scheduler_session, callbacks=callbacks, report_interval_seconds=report_interval, ) if self.options.help_request: help_printer = HelpPrinter( options=self.options, union_membership=self.union_membership) return help_printer.print_help() v1 = global_options.v1 v2 = global_options.v2 with streaming_reporter.session(): engine_result, goal_runner_result = PANTS_FAILED_EXIT_CODE, PANTS_FAILED_EXIT_CODE try: engine_result = self._maybe_run_v2(v2) goal_runner_result = self._maybe_run_v1(v1) except Exception as e: ExceptionSink.log_exception(e) run_tracker_result = self._finish_run( self._merge_exit_codes(engine_result, goal_runner_result)) return self._merge_exit_codes(engine_result, goal_runner_result, run_tracker_result)
def _expand_goals(self, goals): """Check and populate the requested goals for a given run.""" for goal in goals: if self._address_mapper.from_cache(self._root_dir, goal, must_exist=False).file_exists(): logger.warning("Command-line argument '{0}' is ambiguous and was assumed to be " "a goal. If this is incorrect, disambiguate it with ./{0}.".format(goal)) if self._help_request: help_printer = HelpPrinter(self._options) help_printer.print_help() self._exiter(0) self._goals.extend([Goal.by_name(goal) for goal in goals])
def _print_help(self, request: HelpRequest) -> ExitCode: global_options = self.options.for_global_scope() all_help_info = HelpInfoExtracter.get_all_help_info( self.options, self.union_membership, self.graph_session.goal_consumed_subsystem_scopes, ) help_printer = HelpPrinter( bin_name=global_options.pants_bin_name, help_request=request, all_help_info=all_help_info, color=global_options.colors, ) return help_printer.print_help()
def _maybe_run_v1(self): v1_goals, ambiguous_goals, _ = self._options.goals_by_version if not self._global_options.v1: if v1_goals: HelpPrinter(self._options, UnknownGoalHelp(v1_goals)).print_help() return PANTS_FAILED_EXIT_CODE return PANTS_SUCCEEDED_EXIT_CODE if not v1_goals and not ambiguous_goals: return PANTS_SUCCEEDED_EXIT_CODE # Setup and run GoalRunner. goal_runner_factory = GoalRunner.Factory( self._build_root, self._options, self._build_config, self._run_tracker, self._reporting, self._graph_session, self._target_roots, self._exiter ) if self._options.help_request: return goal_runner_factory.handle_help() return goal_runner_factory.create().run()
def _expand_goals(self, goals): """Check and populate the requested goals for a given run.""" for goal in goals: try: self._address_mapper.resolve_spec(goal) logger.warning("Command-line argument '{0}' is ambiguous and was assumed to be " "a goal. If this is incorrect, disambiguate it with ./{0}.".format(goal)) except AddressLookupError: pass if self._help_request: help_printer = HelpPrinter(self._options) result = help_printer.print_help() self._exiter(result) self._goals.extend([Goal.by_name(goal) for goal in goals])
def _maybe_run_v1(self, v1: bool) -> int: v1_goals, ambiguous_goals, _ = self.options.goals_by_version if not v1: if v1_goals: HelpPrinter( options=self.options, help_request=UnknownGoalHelp(list(v1_goals)), union_membership=self.union_membership, ).print_help() return PANTS_FAILED_EXIT_CODE return PANTS_SUCCEEDED_EXIT_CODE if not v1_goals and not ambiguous_goals: return PANTS_SUCCEEDED_EXIT_CODE # Setup and run GoalRunner. return (GoalRunner.Factory( self.build_root, self.options_bootstrapper, self.options, self.build_config, self._run_tracker, # type: ignore self._reporting, # type: ignore self.graph_session, self.specs, self._exiter, ).create().run())
def run( self, build_config: BuildConfiguration, graph_session: GraphSession, options: Options, specs: Specs, union_membership: UnionMembership, ) -> ExitCode: all_help_info = HelpInfoExtracter.get_all_help_info( options, union_membership, graph_session.goal_consumed_subsystem_scopes, RegisteredTargetTypes.create(build_config.target_types), build_config, ) global_options = options.for_global_scope() help_printer = HelpPrinter( help_request=self.create_help_request(options), all_help_info=all_help_info, color=global_options.colors, ) return help_printer.print_help()
def run(self, start_time: float) -> ExitCode: self._set_start_time(start_time) with maybe_profiled(self.profile_path): global_options = self.options.for_global_scope() streaming_handlers = global_options.streaming_workunits_handlers report_interval = global_options.streaming_workunits_report_interval callbacks = Subsystem.get_streaming_workunit_callbacks( streaming_handlers) streaming_reporter = StreamingWorkunitHandler( self.graph_session.scheduler_session, callbacks=callbacks, report_interval_seconds=report_interval, ) if self.options.help_request: all_help_info = HelpInfoExtracter.get_all_help_info( self.options, self.union_membership, self.graph_session.goal_consumed_subsystem_scopes, ) help_printer = HelpPrinter( bin_name=global_options.pants_bin_name, help_request=self.options.help_request, all_help_info=all_help_info, use_color=global_options.colors, ) return help_printer.print_help() with streaming_reporter.session(): engine_result = PANTS_FAILED_EXIT_CODE try: engine_result = self._run_v2() except Exception as e: ExceptionSink.log_exception(e) run_tracker_result = self._finish_run(engine_result) return self._merge_exit_codes(engine_result, run_tracker_result)
def _maybe_run_v1(self): v1_goals, ambiguous_goals, _ = self._options.goals_by_version if not self._global_options.v1: if v1_goals: HelpPrinter( options=self._options, help_request=UnknownGoalHelp(v1_goals), union_membership=self._union_membership, ).print_help() return PANTS_FAILED_EXIT_CODE return PANTS_SUCCEEDED_EXIT_CODE if not v1_goals and not ambiguous_goals: return PANTS_SUCCEEDED_EXIT_CODE # Setup and run GoalRunner. return GoalRunner.Factory(self._build_root, self._options_bootstrapper, self._options, self._build_config, self._run_tracker, self._reporting, self._graph_session, self._specs, self._exiter).create().run()
def _handle_help(self, help_request): """Handle requests for `help` information.""" if help_request: help_printer = HelpPrinter(self._options) result = help_printer.print_help() self._exiter(result)
def _maybe_handle_help(self): """Handle requests for `help` information.""" if self._options.help_request: help_printer = HelpPrinter(self._options) result = help_printer.print_help() return result
def handle_help(self): """Handle requests for `help` information.""" help_printer = HelpPrinter(self._options) return help_printer.print_help()
def run(self): # Ensure anything referencing sys.argv inherits the Pailgun'd args. sys.argv = self.args # Invoke a Pants run with stdio redirected and a proxied environment. with self.nailgunned_stdio( self.maybe_shutdown_socket, self.env) as finalizer, DaemonExiter.override_global_exiter( self.maybe_shutdown_socket, finalizer), hermetic_environment_as(**self.env): exit_code = PANTS_SUCCEEDED_EXIT_CODE try: # Clean global state. clean_global_runtime_state(reset_subsystem=True) options_bootstrapper = OptionsBootstrapper.create( args=self.args, env=self.env) options, build_config = LocalPantsRunner.parse_options( options_bootstrapper) global_options = options.for_global_scope() session = self.scheduler_service.prepare_graph(options) specs = SpecsCalculator.create( options=options, session=session.scheduler_session, exclude_patterns=tuple( global_options.exclude_target_regexp), tags=tuple(global_options.tag) if global_options.tag else (), ) if options.help_request: help_printer = HelpPrinter( options=options, union_membership=UnionMembership( build_config.union_rules()), ) exit_code = help_printer.print_help() else: exit_code = self.scheduler_service.graph_run_v2( session, specs, options, options_bootstrapper) # self.scheduler_service.graph_run_v2 will already run v2 or ambiguous goals. We should # only enter this code path if v1 is set. if global_options.v1: with ExceptionSink.exiter_as_until_exception( lambda _: PantsRunFailCheckerExiter()): runner = LocalPantsRunner.create( self.env, options_bootstrapper, specs, session) env_start_time = self.env.pop( "PANTSD_RUNTRACKER_CLIENT_START_TIME", None) start_time = float( env_start_time) if env_start_time else None runner.set_start_time(start_time) runner.run() except KeyboardInterrupt: self._exiter.exit_and_fail("Interrupted by user.\n") except _PantsRunFinishedWithFailureException as e: ExceptionSink.log_exception( "Pants run failed with exception: {}; exiting".format(e)) self._exiter.exit(e.exit_code) except Exception as e: # TODO: We override sys.excepthook above when we call ExceptionSink.set_exiter(). That # excepthook catches `SignalHandledNonLocalExit`s from signal handlers, which isn't # happening here, so something is probably overriding the excepthook. By catching Exception # and calling this method, we emulate the normal, expected sys.excepthook override. ExceptionSink._log_unhandled_exception_and_exit(exc=e) else: self._exiter.exit(exit_code)