Ejemplo n.º 1
0
 def test_gen_tasks_goals_reference_data(self):
     # can we run our reflection-y goal code without crashing? would be nice
     Goal.by_name('jack').install(TaskRegistrar('jill', lambda: 42))
     gref_data = builddictionary.gen_tasks_goals_reference_data()
     self.assertTrue(
         len(gref_data) > 0,
         'Tried to generate data for goals reference, got emptiness')
Ejemplo n.º 2
0
def register_goals():
    task(name='mypy', action=MypyTask).install('mypy')
    task(name='futurize', action=FuturizeTask).install('futurize')
    Goal.by_name('test').uninstall_task('pytest-prep')
    task(name='pytest-prep', action=PytestPrep).install('test')
    Goal.by_name('test').uninstall_task('pytest')
    task(name='pytest', action=PytestRun).install('test')
Ejemplo n.º 3
0
def register_goals():
    Goal.register('webpack', 'Build Node.js webpack modules.')

    # These are incompatible with our subclasses at the moment.
    Goal.by_name('test').uninstall_task('node')
    Goal.by_name('resolve').uninstall_task('node')

    # Install our webpack-focused node tasks.
    task(name='webpack-resolve', action=WebPackResolve).install('webpack')
    task(name='webpack-gen', action=WebPack).install('webpack')
    task(name='webpack-bundle', action=WebPackBundle).install('bundle')
    task(name='webpack', action=WebPackTestRun).install('test')
Ejemplo n.º 4
0
def register_goals():
  Goal.by_name('idea').uninstall_task('idea')
  Goal.register('old-idea',
    'The old, deprecated task to generate an IntelliJ project (this is the task used in '
    'open-source pants).')
  Goal.register('idea', 
    'Generates an IntelliJ project for the specified targets and transitive dependencies. This is '
    'Square\'s internal version of the idea goal, implemented as a plugin.')
  Goal.register('new-idea', 'This has been renamed to just "idea".')

  task(name='old-idea', action=IdeaGen).install('old-idea')
  task(name='idea', action=SquareIdea).install('idea')
  task(name='new-idea', action=ShowNewIdeaMovedMessage).install('new-idea')
Ejemplo n.º 5
0
  def DISABLED_test_gen_tasks_options_reference_data(self):
    # TODO(Eric Ayers) Not really part of the test, just to detect the cache poisoning
    before_support_dir = Config.from_cache().getdefault('pants_supportdir')

    # can we run our reflection-y goal code without crashing? would be nice
    Goal.by_name('jack').install(TaskRegistrar('jill', DummyTask))
    oref_data = reflect.gen_tasks_options_reference_data()

    # TODO(Eric Ayers) Not really part of the test, just to detect the cache poisoning
    after_support_dir = Config.from_cache().getdefault('pants_supportdir')
    self.assertEquals(before_support_dir, after_support_dir)

    self.assertTrue(len(oref_data) > 0,
                    'Tried to generate data for options reference, got emptiness')
Ejemplo n.º 6
0
  def test_plugin_installs_goal(self):
    def reg_goal():
      Goal.by_name('plugindemo').install(TaskRegistrar('foo', DummyTask))
    self.working_set.add(self.get_mock_plugin('regdemo', '0.0.1', reg=reg_goal))

    # Start without the custom goal.
    self.assertEqual(0, len(Goal.by_name('plugindemo').ordered_task_names()))

    # Load plugin which registers custom goal.
    self.load_plugins(['regdemo'])

    # Now the custom goal exists.
    self.assertEqual(1, len(Goal.by_name('plugindemo').ordered_task_names()))
    self.assertEqual('foo', Goal.by_name('plugindemo').ordered_task_names()[0])
Ejemplo n.º 7
0
  def test_plugin_installs_goal(self):
    def reg_goal():
      Goal.by_name('plugindemo').install(TaskRegistrar('foo', DummyTask))
    self.working_set.add(self.get_mock_plugin('regdemo', '0.0.1', reg=reg_goal))

    # Start without the custom goal.
    self.assertEqual(0, len(Goal.by_name('plugindemo').ordered_task_names()))

    # Load plugin which registers custom goal.
    self.load_plugins(['regdemo'])

    # Now the custom goal exists.
    self.assertEqual(1, len(Goal.by_name('plugindemo').ordered_task_names()))
    self.assertEqual('foo', Goal.by_name('plugindemo').ordered_task_names()[0])
Ejemplo n.º 8
0
    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 BuildFile.from_cache(get_buildroot(), goal,
                                    must_exist=False).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.print_help_if_requested():
            sys.exit(0)

        self.requested_goals = goals

        with self.run_tracker.new_workunit(name='setup',
                                           labels=[WorkUnit.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=[WorkUnit.SETUP]):
                for spec in specs:
                    for address in spec_parser.parse_addresses(
                            spec, fail_fast):
                        self.build_graph.inject_address_closure(address)
                        self.targets.append(
                            self.build_graph.get_target(address))
        self.goals = [Goal.by_name(goal) for goal in goals]
Ejemplo n.º 9
0
  def _gen_reference(self):
    def get_scope_data(scope):
      ret = []
      for si in ScopeInfoIterator(self.context.options.known_scope_to_info).iterate([scope]):
        help_info = HelpInfoExtracter(si.scope).get_option_scope_help_info_from_parser(
          self.context.options.get_parser(si.scope))
        ret.append({
          # We don't use _asdict(), because then .description wouldn't be available.
          'scope_info': si,
          # We do use _asdict() here, so our mustache library can do property expansion.
          'help_info': help_info._asdict(),
        })
      return ret

    all_global_data = get_scope_data(GLOBAL_SCOPE)
    global_scope_data = all_global_data[0:1]
    global_subsystem_data = all_global_data[1:]

    goal_scopes = sorted([si.scope for si in self.context.options.known_scope_to_info.values()
    if si.scope and '.' not in si.scope and si.category != ScopeInfo.SUBSYSTEM])
    # TODO: Make goals Optionable and get their description via their ScopeInfo?
    goal_data = []
    for scope in goal_scopes:
      goal_data.append({
        'goal': scope,
        'goal_description': Goal.by_name(scope).description,
        'task_data': get_scope_data(scope)[1:]
      })

    ref_page = self._do_render(self.get_options().pants_reference_template, {
      'global_scope_data': global_scope_data,
      'global_subsystem_data': global_subsystem_data,
      'goal_data': goal_data
    })
    self.context.products.register_data(self.PANTS_REFERENCE_PRODUCT, ref_page)
Ejemplo n.º 10
0
  def _print_help(self):
    """Print a help screen, followed by an optional message.

    Note: Ony useful if called after options have been registered.
    """
    show_all_help = self._help_request and self._help_request.all_scopes
    goals = (Goal.all() if show_all_help else [Goal.by_name(goal_name) for goal_name in self.goals])
    if goals:
      for goal in goals:
        if not goal.ordered_task_names():
          print('\nUnknown goal: {}'.format(goal.name))
        else:
          print('\n{0}: {1}\n'.format(goal.name, goal.description))
          for scope_info in goal.known_scope_infos():
            help_str = self._format_help_for_scope(scope_info.scope)
            if help_str:
              print(help_str)
    else:
      print(pants_release())
      print('\nUsage:')
      print('  ./pants [option ...] [goal ...] [target...]  Attempt the specified goals.')
      print('  ./pants help                                 Get help.')
      print('  ./pants help [goal]                          Get help for a goal.')
      print('  ./pants help-advanced [goal]                 Get help for a goal\'s advanced options.')
      print('  ./pants help-all                             Get help for all goals.')
      print('  ./pants goals                                List all installed goals.')
      print('')
      print('  [target] accepts two special forms:')
      print('    dir:  to include all targets in the specified directory.')
      print('    dir:: to include all targets found recursively under the directory.')
      print('\nFriendly docs:\n  http://pantsbuild.github.io/')

    if show_all_help or not goals:
      print(self.get_parser(GLOBAL_SCOPE).format_help('Global', self._help_request.advanced))
Ejemplo n.º 11
0
def print_help(goals=None):
    if goals:
        for goal in goals:
            goal = Goal.by_name(goal)
            if not goal.ordered_task_names():
                print('\nUnknown goal: %s' % goal)
            else:
                parser = OptionParser(add_help_option=False)
                Goal.setup_parser(parser, [], [goal])
                print('\n%s: %s' % (goal.name, goal.description))
                _print_flags(parser, goal.name)
    else:
        print(pants_release())
        print('\nUsage:')
        print(
            '  ./pants goal [option ...] [goal ...] [target...]  Attempt the specified goals.'
        )
        print('  ./pants goal help                                 Get help.')
        print(
            '  ./pants goal help [goal]                          Get help for the specified goal.'
        )
        print(
            '  ./pants goal goals                                List all installed goals.'
        )
        print('')
        print('  [target] accepts two special forms:')
        print('    dir:  to include all targets in the specified directory.')
        print(
            '    dir:: to include all targets found recursively under the directory.'
        )

        print('\nFriendly docs:\n  http://pantsbuild.github.io/')

        _print_global_flags()
Ejemplo n.º 12
0
  def _gen_reference(self):
    def get_scope_data(scope):
      ret = []
      for si in ScopeInfoIterator(self.context.options.known_scope_to_info).iterate([scope]):
        help_info = HelpInfoExtracter(si.scope).get_option_scope_help_info_from_parser(
          self.context.options.get_parser(si.scope))
        ret.append({
          # We don't use _asdict(), because then .description wouldn't be available.
          'scope_info': si,
          # We do use _asdict() here, so our mustache library can do property expansion.
          'help_info': help_info._asdict(),
        })
      return ret

    all_global_data = get_scope_data(GLOBAL_SCOPE)
    global_scope_data = all_global_data[0:1]
    global_subsystem_data = all_global_data[1:]

    goal_scopes = sorted([si.scope for si in self.context.options.known_scope_to_info.values()
    if si.scope and '.' not in si.scope and si.category != ScopeInfo.SUBSYSTEM])
    # TODO: Make goals Optionable and get their description via their ScopeInfo?
    goal_data = []
    for scope in goal_scopes:
      goal_data.append({
        'goal': scope,
        'goal_description': Goal.by_name(scope).description,
        'task_data': get_scope_data(scope)[1:]
      })

    ref_page = self._do_render(self.get_options().pants_reference_template, {
      'global_scope_data': global_scope_data,
      'global_subsystem_data': global_subsystem_data,
      'goal_data': goal_data
    })
    self.context.products.register_data(self.PANTS_REFERENCE_PRODUCT, ref_page)
Ejemplo n.º 13
0
def print_help(goals=None):
  if goals:
    for goal in goals:
      goal = Goal.by_name(goal)
      if not goal.ordered_task_names():
        print('\nUnknown goal: %s' % goal)
      else:
        parser = OptionParser(add_help_option=False)
        Goal.setup_parser(parser, [], [goal])
        print('\n%s: %s' % (goal.name, goal.description))
        _print_flags(parser, goal.name)
  else:
    print(pants_release())
    print('\nUsage:')
    print('  ./pants goal [option ...] [goal ...] [target...]  Attempt the specified goals.')
    print('  ./pants goal help                                 Get help.')
    print('  ./pants goal help [goal]                          Get help for the specified goal.')
    print('  ./pants goal goals                                List all installed goals.')
    print('')
    print('  [target] accepts two special forms:')
    print('    dir:  to include all targets in the specified directory.')
    print('    dir:: to include all targets found recursively under the directory.')

    print('\nFriendly docs:\n  http://pantsbuild.github.io/')

    _print_global_flags()
Ejemplo n.º 14
0
    def test_load_valid_partial_goals(self):
        def register_goals():
            Goal.by_name("jack").install(TaskRegistrar("jill", DummyTask))

        with self.create_register(
                register_goals=register_goals) as backend_package:
            Goal.clear()
            self.assertEqual(0, len(Goal.all()))

            load_backend(self.build_configuration,
                         backend_package,
                         is_v1_backend=False)
            self.assertEqual(0, len(Goal.all()))

            load_backend(self.build_configuration,
                         backend_package,
                         is_v1_backend=True)
            self.assert_empty_aliases()
            self.assertEqual(1, len(Goal.all()))

            task_names = Goal.by_name("jack").ordered_task_names()
            self.assertEqual(1, len(task_names))

            task_name = task_names[0]
            self.assertEqual("jill", task_name)
Ejemplo n.º 15
0
  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]
