def context(self, for_task_types=None, for_subsystems=None, options=None, target_roots=None, console_outstream=None, workspace=None, **kwargs): """ :API: public :param dict **kwargs: keyword arguments passed in to `create_options_for_optionables`. """ # Many tests use source root functionality via the SourceRootConfig.global_instance(). # (typically accessed via Target.target_base), so we always set it up, for convenience. optionables = {SourceRootConfig} extra_scopes = set() for_subsystems = for_subsystems or () for subsystem in for_subsystems: if subsystem.options_scope is None: raise TaskError('You must set a scope on your subsystem type before using it in tests.') optionables.add(subsystem) for_task_types = for_task_types or () for task_type in for_task_types: scope = task_type.options_scope if scope is None: raise TaskError('You must set a scope on your task type before using it in tests.') optionables.add(task_type) # If task is expected to inherit goal-level options, register those directly on the task, # by subclassing the goal options registrar and settings its scope to the task scope. if issubclass(task_type, GoalOptionsMixin): subclass_name = b'test_{}_{}_{}'.format( task_type.__name__, task_type.goal_options_registrar_cls.options_scope, task_type.options_scope) optionables.add(type(subclass_name, (task_type.goal_options_registrar_cls, ), {b'options_scope': task_type.options_scope})) extra_scopes.update([si.scope for si in task_type.known_scope_infos()]) optionables.update(Subsystem.closure( set([dep.subsystem_cls for dep in task_type.subsystem_dependencies_iter()]) | self._build_configuration.subsystems())) # Now default the option values and override with any caller-specified values. # TODO(benjy): Get rid of the options arg, and require tests to call set_options. options = options.copy() if options else {} for s, opts in self.options.items(): scoped_opts = options.setdefault(s, {}) scoped_opts.update(opts) fake_options = create_options_for_optionables( optionables, extra_scopes=extra_scopes, options=options, **kwargs) Subsystem.reset(reset_options=True) Subsystem.set_options(fake_options) context = create_context_from_options(fake_options, target_roots=target_roots, build_graph=self.build_graph, build_file_parser=self.build_file_parser, address_mapper=self.address_mapper, console_outstream=console_outstream, workspace=workspace) return context
def context(self, for_task_types=None, options=None, passthru_args=None, target_roots=None, console_outstream=None, workspace=None, for_subsystems=None): """ :API: public """ # Many tests use source root functionality via the SourceRootConfig.global_instance(). # (typically accessed via Target.target_base), so we always set it up, for convenience. optionables = {SourceRootConfig} extra_scopes = set() for_subsystems = for_subsystems or () for subsystem in for_subsystems: if subsystem.options_scope is None: raise TaskError('You must set a scope on your subsystem type before using it in tests.') optionables.add(subsystem) for_task_types = for_task_types or () for task_type in for_task_types: scope = task_type.options_scope if scope is None: raise TaskError('You must set a scope on your task type before using it in tests.') optionables.add(task_type) extra_scopes.update([si.scope for si in task_type.known_scope_infos()]) optionables.update(Subsystem.closure( set([dep.subsystem_cls for dep in task_type.subsystem_dependencies_iter()]) | self._build_configuration.subsystems())) # Now default the option values and override with any caller-specified values. # TODO(benjy): Get rid of the options arg, and require tests to call set_options. options = options.copy() if options else {} for s, opts in self.options.items(): scoped_opts = options.setdefault(s, {}) scoped_opts.update(opts) options = create_options_for_optionables(optionables, extra_scopes=extra_scopes, options=options, passthru_args=passthru_args) Subsystem.reset(reset_options=True) Subsystem.set_options(options) context = create_context_from_options(options, target_roots=target_roots, build_graph=self.build_graph, build_file_parser=self.build_file_parser, address_mapper=self.address_mapper, console_outstream=console_outstream, workspace=workspace) return context
def context(self, for_task_types=None, for_subsystems=None, options=None, target_roots=None, console_outstream=None, workspace=None, scheduler=None, **kwargs): """ :API: public :param dict **kwargs: keyword arguments passed in to `create_options_for_optionables`. """ # Many tests use source root functionality via the SourceRootConfig.global_instance(). # (typically accessed via Target.target_base), so we always set it up, for convenience. for_subsystems = set(for_subsystems or ()) for subsystem in for_subsystems: if subsystem.options_scope is None: raise TaskError('You must set a scope on your subsystem type before using it in tests.') optionables = {SourceRootConfig} | self._build_configuration.subsystems() | for_subsystems for_task_types = for_task_types or () for task_type in for_task_types: scope = task_type.options_scope if scope is None: raise TaskError('You must set a scope on your task type before using it in tests.') optionables.add(task_type) # If task is expected to inherit goal-level options, register those directly on the task, # by subclassing the goal options registrar and settings its scope to the task scope. if issubclass(task_type, GoalOptionsMixin): subclass_name = 'test_{}_{}_{}'.format( task_type.__name__, task_type.goal_options_registrar_cls.options_scope, task_type.options_scope) if PY2: subclass_name = subclass_name.encode('utf-8') optionables.add(type(subclass_name, (task_type.goal_options_registrar_cls, ), {'options_scope': task_type.options_scope})) # Now expand to all deps. all_optionables = set() for optionable in optionables: all_optionables.update(si.optionable_cls for si in optionable.known_scope_infos()) # Now default the option values and override with any caller-specified values. # TODO(benjy): Get rid of the options arg, and require tests to call set_options. options = options.copy() if options else {} for s, opts in self.options.items(): scoped_opts = options.setdefault(s, {}) scoped_opts.update(opts) fake_options = create_options_for_optionables( all_optionables, options=options, **kwargs) Subsystem.reset(reset_options=True) Subsystem.set_options(fake_options) context = create_context_from_options(fake_options, target_roots=target_roots, build_graph=self.build_graph, build_file_parser=self.build_file_parser, address_mapper=self.address_mapper, console_outstream=console_outstream, workspace=workspace, scheduler=scheduler) return context
def context(self, for_task_types=None, for_subsystems=None, options=None, target_roots=None, console_outstream=None, workspace=None, **kwargs): """ :API: public :param dict **kwargs: keyword arguments passed in to `create_options_for_optionables`. """ # Many tests use source root functionality via the SourceRootConfig.global_instance(). # (typically accessed via Target.target_base), so we always set it up, for convenience. optionables = {SourceRootConfig} extra_scopes = set() for_subsystems = for_subsystems or () for subsystem in for_subsystems: if subsystem.options_scope is None: raise TaskError( 'You must set a scope on your subsystem type before using it in tests.' ) optionables.add(subsystem) for_task_types = for_task_types or () for task_type in for_task_types: scope = task_type.options_scope if scope is None: raise TaskError( 'You must set a scope on your task type before using it in tests.' ) optionables.add(task_type) extra_scopes.update( [si.scope for si in task_type.known_scope_infos()]) optionables.update( Subsystem.closure( set([ dep.subsystem_cls for dep in task_type.subsystem_dependencies_iter() ]) | self._build_configuration.subsystems())) # Now default the option values and override with any caller-specified values. # TODO(benjy): Get rid of the options arg, and require tests to call set_options. options = options.copy() if options else {} for s, opts in self.options.items(): scoped_opts = options.setdefault(s, {}) scoped_opts.update(opts) options = create_options_for_optionables(optionables, extra_scopes=extra_scopes, options=options, **kwargs) Subsystem.reset(reset_options=True) Subsystem.set_options(options) context = create_context_from_options( options, target_roots=target_roots, build_graph=self.build_graph, build_file_parser=self.build_file_parser, address_mapper=self.address_mapper, console_outstream=console_outstream, workspace=workspace) return context