Ejemplo n.º 16
0
  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 BuildFile.from_cache(get_buildroot(), goal, must_exist=False).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.print_help_if_requested():
      sys.exit(0)

    self.requested_goals = goals

    with self.run_tracker.new_workunit(name='setup', labels=[WorkUnit.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=[WorkUnit.SETUP]):
        for spec in specs:
          for address in spec_parser.parse_addresses(spec, fail_fast):
            self.build_graph.inject_address_closure(address)
            self.targets.append(self.build_graph.get_target(address))
    self.goals = [Goal.by_name(goal) for goal in goals]
Ejemplo n.º 17
0
  def _print_help(self):
    """Print a help screen, followed by an optional message.

    Note: Ony useful if called after options have been registered.
    """
    show_all_help = self._help_request and self._help_request.all_scopes
    goals = (Goal.all() if show_all_help else [Goal.by_name(goal_name) for goal_name in self.goals])
    if goals:
      for goal in goals:
        if not goal.ordered_task_names():
          print('\nUnknown goal: {}'.format(goal.name))
        else:
          print('\n{0}: {1}\n'.format(goal.name, goal.description))
          for scope_info in goal.known_scope_infos():
            help_str = self._format_help_for_scope(scope_info.scope)
            if help_str:
              print(help_str)
    else:
      print(pants_release())
      print('\nUsage:')
      print('  ./pants [option ...] [goal ...] [target...]  Attempt the specified goals.')
      print('  ./pants help                                 Get help.')
      print('  ./pants help [goal]                          Get help for a goal.')
      print('  ./pants help-advanced [goal]                 Get help for a goal\'s advanced options.')
      print('  ./pants help-all                             Get help for all goals.')
      print('  ./pants goals                                List all installed goals.')
      print('')
      print('  [target] accepts two special forms:')
      print('    dir:  to include all targets in the specified directory.')
      print('    dir:: to include all targets found recursively under the directory.')
      print('\nFriendly docs:\n  http://pantsbuild.github.io/')

    if show_all_help or not goals:
      print(self.get_parser(GLOBAL_SCOPE).format_help('Global', self._help_request.advanced))
Ejemplo n.º 18
0
  def setup_parser(self, parser, args):
    if not args:
      args.append('help')

    logger = logging.getLogger(__name__)

    goals = self.new_options.goals
    specs = self.new_options.target_specs
    fail_fast = self.new_options.for_global_scope().fail_fast

    for goal in goals:
      if BuildFile.from_cache(get_buildroot(), goal, must_exist=False).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.new_options.is_help:
      self.new_options.print_help(goals=goals)
      sys.exit(0)

    self.requested_goals = goals

    with self.run_tracker.new_workunit(name='setup', labels=[WorkUnit.SETUP]):
      spec_parser = CmdLineSpecParser(self.root_dir, self.address_mapper,
                                      spec_excludes=self.get_spec_excludes())
      with self.run_tracker.new_workunit(name='parse', labels=[WorkUnit.SETUP]):
        for spec in specs:
          for address in spec_parser.parse_addresses(spec, fail_fast):
            self.build_graph.inject_address_closure(address)
            self.targets.append(self.build_graph.get_target(address))
    self.goals = [Goal.by_name(goal) for goal in goals]

    rcfiles = self.config.getdefault('rcfiles', type=list,
                                     default=['/etc/pantsrc', '~/.pants.rc'])
    if rcfiles:
      rcfile = RcFile(rcfiles, default_prepend=False, process_default=True)

      # Break down the goals specified on the command line to the full set that will be run so we
      # can apply default flags to inner goal nodes.  Also break down goals by Task subclass and
      # register the task class hierarchy fully qualified names so we can apply defaults to
      # baseclasses.

      sections = OrderedSet()
      for goal in Engine.execution_order(self.goals):
        for task_name in goal.ordered_task_names():
          sections.add(task_name)
          task_type = goal.task_type_by_name(task_name)
          for clazz in task_type.mro():
            if clazz == Task:
              break
            sections.add('%s.%s' % (clazz.__module__, clazz.__name__))

      augmented_args = rcfile.apply_defaults(sections, args)
      if augmented_args != args:
        # TODO(John Sirois): Cleanup this currently important mutation of the passed in args
        # once the 2-layer of command -> goal is squashed into one.
        args[:] = augmented_args
        sys.stderr.write("(using pantsrc expansion: pants goal %s)\n" % ' '.join(augmented_args))
Ejemplo n.º 19
0
def register_goals():
    # Some legacy libraries have broken javadoc - but the javadoc product is required by pom-publish and publish.jar.
    # This mocks that product and sidesteps the javadoc generation completely. The real fix is to require working
    # javadoc for any published lib - especially things we publish externally like Fsq.io.
    # TODO(mateo): Fix javadoc errors for published libraries and reinstall tasks.
    Goal.by_name('doc').uninstall_task('javadoc')
    Goal.by_name('doc').uninstall_task('scaladoc')

    class MockJavadoc(Task):
        @classmethod
        def product_types(cls):
            return ['javadoc', 'scaladoc']

        def execute(self):
            pass

    task(name='mockdoc', action=MockJavadoc).install('doc')
    task(name='pom-publish', action=PomPublish).install()
Ejemplo n.º 20
0
  def _determine_goals(self, address_mapper, requested_goals):
    """Check and populate the requested goals for a given run."""
    spec_parser = CmdLineSpecParser(self._root_dir)

    for goal in requested_goals:
      if address_mapper.is_valid_single_address(spec_parser.parse_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))

    return [Goal.by_name(goal) for goal in requested_goals]
Ejemplo n.º 21
0
    def _print_help(self):
        """Print a help screen, followed by an optional message.

    Note: Ony useful if called after options have been registered.
    """
        def _maybe_help(scope):
            s = self._format_help_for_scope(scope)
            if s != '':  # Avoid printing scope name for scope with empty options.
                print(scope)
                for line in s.split('\n'):
                    if line != '':  # Avoid superfluous blank lines for empty strings.
                        print('  {0}'.format(line))

        show_all_help = self._help_request and self._help_request.all_scopes
        goals = (Goal.all() if show_all_help else
                 [Goal.by_name(goal_name) for goal_name in self.goals])
        if goals:
            for goal in goals:
                if not goal.ordered_task_names():
                    print('\nUnknown goal: %s' % goal.name)
                else:
                    print('\n{0}: {1}\n'.format(goal.name, goal.description))
                    for scope in goal.known_scopes():
                        _maybe_help(scope)
        else:
            print(pants_release())
            print('\nUsage:')
            print(
                '  ./pants [option ...] [goal ...] [target...]  Attempt the specified goals.'
            )
            print('  ./pants help                                 Get help.')
            print(
                '  ./pants help [goal]                          Get help for a goal.'
            )
            print(
                '  ./pants help-advanced [goal]                 Get help for a goal\'s advanced options.'
            )
            print(
                '  ./pants help-all                             Get help for all goals.'
            )
            print(
                '  ./pants goals                                List all installed goals.'
            )
            print('')
            print('  [target] accepts two special forms:')
            print(
                '    dir:  to include all targets in the specified directory.')
            print(
                '    dir:: to include all targets found recursively under the directory.'
            )
            print('\nFriendly docs:\n  http://pantsbuild.github.io/')

        if show_all_help or not goals:
            print('\nGlobal options:')
            print(self.get_global_parser().format_help())
Ejemplo n.º 22
0
  def _determine_goals(self, requested_goals):
    """Check and populate the requested goals for a given run."""

    spec_parser = CmdLineSpecParser(self._root_dir)
    for goal in requested_goals:
      if self._address_mapper.is_valid_single_address(spec_parser.parse_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))

    goals = [Goal.by_name(goal) for goal in requested_goals]
    return goals
Ejemplo n.º 23
0
  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])
Ejemplo n.º 24
0
  def _determine_goals(self, requested_goals):
    """Check and populate the requested goals for a given run."""
    def is_quiet(goals):
      return any(goal.has_task_of_type(QuietTaskMixin) for goal in goals) or self._explain

    spec_parser = CmdLineSpecParser(self._root_dir)
    for goal in requested_goals:
      if self._address_mapper.is_valid_single_address(spec_parser.parse_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))

    goals = [Goal.by_name(goal) for goal in requested_goals]
    return goals, is_quiet(goals)
Ejemplo n.º 25
0
  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])
Ejemplo n.º 26
0
    def print_help(self, msg=None, goals=None, legacy=False):
        """Print a help screen, followed by an optional message.

    Note: Ony useful if called after options have been registered.
    """
        def _maybe_print(s):
            if s != '':  # Avoid superfluous blank lines for empty strings.
                print(s)

        goals = goals or self.goals
        if goals:
            for goal_name in goals:
                goal = Goal.by_name(goal_name)
                if not goal.ordered_task_names():
                    print('\nUnknown goal: %s' % goal_name)
                else:
                    _maybe_print(
                        self.format_help('%s' % goal.name, legacy=legacy))
                    for task_name in goal.ordered_task_names():
                        if task_name != goal.name:  # Otherwise we registered on the goal scope.
                            scope = '%s.%s' % (goal.name, task_name)
                            _maybe_print(self.format_help(scope,
                                                          legacy=legacy))
        else:
            print(pants_release())
            print('\nUsage:')
            print(
                '  ./pants [option ...] [goal ...] [target...]  Attempt the specified goals.'
            )
            print('  ./pants help                                 Get help.')
            print(
                '  ./pants help [goal]                          Get help for the specified goal.'
            )
            print(
                '  ./pants goals                                List all installed goals.'
            )
            print('')
            print('  [target] accepts two special forms:')
            print(
                '    dir:  to include all targets in the specified directory.')
            print(
                '    dir:: to include all targets found recursively under the directory.'
            )

            print('\nFriendly docs:\n  http://pantsbuild.github.io/')

            print('\nGlobal options:')
            print(self.format_global_help())

        if msg is not None:
            print(msg)
Ejemplo n.º 27
0
  def install(self, goal=None, first=False, replace=False, before=None, after=None):
    """Install the task in the specified goal (or a new goal with the same name as the task).

    The placement of the task in the execution list of the goal defaults to the end but can be
    influence by specifying exactly one of the following arguments:

    :param first: Places this task 1st in the goal's execution list.
    :param replace: Replaces any existing tasks in the goal with this goal.
    :param before: Places this task before the named task in the goal's execution list.
    :param after: Places this task after the named task in the goal's execution list.
    """
    goal = Goal.by_name(goal or self.name)
    goal.install(self, first, replace, before, after)
    return goal
Ejemplo n.º 28
0
  def install(self, goal=None, first=False, replace=False, before=None, after=None):
    """Install the task in the specified goal (or a new goal with the same name as the task).

    The placement of the task in the execution list of the goal defaults to the end but can be
    influence by specifying exactly one of the following arguments:

    :param first: Places this task 1st in the goal's execution list.
    :param replace: Replaces any existing tasks in the goal with this goal.
    :param before: Places this task before the named task in the goal's execution list.
    :param after: Places this task after the named task in the goal's execution list.
    """
    goal = Goal.by_name(goal or self.name)
    goal.install(self, first, replace, before, after)
    return goal
Ejemplo n.º 29
0
    def test_plugin_installs_goal(self):
        def reg_goal():
            Goal.by_name("plugindemo").install(TaskRegistrar("foo", DummyTask))

        self.working_set.add(
            self.get_mock_plugin("regdemo", "0.0.1", reg=reg_goal))

        # Start without the custom goal.
        self.assertEqual(0,
                         len(Goal.by_name("plugindemo").ordered_task_names()))

        # Ensure goal isn't created in a v2 world.
        self.load_plugins(["regdemo"], is_v1_plugin=False)
        self.assertEqual(0,
                         len(Goal.by_name("plugindemo").ordered_task_names()))

        # Load plugin which registers custom goal.
        self.load_plugins(["regdemo"], is_v1_plugin=True)

        # Now the custom goal exists.
        self.assertEqual(1,
                         len(Goal.by_name("plugindemo").ordered_task_names()))
        self.assertEqual("foo",
                         Goal.by_name("plugindemo").ordered_task_names()[0])
Ejemplo n.º 30
0
  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])
Ejemplo n.º 31
0
  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])
Ejemplo n.º 32
0
  def test_load_valid_partial_goals(self):
    def register_goals():
      Goal.by_name('jack').install(TaskRegistrar('jill', DummyTask))

    with self.create_register(register_goals=register_goals) as backend_package:
      Goal.clear()
      self.assertEqual(0, len(Goal.all()))

      load_backend(self.build_configuration, backend_package)
      self.assert_empty_aliases()
      self.assertEqual(1, len(Goal.all()))

      task_names = Goal.by_name('jack').ordered_task_names()
      self.assertEqual(1, len(task_names))

      task_name = task_names[0]
      self.assertEqual('jill', task_name)
Ejemplo n.º 33
0
  def test_load_valid_partial_goals(self):
    def register_goals():
      Goal.by_name('jack').install(TaskRegistrar('jill', lambda: 42))

    with self.create_register(register_goals=register_goals) as backend_package:
      Goal.clear()
      self.assertEqual(0, len(Goal.all()))

      load_backend(self.build_configuration, backend_package)
      self.assert_empty_aliases()
      self.assertEqual(1, len(Goal.all()))

      task_names = Goal.by_name('jack').ordered_task_names()
      self.assertEqual(1, len(task_names))

      task_name = task_names[0]
      self.assertEqual('jill', task_name)
Ejemplo n.º 34
0
  def print_help(self, msg=None, goals=None):
    """Print a help screen, followed by an optional message.

    Note: Ony useful if called after options have been registered.
    """
    def _maybe_help(scope):
      s = self.format_help(scope)
      if s != '':  # Avoid printing scope name for scope with empty options.
        print(scope)
        for line in s.split('\n'):
          if line != '':  # Avoid superfluous blank lines for empty strings.
            print('  {0}'.format(line))

    goals = goals or self.goals
    if goals:
      for goal_name in goals:
        goal = Goal.by_name(goal_name)
        if not goal.ordered_task_names():
          print('\nUnknown goal: %s' % goal_name)
        else:
          print('\n{0}: {1}\n'.format(goal.name, goal.description))
          for scope in goal.known_scopes():
            _maybe_help(scope)
    else:
      print(pants_release())
      print('\nUsage:')
      print('  ./pants [option ...] [goal ...] [target...]  Attempt the specified goals.')
      print('  ./pants help                                 Get help.')
      print('  ./pants help [goal]                          Get help for the specified goal.')
      print('  ./pants goal goals                           List all installed goals.')
      print('')
      print('  [target] accepts two special forms:')
      print('    dir:  to include all targets in the specified directory.')
      print('    dir:: to include all targets found recursively under the directory.')

      print('\nFriendly docs:\n  http://pantsbuild.github.io/')

      print('\nGlobal options:')
      print(self.format_global_help())

    if msg is not None:
      print(msg)
Ejemplo n.º 35
0
    def __init__(self, name, action, dependencies=None, serialize=True):
        """
    :param name: the name of the task.
    :param action: the Task action object to invoke this task.
    :param dependencies: the names of other goals which must be achieved before invoking this
                         task's goal.
    :param serialize: a flag indicating whether or not the action to achieve this goal requires
      the global lock. If true, the action will block until it can acquire the lock.
    """
        self.serialize = serialize
        self.name = name
        self.dependencies = [Goal.by_name(d)
                             for d in dependencies] if dependencies else []

        if isinstance(type(action), type) and issubclass(action, Task):
            self._task = action
        else:
            args, varargs, keywords, defaults = inspect.getargspec(action)
            if varargs or keywords or defaults:
                raise GoalError(
                    'Invalid action supplied, cannot accept varargs, keywords or defaults'
                )
            if len(args) > 1:
                raise GoalError(
                    'Invalid action supplied, must accept either no args or else a single '
                    'Context object')

            class FuncTask(Task):
                def __init__(self, *args, **kwargs):
                    super(FuncTask, self).__init__(*args, **kwargs)

                    if not args:
                        self.action = action
                    elif len(args) == 1:
                        self.action = functools.partial(action, self.context)
                    else:
                        raise AssertionError('Unexpected fallthrough')

                def execute(self):
                    self.action()

            self._task = FuncTask
Ejemplo n.º 36
0
  def _print_help(self):
    """Print a help screen, followed by an optional message.

    Note: Ony useful if called after options have been registered.
    """
    def _maybe_help(scope):
      s = self._format_help_for_scope(scope)
      if s != '':  # Avoid printing scope name for scope with empty options.
        print(scope)
        for line in s.split('\n'):
          if line != '':  # Avoid superfluous blank lines for empty strings.
            print('  {0}'.format(line))

    show_all_help = self._help_request and self._help_request.all_scopes
    goals = (Goal.all() if show_all_help else [Goal.by_name(goal_name) for goal_name in self.goals])
    if goals:
      for goal in goals:
        if not goal.ordered_task_names():
          print('\nUnknown goal: {}'.format(goal.name))
        else:
          print('\n{0}: {1}\n'.format(goal.name, goal.description))
          for scope in goal.known_scopes():
            _maybe_help(scope)
    else:
      print(pants_release())
      print('\nUsage:')
      print('  ./pants [option ...] [goal ...] [target...]  Attempt the specified goals.')
      print('  ./pants help                                 Get help.')
      print('  ./pants help [goal]                          Get help for a goal.')
      print('  ./pants help-advanced [goal]                 Get help for a goal\'s advanced options.')
      print('  ./pants help-all                             Get help for all goals.')
      print('  ./pants goals                                List all installed goals.')
      print('')
      print('  [target] accepts two special forms:')
      print('    dir:  to include all targets in the specified directory.')
      print('    dir:: to include all targets found recursively under the directory.')
      print('\nFriendly docs:\n  http://pantsbuild.github.io/')

    if show_all_help or not goals:
      print('\nGlobal options:')
      print(self.get_global_parser().format_help())
Ejemplo n.º 37
0
  def print_help(self, msg=None, goals=None, legacy=False):
    """Print a help screen, followed by an optional message.

    Note: Ony useful if called after options have been registered.
    """
    def _maybe_print(s):
      if s != '':  # Avoid superfluous blank lines for empty strings.
        print(s)

    goals = goals or self.goals
    if goals:
      for goal_name in goals:
        goal = Goal.by_name(goal_name)
        if not goal.ordered_task_names():
          print('\nUnknown goal: %s' % goal_name)
        else:
          _maybe_print(self.format_help('%s' % goal.name, legacy=legacy))
          for task_name in goal.ordered_task_names():
            if task_name != goal.name:  # Otherwise we registered on the goal scope.
              scope = '%s.%s' % (goal.name, task_name)
              _maybe_print(self.format_help(scope, legacy=legacy))
    else:
      print(pants_release())
      print('\nUsage:')
      print('  ./pants [option ...] [goal ...] [target...]  Attempt the specified goals.')
      print('  ./pants help                                 Get help.')
      print('  ./pants help [goal]                          Get help for the specified goal.')
      print('  ./pants goals                                List all installed goals.')
      print('')
      print('  [target] accepts two special forms:')
      print('    dir:  to include all targets in the specified directory.')
      print('    dir:: to include all targets found recursively under the directory.')

      print('\nFriendly docs:\n  http://pantsbuild.github.io/')

      print('\nGlobal options:')
      print(self.format_global_help())

    if msg is not None:
      print(msg)
Ejemplo n.º 38
0
  def __init__(self, name, action, dependencies=None, serialize=True):
    """
    :param name: the name of the task.
    :param action: the Task action object to invoke this task.
    :param dependencies: the names of other goals which must be achieved before invoking this
                         task's goal.
    :param serialize: a flag indicating whether or not the action to achieve this goal requires
      the global lock. If true, the action will block until it can acquire the lock.
    """
    self.serialize = serialize
    self.name = name
    self.dependencies = [Goal.by_name(d) for d in dependencies] if dependencies else []

    if isinstance(type(action), type) and issubclass(action, Task):
      self._task = action
    else:
      args, varargs, keywords, defaults = inspect.getargspec(action)
      if varargs or keywords or defaults:
        raise GoalError('Invalid action supplied, cannot accept varargs, keywords or defaults')
      if len(args) > 1:
        raise GoalError('Invalid action supplied, must accept either no args or else a single '
                        'Context object')

      class FuncTask(Task):
        def __init__(self, *args, **kwargs):
          super(FuncTask, self).__init__(*args, **kwargs)

          if not args:
            self.action = action
          elif len(args) == 1:
            self.action = functools.partial(action, self.context)
          else:
            raise AssertionError('Unexpected fallthrough')

        def execute(self):
          self.action()

      self._task = FuncTask
Ejemplo n.º 39
0
def register_goals():
    ng_killall = task(name='ng-killall', action=NailgunKillall)
    ng_killall.install()

    Goal.by_name('invalidate').install(ng_killall, first=True)
    Goal.by_name('clean-all').install(ng_killall, first=True)

    task(name='jar-dependency-management',
         action=JarDependencyManagementSetup).install('bootstrap')

    task(name='jvm-platform-explain',
         action=JvmPlatformExplain).install('jvm-platform-explain')
    task(name='jvm-platform-validate',
         action=JvmPlatformValidate).install('jvm-platform-validate')

    task(name='bootstrap-jvm-tools',
         action=BootstrapJvmTools).install('bootstrap')
    task(name='provide-tools-jar', action=ProvideToolsJar).install('bootstrap')

    # Compile
    task(name='zinc', action=ZincCompile).install('compile')

    # Dependency resolution.
    task(name='ivy', action=IvyResolve).install('resolve', first=True)
    task(name='ivy-imports', action=IvyImports).install('imports')
    task(name='unpack-jars', action=UnpackJars).install()

    # Resource preparation.
    task(name='prepare', action=PrepareResources).install('resources')
    task(name='services', action=PrepareServices).install('resources')

    task(name='export-classpath', action=RuntimeClasspathPublisher).install()
    task(name='jvm-dep-check', action=JvmDependencyCheck).install('compile')

    task(name='jvm', action=JvmDependencyUsage).install('dep-usage')

    task(name='classmap', action=ClassmapTask).install('classmap')

    # Generate documentation.
    task(name='javadoc', action=JavadocGen).install('doc')
    task(name='scaladoc', action=ScaladocGen).install('doc')

    # Bundling.
    task(name='create', action=JarCreate).install('jar')
    detect_duplicates = task(name='dup', action=DuplicateDetector)

    task(name='jvm', action=BinaryCreate).install('binary')
    detect_duplicates.install('binary')

    task(name='consolidate-classpath',
         action=ConsolidateClasspath).install('bundle')
    task(name='jvm', action=BundleCreate).install('bundle')
    detect_duplicates.install('bundle')

    task(name='detect-duplicates', action=DuplicateDetector).install()

    # Publishing.
    task(name='check-published-deps',
         action=CheckPublishedDeps).install('check-published-deps')

    task(name='jar', action=JarPublish).install('publish')

    # Testing.
    task(name='junit', action=JUnitRun).install('test')
    task(name='bench', action=BenchmarkRun).install('bench')

    # Running.
    task(name='jvm', action=JvmRun, serialize=False).install('run')
    task(name='jvm-dirty', action=JvmRun, serialize=False).install('run-dirty')
    task(name='scala', action=ScalaRepl, serialize=False).install('repl')
    task(name='scala-dirty', action=ScalaRepl,
         serialize=False).install('repl-dirty')
    task(name='scalafmt', action=ScalaFmtCheckFormat,
         serialize=False).install('compile', first=True)
    task(name='scalafmt', action=ScalaFmtFormat,
         serialize=False).install('fmt')
    task(name='test-jvm-prep-command',
         action=RunTestJvmPrepCommand).install('test', first=True)
    task(name='binary-jvm-prep-command',
         action=RunBinaryJvmPrepCommand).install('binary', first=True)
    task(name='compile-jvm-prep-command',
         action=RunCompileJvmPrepCommand).install('compile', first=True)
Ejemplo n.º 40
0
 def register_goals():
   Goal.by_name('jack').install(TaskRegistrar('jill', DummyTask))
Ejemplo n.º 41
0
def register_goals():
  ng_killall = task(name='ng-killall', action=NailgunKillall)
  ng_killall.install()

  Goal.by_name('invalidate').install(ng_killall, first=True)
  Goal.by_name('clean-all').install(ng_killall, first=True)

  task(name='jar-dependency-management', action=JarDependencyManagementSetup).install('bootstrap')

  task(name='jvm-platform-explain', action=JvmPlatformExplain).install('jvm-platform-explain')
  task(name='jvm-platform-validate', action=JvmPlatformValidate).install('jvm-platform-validate')

  task(name='bootstrap-jvm-tools', action=BootstrapJvmTools).install('bootstrap')
  task(name='provide-tools-jar', action=ProvideToolsJar).install('bootstrap')

  # Compile
  task(name='zinc', action=ZincCompile).install('compile')
  task(name='javac', action=JavacCompile).install('compile')

  # Analysis extraction.
  task(name='zinc', action=AnalysisExtraction).install('analysis')

  # Dependency resolution.
  task(name='ivy', action=IvyResolve).install('resolve', first=True)
  task(name='coursier', action=CoursierResolve).install('resolve')
  task(name='ivy-imports', action=IvyImports).install('imports')
  task(name='unpack-jars', action=UnpackJars).install()
  task(name='ivy', action=IvyOutdated).install('outdated')

  # Resource preparation.
  task(name='prepare', action=PrepareResources).install('resources')
  task(name='services', action=PrepareServices).install('resources')

  task(name='export-classpath', action=RuntimeClasspathPublisher).install()

  task(name='jvm', action=JvmDependencyUsage).install('dep-usage')

  task(name='classmap', action=ClassmapTask).install('classmap')

  # Generate documentation.
  task(name='javadoc', action=JavadocGen).install('doc')
  task(name='scaladoc', action=ScaladocGen).install('doc')

  # Bundling.
  task(name='create', action=JarCreate).install('jar')
  detect_duplicates = task(name='dup', action=DuplicateDetector)

  task(name='jvm', action=BinaryCreate).install('binary')
  detect_duplicates.install('binary')

  task(name='consolidate-classpath', action=ConsolidateClasspath).install('bundle')
  task(name='jvm', action=BundleCreate).install('bundle')
  detect_duplicates.install('bundle')

  task(name='detect-duplicates', action=DuplicateDetector).install()

  # Publishing.
  task(name='check-published-deps', action=CheckPublishedDeps).install('check-published-deps')

  task(name='jar', action=JarPublish).install('publish')

  # Testing.
  task(name='junit', action=JUnitRun).install('test')
  task(name='bench', action=BenchmarkRun).install('bench')

  # Linting.
  task(name='scalafix', action=ScalaFixCheck).install('lint')
  task(name='scalafmt', action=ScalaFmtCheckFormat, serialize=False).install('lint')
  task(name='scalastyle', action=Scalastyle, serialize=False).install('lint')
  task(name='checkstyle', action=Checkstyle, serialize=False).install('lint')
  task(name='jvm-dep-check', action=JvmDependencyCheck, serialize=False).install('lint')

  # Formatting.
  # Scalafix has to go before scalafmt in order not to
  # further change Scala files after scalafmt.
  task(name='scalafix', action=ScalaFixFix).install('fmt')
  task(name='scalafmt', action=ScalaFmtFormat, serialize=False).install('fmt')

  # Running.
  task(name='jvm', action=JvmRun, serialize=False).install('run')
  task(name='jvm-dirty', action=JvmRun, serialize=False).install('run-dirty')
  task(name='scala', action=ScalaRepl, serialize=False).install('repl')
  task(name='scala-dirty', action=ScalaRepl, serialize=False).install('repl-dirty')
  task(name='test-jvm-prep-command', action=RunTestJvmPrepCommand).install('test', first=True)
  task(name='binary-jvm-prep-command', action=RunBinaryJvmPrepCommand).install('binary', first=True)
  task(name='compile-jvm-prep-command', action=RunCompileJvmPrepCommand).install('compile', first=True)
Ejemplo n.º 42
0
def register_goals():
    Goal.by_name('bootstrap').uninstall_task('jar-dependency-management')
    task(name='global-jar-dependency-management',
         action=JarDependencyGlobalManagementSetup).install('bootstrap')
    Goal.by_name('resolve').uninstall_task('ivy')
    task(name='ivy', action=IvyGlobalResolve).install('resolve', first=True)
Ejemplo n.º 43
0
 def register_goals():
     Goal.by_name("jack").install(TaskRegistrar("jill", DummyTask))
Ejemplo n.º 44
0
 def register_goals():
     Goal.by_name("jack").install(TaskRegistrar("jill", lambda: 42))
Ejemplo n.º 45
0
def register_goals():
    ng_killall = task(name='ng-killall', action=NailgunKillall)
    ng_killall.install().with_description('Kill running nailgun servers.')

    Goal.by_name('invalidate').install(ng_killall, first=True)
    Goal.by_name('clean-all').install(ng_killall, first=True)
    Goal.by_name('clean-all-async').install(ng_killall, first=True)

    task(name='bootstrap-jvm-tools', action=BootstrapJvmTools).install(
        'bootstrap').with_description('Bootstrap tools needed for building.')

    # Dependency resolution.
    task(name='ivy', action=IvyResolve).install('resolve').with_description(
        'Resolve dependencies and produce dependency reports.')

    task(name='ivy-imports', action=IvyImports).install('imports')

    task(name='unpack-jars', action=UnpackJars).install().with_description(
        'Unpack artifacts specified by unpacked_jars() targets.')

    # Compilation.

    # AnnotationProcessors are java targets, but we need to force them into their own compilation
    # rounds so that they are on classpath of any dependees downstream that may use them. Without
    # forcing a separate member type we could get a java chunk containing a mix of apt processors and
    # code that relied on the un-compiled apt processor in the same javac invocation.  If so, javac
    # would not be smart enough to compile the apt processors 1st and activate them.
    class AptCompile(JavaCompile):
        @classmethod
        def name(cls):
            return 'apt'

        def select(self, target):
            return super(AptCompile, self).select(target) and isinstance(
                target, AnnotationProcessor)

    jvm_compile = GroupTask.named(
        'jvm-compilers',
        product_type=['classes_by_target', 'classes_by_source'],
        flag_namespace=['compile'])

    # Here we register the ScalaCompile group member before the java group members very deliberately.
    # At some point ScalaLibrary targets will be able to own mixed scala and java source sets. At that
    # point, the ScalaCompile group member will still only select targets via has_sources('*.scala');
    # however if the JavaCompile group member were registered earlier, it would claim the ScalaLibrary
    # targets with mixed source sets leaving those targets un-compiled by scalac and resulting in
    # systemic compile errors.
    jvm_compile.add_member(ScalaCompile)

    # Its important we add AptCompile before JavaCompile since it 1st selector wins and apt code is a
    # subset of java code
    jvm_compile.add_member(AptCompile)

    jvm_compile.add_member(JavaCompile)

    task(name='jvm', action=jvm_compile).install('compile').with_description(
        'Compile source code.')

    # Generate documentation.
    task(name='javadoc', action=JavadocGen).install('doc').with_description(
        'Create documentation.')
    task(name='scaladoc', action=ScaladocGen).install('doc')

    # Bundling.
    task(name='jar', action=JarCreate).install('jar')
    detect_duplicates = task(name='dup', action=DuplicateDetector)

    task(name='binary', action=BinaryCreate).install().with_description(
        'Create a runnable binary.')
    detect_duplicates.install('binary')

    task(name='bundle', action=BundleCreate).install().with_description(
        'Create an application bundle from binary targets.')
    detect_duplicates.install('bundle')

    task(name='detect-duplicates',
         action=DuplicateDetector).install().with_description(
             'Detect duplicate classes and resources on the classpath.')

    # Publishing.
    task(
        name='check_published_deps',
        action=CheckPublishedDeps,
    ).install('check_published_deps').with_description(
        'Find references to outdated artifacts.')

    task(name='publish', action=JarPublish).install(
        'publish').with_description('Publish artifacts.')

    # Testing.
    task(name='junit', action=JUnitRun).install('test').with_description(
        'Test compiled code.')
    task(name='specs', action=SpecsRun).install('test')
    task(name='bench', action=BenchmarkRun).install('bench')

    # Running.
    task(name='jvm', action=JvmRun, serialize=False).install(
        'run').with_description('Run a binary target.')
    task(name='jvm-dirty', action=JvmRun,
         serialize=False).install('run-dirty').with_description(
             'Run a binary target, skipping compilation.')

    task(name='scala', action=ScalaRepl,
         serialize=False).install('repl').with_description('Run a REPL.')
    task(name='scala-dirty', action=ScalaRepl, serialize=False).install(
        'repl-dirty').with_description('Run a REPL, skipping compilation.')

    # IDE support.
    task(name='idea', action=IdeaGen).install().with_description(
        'Create an IntelliJ IDEA project from the given targets.')

    task(name='eclipse', action=EclipseGen).install().with_description(
        'Create an Eclipse project from the given targets.')

    task(name='ensime', action=EnsimeGen).install().with_description(
        'Create an Ensime project from the given targets.')

    # Build graph information.
    task(name='provides', action=Provides).install().with_description(
        'Print the symbols provided by the given targets.')

    # XXX(pl): These should be core, but they have dependencies on JVM
    task(name='depmap', action=Depmap).install().with_description(
        "Depict the target's dependencies.")

    task(name='dependencies', action=Dependencies).install().with_description(
        "Print the target's dependencies.")

    task(name='filedeps',
         action=FileDeps).install('filedeps').with_description(
             'Print out the source and BUILD files the target depends on.')
Ejemplo n.º 46
0
def register_goals():
    ng_killall = task(name="ng-killall", action=NailgunKillall)
    ng_killall.install()

    Goal.by_name("invalidate").install(ng_killall, first=True)
    Goal.by_name("clean-all").install(ng_killall, first=True)

    task(name="jar-dependency-management",
         action=JarDependencyManagementSetup).install("bootstrap")

    task(name="jvm-platform-explain",
         action=JvmPlatformExplain).install("jvm-platform-explain")
    task(name="jvm-platform-validate",
         action=JvmPlatformValidate).install("jvm-platform-validate")

    task(name="bootstrap-jvm-tools",
         action=BootstrapJvmTools).install("bootstrap")
    task(name="provide-tools-jar", action=ProvideToolsJar).install("bootstrap")

    # Compile
    task(name="rsc", action=RscCompile).install("compile")
    task(name="javac", action=JavacCompile).install("compile")

    # Analysis extraction.
    task(name="zinc", action=AnalysisExtraction).install("analysis")

    # Dependency resolution.
    task(name="ivy", action=IvyResolve).install("resolve", first=True)
    task(name="coursier", action=CoursierResolve).install("resolve")
    task(name="ivy-imports", action=IvyImports).install("imports")
    task(name="unpack-jars", action=UnpackJars).install()
    task(name="ivy", action=IvyOutdated).install("outdated")

    # Resource preparation.
    task(name="prepare", action=PrepareResources).install("resources")
    task(name="services", action=PrepareServices).install("resources")

    task(name="export-classpath", action=RuntimeClasspathPublisher).install()

    # This goal affects the contents of the runtime_classpath, and should not be
    # combined with any other goals on the command line.
    task(name="export-dep-as-jar", action=ExportDepAsJar).install()

    task(name="jvm", action=JvmDependencyUsage).install("dep-usage")

    task(name="classmap", action=ClassmapTask).install("classmap")

    # Generate documentation.
    task(name="javadoc", action=JavadocGen).install("doc")
    task(name="scaladoc", action=ScaladocGen).install("doc")

    # Bundling.
    task(name="create", action=JarCreate).install("jar")
    detect_duplicates = task(name="dup", action=DuplicateDetector)

    task(name="jvm", action=BinaryCreate).install("binary")
    detect_duplicates.install("binary")

    task(name="consolidate-classpath",
         action=ConsolidateClasspath).install("bundle")
    task(name="jvm", action=BundleCreate).install("bundle")
    detect_duplicates.install("bundle")

    task(name="detect-duplicates", action=DuplicateDetector).install()

    # Publishing.
    task(name="check-published-deps",
         action=CheckPublishedDeps).install("check-published-deps")

    task(name="jar", action=JarPublish).install("publish")

    # Testing.
    task(name="junit", action=JUnitRun).install("test")
    task(name="bench", action=BenchmarkRun).install("bench")

    # Linting.
    task(name="scalafix", action=ScalaFixCheck).install("lint")
    task(name="scalafmt", action=ScalaFmtCheckFormat,
         serialize=False).install("lint")
    task(name="scalastyle", action=ScalastyleTask,
         serialize=False).install("lint")
    task(name="checkstyle", action=Checkstyle, serialize=False).install("lint")
    task(name="jvm-dep-check", action=JvmDependencyCheck,
         serialize=False).install("lint")

    # Formatting.
    # Scalafix has to go before scalafmt in order not to
    # further change Scala files after scalafmt.
    task(name="scalafix", action=ScalaFixFix).install("fmt")
    task(name="scalafmt", action=ScalaFmtFormat,
         serialize=False).install("fmt")

    # Running.
    task(name="jvm", action=JvmRun, serialize=False).install("run")
    task(name="jvm-dirty", action=JvmRun, serialize=False).install("run-dirty")
    task(name="scala", action=ScalaRepl, serialize=False).install("repl")
    task(name="scala-dirty", action=ScalaRepl,
         serialize=False).install("repl-dirty")
    task(name="test-jvm-prep-command",
         action=RunTestJvmPrepCommand).install("test", first=True)
    task(name="binary-jvm-prep-command",
         action=RunBinaryJvmPrepCommand).install("binary", first=True)
    task(name="compile-jvm-prep-command",
         action=RunCompileJvmPrepCommand).install("compile", first=True)
Ejemplo n.º 47
0
 def reg_goal():
     Goal.by_name("plugindemo").install(TaskRegistrar("foo", DummyTask))
Ejemplo n.º 48
0
 def reg_goal():
   Goal.by_name('plugindemo').install(TaskRegistrar('foo', DummyTask))
Ejemplo n.º 49
0
 def test_gen_tasks_goals_reference_data(self):
   # can we run our reflection-y goal code without crashing? would be nice
   Goal.by_name('jack').install(TaskRegistrar('jill', lambda: 42))
   gref_data = builddictionary.gen_tasks_goals_reference_data()
   self.assertTrue(len(gref_data) > 0, 'Tried to generate data for goals reference, got emptiness')
Ejemplo n.º 50
0
def register_goals():
  ng_killall = task(name='ng-killall', action=NailgunKillall)
  ng_killall.install().with_description('Kill running nailgun servers.')

  Goal.by_name('invalidate').install(ng_killall, first=True)
  Goal.by_name('clean-all').install(ng_killall, first=True)
  Goal.by_name('clean-all-async').install(ng_killall, first=True)

  task(name='bootstrap-jvm-tools', action=BootstrapJvmTools).install('bootstrap').with_description(
      'Bootstrap tools needed for building.')

  # Dependency resolution.
  task(name='ivy', action=IvyResolve).install('resolve').with_description(
      'Resolve dependencies and produce dependency reports.')

  task(name='ivy-imports', action=IvyImports).install('imports')

  # Compilation.

  # AnnotationProcessors are java targets, but we need to force them into their own compilation
  # rounds so that they are on classpath of any dependees downstream that may use them. Without
  # forcing a separate member type we could get a java chunk containing a mix of apt processors and
  # code that relied on the un-compiled apt processor in the same javac invocation.  If so, javac
  # would not be smart enough to compile the apt processors 1st and activate them.
  class AptCompile(JavaCompile):
    @classmethod
    def name(cls):
      return 'apt'

    def select(self, target):
      return super(AptCompile, self).select(target) and target.is_apt


  jvm_compile = GroupTask.named(
      'jvm-compilers',
      product_type=['classes_by_target', 'classes_by_source'],
      flag_namespace=['compile'])

  # Here we register the ScalaCompile group member before the java group members very deliberately.
  # At some point ScalaLibrary targets will be able to own mixed scala and java source sets. At that
  # point, the ScalaCompile group member will still only select targets via has_sources('*.scala');
  # however if the JavaCompile group member were registered earlier, it would claim the ScalaLibrary
  # targets with mixed source sets leaving those targets un-compiled by scalac and resulting in
  # systemic compile errors.
  jvm_compile.add_member(ScalaCompile)

  # Its important we add AptCompile before JavaCompile since it 1st selector wins and apt code is a
  # subset of java code
  jvm_compile.add_member(AptCompile)

  jvm_compile.add_member(JavaCompile)

  task(name='jvm', action=jvm_compile).install('compile').with_description('Compile source code.')

  # Generate documentation.
  task(name='javadoc', action=JavadocGen).install('doc').with_description('Create documentation.')
  task(name='scaladoc', action=ScaladocGen).install('doc')

  # Bundling.
  task(name='jar', action=JarCreate).install('jar')
  detect_duplicates = task(name='dup', action=DuplicateDetector)

  task(name='binary', action=BinaryCreate).install().with_description('Create a runnable binary.')
  detect_duplicates.install('binary')

  task(name='bundle', action=BundleCreate).install().with_description(
      'Create an application bundle from binary targets.')
  detect_duplicates.install('bundle')

  task(name='detect-duplicates', action=DuplicateDetector).install().with_description(
      'Detect duplicate classes and resources on the classpath.')

 # Publishing.
  task(
    name='check_published_deps',
    action=CheckPublishedDeps,
  ).install('check_published_deps').with_description('Find references to outdated artifacts.')

  task(name='publish', action=JarPublish).install('publish').with_description(
      'Publish artifacts.')

  # Testing.
  task(name='junit', action=JUnitRun).install('test').with_description('Test compiled code.')
  task(name='specs', action=SpecsRun).install('test')
  task(name='bench', action=BenchmarkRun).install('bench')

  # Running.
  task(name='jvm', action=JvmRun, serialize=False).install('run').with_description(
      'Run a binary target.')
  task(name='jvm-dirty', action=JvmRun, serialize=False).install('run-dirty').with_description(
      'Run a binary target, skipping compilation.')

  task(name='scala', action=ScalaRepl, serialize=False).install('repl').with_description(
      'Run a REPL.')
  task(
    name='scala-dirty',
    action=ScalaRepl,
    serialize=False
  ).install('repl-dirty').with_description('Run a REPL, skipping compilation.')

  # IDE support.
  task(name='idea', action=IdeaGen).install().with_description(
      'Create an IntelliJ IDEA project from the given targets.')

  task(name='eclipse', action=EclipseGen).install().with_description(
      'Create an Eclipse project from the given targets.')

  task(name='ensime', action=EnsimeGen).install().with_description(
      'Create an Ensime project from the given targets.')

  # Build graph information.
  task(name='provides', action=Provides).install().with_description(
      'Print the symbols provided by the given targets.')

  # XXX(pl): These should be core, but they have dependencies on JVM
  task(name='depmap', action=Depmap).install().with_description("Depict the target's dependencies.")

  task(name='dependencies', action=Dependencies).install().with_description(
      "Print the target's dependencies.")

  task(name='filedeps', action=FileDeps).install('filedeps').with_description(
      'Print out the source and BUILD files the target depends on.')
Ejemplo n.º 51
0
 def test_gen_tasks_options_reference_data(self):
   # Can we run our reflection-y goal code without crashing? would be nice.
   Goal.by_name('jack').install(TaskRegistrar('jill', DummyTask))
   oref_data = reflect.gen_tasks_options_reference_data()
   self.assertTrue(len(oref_data) > 0,
                   'Tried to generate data for options reference, got emptiness')
Ejemplo n.º 52
0
 def register_goals():
   Goal.by_name('jack').install(TaskRegistrar('jill', DummyTask))
Ejemplo n.º 53
0
    def setup_parser(self, parser, args):
        self.config = Config.load()
        add_global_options(parser)

        # We support attempting zero or more goals.  Multiple goals must be delimited from further
        # options and non goal args with a '--'.  The key permutations we need to support:
        # ./pants goal => goals
        # ./pants goal goals => goals
        # ./pants goal compile src/java/... => compile
        # ./pants goal compile -x src/java/... => compile
        # ./pants goal compile src/java/... -x => compile
        # ./pants goal compile run -- src/java/... => compile, run
        # ./pants goal compile run -- src/java/... -x => compile, run
        # ./pants goal compile run -- -x src/java/... => compile, run

        if not args:
            args.append("help")

        help_flags = set(["-h", "--help", "help"])
        show_help = len(help_flags.intersection(args)) > 0
        non_help_args = filter(lambda f: f not in help_flags, args)

        goals, specs = GoalRunner.parse_args(non_help_args)
        if show_help:
            print_help(goals)
            sys.exit(0)

        self.requested_goals = goals

        with self.run_tracker.new_workunit(name="setup", labels=[WorkUnit.SETUP]):
            # Bootstrap user goals by loading any BUILD files implied by targets.
            spec_parser = CmdLineSpecParser(self.root_dir, self.address_mapper)
            with self.run_tracker.new_workunit(name="parse", labels=[WorkUnit.SETUP]):
                for spec in specs:
                    for address in spec_parser.parse_addresses(spec):
                        self.build_graph.inject_address_closure(address)
                        self.targets.append(self.build_graph.get_target(address))
        self.goals = [Goal.by_name(goal) for goal in goals]

        rcfiles = self.config.getdefault("rcfiles", type=list, default=["/etc/pantsrc", "~/.pants.rc"])
        if rcfiles:
            rcfile = RcFile(rcfiles, default_prepend=False, process_default=True)

            # Break down the goals specified on the command line to the full set that will be run so we
            # can apply default flags to inner goal nodes.  Also break down goals by Task subclass and
            # register the task class hierarchy fully qualified names so we can apply defaults to
            # baseclasses.

            sections = OrderedSet()
            for goal in Engine.execution_order(self.goals):
                for task_name in goal.ordered_task_names():
                    sections.add(task_name)
                    task_type = goal.task_type_by_name(task_name)
                    for clazz in task_type.mro():
                        if clazz == Task:
                            break
                        sections.add("%s.%s" % (clazz.__module__, clazz.__name__))

            augmented_args = rcfile.apply_defaults(sections, args)
            if augmented_args != args:
                # TODO(John Sirois): Cleanup this currently important mutation of the passed in args
                # once the 2-layer of command -> goal is squashed into one.
                del args[:]
                args.extend(augmented_args)
                sys.stderr.write("(using pantsrc expansion: pants goal %s)\n" % " ".join(augmented_args))

        Goal.setup_parser(parser, args, self.goals)
Ejemplo n.º 54
0
 def reg_goal():
   Goal.by_name('plugindemo').install(TaskRegistrar('foo', DummyTask))
Ejemplo n.º 55
0
def register_goals():
    Goal.by_name('export').uninstall_task('export')
    task(
        name='export',
        action=GenStubsAndExport,
    ).install()
Ejemplo n.º 56
0
 def _determine_v1_goals(self, options: Options) -> List[Goal]:
     """Check and populate the requested goals for a given run."""
     v1_goals, ambiguous_goals, _ = options.goals_by_version
     return [Goal.by_name(goal) for goal in v1_goals + ambiguous_goals]
Ejemplo n.º 57
0
def register_goals():
  ng_killall = task(name='ng-killall', action=NailgunKillall)
  ng_killall.install().with_description('Kill running nailgun servers.')

  Goal.by_name('invalidate').install(ng_killall, first=True)
  Goal.by_name('clean-all').install(ng_killall, first=True)
  Goal.by_name('clean-all-async').install(ng_killall, first=True)

  task(name='jvm-platform-explain', action=JvmPlatformExplain).install('jvm-platform-explain')
  task(name='jvm-platform-validate', action=JvmPlatformValidate).install('jvm-platform-validate')

  task(name='bootstrap-jvm-tools', action=BootstrapJvmTools).install('bootstrap').with_description(
      'Bootstrap tools needed for building.')

  # Dependency resolution.
  task(name='ivy', action=IvyResolve).install('resolve').with_description(
      'Resolve dependencies and produce dependency reports.')

  task(name='ivy-imports', action=IvyImports).install('imports')

  task(name='unpack-jars', action=UnpackJars).install().with_description(
    'Unpack artifacts specified by unpacked_jars() targets.')

  # Resource preparation.
  task(name='prepare', action=PrepareResources).install('resources')
  task(name='services', action=PrepareServices).install('resources')

  # Compilation.
  jvm_compile = GroupTask.named(
      'jvm-compilers',
      product_type=['runtime_classpath', 'classes_by_source', 'product_deps_by_src'],
      flag_namespace=['compile'])

  # It's important we add AptCompile before other java-compiling tasks since the first selector wins,
  # and apt code is a subset of java code.
  jvm_compile.add_member(AptCompile)
  jvm_compile.add_member(JmakeCompile)
  jvm_compile.add_member(ZincCompile)

  task(name='jvm', action=jvm_compile).install('compile').with_description('Compile source code.')
  task(name='jvm-dep-check', action=JvmDependencyCheck).install('compile').with_description(
      'Check that used dependencies have been requested.')

  task(name='jvm', action=JvmDependencyUsage).install('dep-usage').with_description(
      'Collect target dependency usage data.')

  # Generate documentation.
  task(name='javadoc', action=JavadocGen).install('doc').with_description('Create documentation.')
  task(name='scaladoc', action=ScaladocGen).install('doc')

  # Bundling.
  task(name='jar', action=JarCreate).install('jar')
  detect_duplicates = task(name='dup', action=DuplicateDetector)

  task(name='binary', action=BinaryCreate).install().with_description('Create a runnable binary.')
  detect_duplicates.install('binary')

  task(name='bundle', action=BundleCreate).install().with_description(
      'Create an application bundle from binary targets.')
  detect_duplicates.install('bundle')

  task(name='detect-duplicates', action=DuplicateDetector).install().with_description(
      'Detect duplicate classes and resources on the classpath.')

 # Publishing.
  task(
    name='check_published_deps',
    action=CheckPublishedDeps,
  ).install('check_published_deps').with_description('Find references to outdated artifacts.')

  task(name='jar', action=JarPublish).install('publish').with_description(
      'Publish artifacts.')

  # Testing.
  task(name='junit', action=JUnitRun).install('test').with_description('Test compiled code.')
  task(name='bench', action=BenchmarkRun).install('bench').with_description('Run benchmark tests.')

  # Running.
  task(name='jvm', action=JvmRun, serialize=False).install('run').with_description(
      'Run a binary target.')
  task(name='jvm-dirty', action=JvmRun, serialize=False).install('run-dirty').with_description(
      'Run a binary target, skipping compilation.')

  task(name='scala', action=ScalaRepl, serialize=False).install('repl').with_description(
      'Run a REPL.')
  task(
    name='scala-dirty',
    action=ScalaRepl,
    serialize=False
  ).install('repl-dirty').with_description('Run a REPL, skipping compilation.')
Ejemplo n.º 58
0
def register_goals():
  # Remove upstream XRPC-based plugin to reclaim this namespace.
  Goal.by_name('confluence').uninstall_task('confluence')
  task(name='confluence', action=ConfluenceRestfulPublish).install()
Ejemplo n.º 59
0
def register_goals():
    ng_killall = task(name='ng-killall', action=NailgunKillall)
    ng_killall.install().with_description('Kill running nailgun servers.')

    Goal.by_name('invalidate').install(ng_killall, first=True)
    Goal.by_name('clean-all').install(ng_killall, first=True)
    Goal.by_name('clean-all-async').install(ng_killall, first=True)

    task(name='jvm-platform-explain',
         action=JvmPlatformExplain).install('jvm-platform-explain')
    task(name='jvm-platform-validate',
         action=JvmPlatformValidate).install('jvm-platform-validate')

    task(name='bootstrap-jvm-tools', action=BootstrapJvmTools).install(
        'bootstrap').with_description('Bootstrap tools needed for building.')

    # Dependency resolution.
    task(name='ivy', action=IvyResolve).install('resolve').with_description(
        'Resolve dependencies and produce dependency reports.')

    task(name='ivy-imports', action=IvyImports).install('imports')

    task(name='unpack-jars', action=UnpackJars).install().with_description(
        'Unpack artifacts specified by unpacked_jars() targets.')

    # Resource preparation.
    task(name='prepare', action=PrepareResources).install('resources')
    task(name='services', action=PrepareServices).install('resources')

    # Compilation.
    # NB: Despite being the only member, ZincCompile should continue to use GroupTask until
    # post engine refactor. It's possible that someone will want to rush in an additional
    # jvm language.
    jvm_compile = GroupTask.named('jvm-compilers',
                                  product_type=[
                                      'runtime_classpath', 'classes_by_source',
                                      'product_deps_by_src'
                                  ],
                                  flag_namespace=['compile'])
    jvm_compile.add_member(ZincCompile)
    task(name='jvm', action=jvm_compile).install('compile').with_description(
        'Compile source code.')

    task(name='jvm-dep-check',
         action=JvmDependencyCheck).install('compile').with_description(
             'Check that used dependencies have been requested.')

    task(name='jvm', action=JvmDependencyUsage).install(
        'dep-usage').with_description('Collect target dependency usage data.')

    # Generate documentation.
    task(name='javadoc', action=JavadocGen).install('doc').with_description(
        'Create documentation.')
    task(name='scaladoc', action=ScaladocGen).install('doc')

    # Bundling.
    task(name='create', action=JarCreate).install('jar')
    detect_duplicates = task(name='dup', action=DuplicateDetector)

    task(name='jvm', action=BinaryCreate).install('binary').with_description(
        'Create a runnable binary.')
    detect_duplicates.install('binary')

    task(name='jvm', action=BundleCreate).install('bundle').with_description(
        'Create an application bundle from binary targets.')
    detect_duplicates.install('bundle')

    task(name='detect-duplicates',
         action=DuplicateDetector).install().with_description(
             'Detect duplicate classes and resources on the classpath.')

    # Publishing.
    task(
        name='check_published_deps',
        action=CheckPublishedDeps,
    ).install('check_published_deps').with_description(
        'Find references to outdated artifacts.')

    task(name='jar', action=JarPublish).install('publish').with_description(
        'Publish artifacts.')

    # Testing.
    task(name='junit', action=JUnitRun).install('test').with_description(
        'Test compiled code.')
    task(name='bench', action=BenchmarkRun).install('bench').with_description(
        'Run benchmark tests.')

    # Running.
    task(name='jvm', action=JvmRun, serialize=False).install(
        'run').with_description('Run a binary target.')
    task(name='jvm-dirty', action=JvmRun,
         serialize=False).install('run-dirty').with_description(
             'Run a binary target, skipping compilation.')

    task(name='scala', action=ScalaRepl,
         serialize=False).install('repl').with_description('Run a REPL.')
    task(name='scala-dirty', action=ScalaRepl, serialize=False).install(
        'repl-dirty').with_description('Run a REPL, skipping compilation.')