Ejemplo n.º 1
0
    def execute(self, targets):
        # The repl session may last a while, allow concurrent pants activity during this pants idle
        # period.
        tools_classpath = self._jvm_tool_bootstrapper.get_jvm_tool_classpath(self._bootstrap_key)

        self.context.lock.release()
        self.save_stty_options()

        classpath = self.classpath(
            tools_classpath, confs=self.confs, exclusives_classpath=self.get_base_classpath_for_target(targets[0])
        )

        print("")  # Start REPL output on a new line.
        try:
            execute_java(
                classpath=classpath,
                main=self.main,
                jvm_options=self.jvm_args,
                args=self.args,
                workunit_factory=self.context.new_workunit,
                workunit_name="repl",
                workunit_labels=[WorkUnit.REPL, WorkUnit.JVM],
            )
        except KeyboardInterrupt:
            # TODO(John Sirois): Confirm with Steve Gury that finally does not work on mac and an
            # explicit catch of KeyboardInterrupt is required.
            pass
        self.restore_ssty_options()
Ejemplo n.º 2
0
    def runjava(self,
                classpath,
                main,
                jvm_options=None,
                args=None,
                workunit_name=None,
                workunit_labels=None):
        """Runs the java main using the given classpath and args.

    If --no-ng-daemons is specified then the java main is run in a freshly spawned subprocess,
    otherwise a persistent nailgun server dedicated to this Task subclass is used to speed up
    amortized run times.
    """
        executor = self.create_java_executor()
        try:
            return util.execute_java(
                classpath=classpath,
                main=main,
                jvm_options=jvm_options,
                args=args,
                executor=executor,
                workunit_factory=self.context.new_workunit,
                workunit_name=workunit_name,
                workunit_labels=workunit_labels)
        except executor.Error as e:
            raise TaskError(e)
Ejemplo n.º 3
0
  def execute(self, targets):
    # For rewriting JDK classes to work, the JAR file has to be listed specifically in
    # the JAR manifest as something that goes in the bootclasspath.
    # The MANIFEST list a jar 'allocation.jar' this is why we have to rename it
    agent_tools_classpath = self._jvm_tool_bootstrapper.get_jvm_tool_classpath(
        self._agent_bootstrap_key)
    agent_jar = agent_tools_classpath[0]
    allocation_jar = os.path.join(os.path.dirname(agent_jar), "allocation.jar")

    # TODO(Steve Gury): Find a solution to avoid copying the jar every run and being resilient
    # to version upgrade
    shutil.copyfile(agent_jar, allocation_jar)
    os.environ['ALLOCATION_JAR'] = str(allocation_jar)

    benchmark_tools_classpath = self._jvm_tool_bootstrapper.get_jvm_tool_classpath(
        self._benchmark_bootstrap_key)

    classpath = self.classpath(benchmark_tools_classpath,
                               confs=self.confs,
                               exclusives_classpath=self.get_base_classpath_for_target(targets[0]))

    caliper_main = 'com.google.caliper.Runner'
    exit_code = execute_java(classpath=classpath,
                             main=caliper_main,
                             jvm_options=self.jvm_args,
                             args=self.caliper_args,
                             workunit_factory=self.context.new_workunit,
                             workunit_name='caliper')
    if exit_code != 0:
      raise TaskError('java %s ... exited non-zero (%i)' % (caliper_main, exit_code))
Ejemplo n.º 4
0
    def execute(self, targets):
        # For rewriting JDK classes to work, the JAR file has to be listed specifically in
        # the JAR manifest as something that goes in the bootclasspath.
        # The MANIFEST list a jar 'allocation.jar' this is why we have to rename it
        agent_tools_classpath = self._jvm_tool_bootstrapper.get_jvm_tool_classpath(
            self._agent_bootstrap_key)
        agent_jar = agent_tools_classpath[0]
        allocation_jar = os.path.join(os.path.dirname(agent_jar),
                                      "allocation.jar")

        # TODO(Steve Gury): Find a solution to avoid copying the jar every run and being resilient
        # to version upgrade
        shutil.copyfile(agent_jar, allocation_jar)
        os.environ['ALLOCATION_JAR'] = str(allocation_jar)

        benchmark_tools_classpath = self._jvm_tool_bootstrapper.get_jvm_tool_classpath(
            self._benchmark_bootstrap_key)

        classpath = self.classpath(
            benchmark_tools_classpath,
            confs=self.confs,
            exclusives_classpath=self.get_base_classpath_for_target(
                targets[0]))

        caliper_main = 'com.google.caliper.Runner'
        exit_code = execute_java(classpath=classpath,
                                 main=caliper_main,
                                 jvm_options=self.jvm_args,
                                 args=self.caliper_args,
                                 workunit_factory=self.context.new_workunit,
                                 workunit_name='caliper')
        if exit_code != 0:
            raise TaskError('java %s ... exited non-zero (%i)' %
                            (caliper_main, exit_code))
Ejemplo n.º 5
0
                    def generate_reports():
                        args = [
                            'report', '-in', self.coverage_metadata_file,
                            '-in', self.coverage_file, '-exit'
                        ]
                        source_bases = set()

                        def collect_source_base(target):
                            if self.is_coverage_target(target):
                                source_bases.add(target.target_base)

                        for target in self.test_target_candidates(targets):
                            target.walk(collect_source_base)
                        for source_base in source_bases:
                            args.extend(['-sp', source_base])

                        sorting = [
                            '-Dreport.sort', '+name,+class,+method,+block'
                        ]
                        if self.coverage_report_console:
                            args.extend([
                                '-r', 'txt',
                                '-Dreport.txt.out.file=%s' %
                                self.coverage_console_file
                            ] + sorting)
                        if self.coverage_report_xml:
                            args.extend([
                                '-r', 'xml',
                                '-Dreport.xml.out.file=%s' %
                                self.coverage_xml_file
                            ])
                        if self.coverage_report_html:
                            args.extend([
                                '-r', 'html',
                                '-Dreport.html.out.file=%s' %
                                self.coverage_html_file,
                                '-Dreport.out.encoding=UTF-8'
                            ] + sorting)

                        main = 'emma'
                        result = execute_java(
                            classpath=emma_classpath,
                            main=main,
                            args=args,
                            workunit_factory=self.context.new_workunit,
                            workunit_name='emma-report')
                        if result != 0:
                            raise TaskError(
                                "java %s ... exited non-zero (%i)"
                                " 'failed to generate code coverage reports'" %
                                (main, result))

                        if self.coverage_report_console:
                            with safe_open(self.coverage_console_file
                                           ) as console_report:
                                sys.stdout.write(console_report.read())
                        if self.coverage_report_html_open:
                            binary_util.ui_open(self.coverage_html_file)
Ejemplo n.º 6
0
 def instrument_code():
   safe_mkdir(self.coverage_instrument_dir, clean=True)
   with binary_util.safe_args(self.get_coverage_patterns(targets)) as patterns:
     args = [
       'instr',
       '-out', self.coverage_metadata_file,
       '-d', self.coverage_instrument_dir,
       '-cp', os.pathsep.join(junit_classpath),
       '-exit'
     ]
     for pattern in patterns:
       args.extend(['-filter', pattern])
     main = 'emma'
     result = execute_java(classpath=emma_classpath, main=main, args=args,
                           workunit_factory=self.context.new_workunit,
                           workunit_name='emma-instrument')
     if result != 0:
       raise TaskError("java %s ... exited non-zero (%i)"
                       " 'failed to instrument'" % (main, result))
Ejemplo n.º 7
0
 def run_tests(classpath, main, jvm_args=None):
   # TODO(John Sirois): Integrated batching with the test runner.  As things stand we get
   # results summaries for example for each batch but no overall summary.
   # http://jira.local.twitter.com/browse/AWESOME-1114
   result = 0
   for batch in self._partition(tests):
     with binary_util.safe_args(batch) as batch_tests:
       result += abs(execute_java(
         classpath=classpath,
         main=main,
         jvm_options=(jvm_args or []) + self.jvm_args,
         args=self.opts + batch_tests,
         workunit_factory=self.context.new_workunit,
         workunit_name='run',
         workunit_labels=[WorkUnit.TEST]
       ))
       if result != 0 and self.fail_fast:
         break
   if result != 0:
     raise TaskError('java %s ... exited non-zero (%i)' % (main, result))
Ejemplo n.º 8
0
  def runjava(self, classpath, main, jvm_options=None, args=None, workunit_name=None,
              workunit_labels=None):
    """Runs the java main using the given classpath and args.

    If --no-ng-daemons is specified then the java main is run in a freshly spawned subprocess,
    otherwise a persistent nailgun server dedicated to this Task subclass is used to speed up
    amortized run times.
    """
    executor = self.create_java_executor()
    try:
      return util.execute_java(classpath=classpath,
                               main=main,
                               jvm_options=jvm_options,
                               args=args,
                               executor=executor,
                               workunit_factory=self.context.new_workunit,
                               workunit_name=workunit_name,
                               workunit_labels=workunit_labels)
    except executor.Error as e:
      raise TaskError(e)
Ejemplo n.º 9
0
          def generate_reports():
            args = [
              'report',
              '-in', self.coverage_metadata_file,
              '-in', self.coverage_file,
              '-exit'
            ]
            source_bases = set()
            def collect_source_base(target):
              if self.is_coverage_target(target):
                source_bases.add(target.target_base)
            for target in self.test_target_candidates(targets):
              target.walk(collect_source_base)
            for source_base in source_bases:
              args.extend(['-sp', source_base])

            sorting = ['-Dreport.sort', '+name,+class,+method,+block']
            if self.coverage_report_console:
              args.extend(['-r', 'txt',
                           '-Dreport.txt.out.file=%s' % self.coverage_console_file] + sorting)
            if self.coverage_report_xml:
              args.extend(['-r', 'xml','-Dreport.xml.out.file=%s' % self.coverage_xml_file])
            if self.coverage_report_html:
              args.extend(['-r', 'html',
                           '-Dreport.html.out.file=%s' % self.coverage_html_file,
                           '-Dreport.out.encoding=UTF-8'] + sorting)

            main = 'emma'
            result = execute_java(classpath=emma_classpath, main=main, args=args,
                                  workunit_factory=self.context.new_workunit,
                                  workunit_name='emma-report')
            if result != 0:
              raise TaskError("java %s ... exited non-zero (%i)"
                              " 'failed to generate code coverage reports'" % (main, result))

            if self.coverage_report_console:
              with safe_open(self.coverage_console_file) as console_report:
                sys.stdout.write(console_report.read())
            if self.coverage_report_html_open:
              binary_util.ui_open(self.coverage_html_file)
Ejemplo n.º 10
0
    def execute(self, targets):
        # The called binary may block for a while, allow concurrent pants activity during this pants
        # idle period.
        #
        # TODO(John Sirois): refactor lock so that I can do:
        # with self.context.lock.yield():
        #   - blocking code
        #
        # Currently re-acquiring the lock requires a path argument that was set up by the goal
        # execution engine.  I do not want task code to learn the lock location.
        # http://jira.local.twitter.com/browse/AWESOME-1317

        self.context.lock.release()
        # Run the first target that is a binary.
        binaries = filter(is_binary, targets)
        if len(binaries) > 0:  # We only run the first one.
            main = binaries[0].main
            egroups = self.context.products.get_data('exclusives_groups')
            group_key = egroups.get_group_key_for_target(binaries[0])
            group_classpath = egroups.get_classpath_for_group(group_key)

            executor = CommandLineGrabber(
            ) if self.only_write_cmd_line else None
            result = execute_java(classpath=(self.classpath(
                confs=self.confs, exclusives_classpath=group_classpath)),
                                  main=main,
                                  executor=executor,
                                  jvm_options=self.jvm_args,
                                  args=self.args,
                                  workunit_factory=self.context.new_workunit,
                                  workunit_name='run',
                                  workunit_labels=[WorkUnit.RUN])

            if self.only_write_cmd_line:
                with safe_open(self.only_write_cmd_line, 'w') as outfile:
                    outfile.write(' '.join(executor.cmd))
            elif result != 0:
                raise TaskError('java %s ... exited non-zero (%i)' %
                                (main, result),
                                exit_code=result)
Ejemplo n.º 11
0
 def run_tests(classpath, main, jvm_args=None):
     # TODO(John Sirois): Integrated batching with the test runner.  As things stand we get
     # results summaries for example for each batch but no overall summary.
     # http://jira.local.twitter.com/browse/AWESOME-1114
     result = 0
     for batch in self._partition(tests):
         with binary_util.safe_args(batch) as batch_tests:
             result += abs(
                 execute_java(
                     classpath=classpath,
                     main=main,
                     jvm_options=(jvm_args or []) +
                     self.jvm_args,
                     args=self.opts + batch_tests,
                     workunit_factory=self.context.new_workunit,
                     workunit_name='run',
                     workunit_labels=[WorkUnit.TEST]))
             if result != 0 and self.fail_fast:
                 break
     if result != 0:
         raise TaskError('java %s ... exited non-zero (%i)' %
                         (main, result))
Ejemplo n.º 12
0
    def execute(self, targets):
        # The called binary may block for a while, allow concurrent pants activity during this pants
        # idle period.
        #
        # TODO(John Sirois): refactor lock so that I can do:
        # with self.context.lock.yield():
        #   - blocking code
        #
        # Currently re-acquiring the lock requires a path argument that was set up by the goal
        # execution engine.  I do not want task code to learn the lock location.
        # http://jira.local.twitter.com/browse/AWESOME-1317

        self.context.lock.release()
        # Run the first target that is a binary.
        binaries = filter(is_binary, targets)
        if len(binaries) > 0:  # We only run the first one.
            main = binaries[0].main
            egroups = self.context.products.get_data("exclusives_groups")
            group_key = egroups.get_group_key_for_target(binaries[0])
            group_classpath = egroups.get_classpath_for_group(group_key)

            executor = CommandLineGrabber() if self.only_write_cmd_line else None
            result = execute_java(
                classpath=(self.classpath(confs=self.confs, exclusives_classpath=group_classpath)),
                main=main,
                executor=executor,
                jvm_options=self.jvm_args,
                args=self.args,
                workunit_factory=self.context.new_workunit,
                workunit_name="run",
                workunit_labels=[WorkUnit.RUN],
            )

            if self.only_write_cmd_line:
                with safe_open(self.only_write_cmd_line, "w") as outfile:
                    outfile.write(" ".join(executor.cmd))
            elif result != 0:
                raise TaskError("java %s ... exited non-zero (%i)" % (main, result), exit_code=result)
Ejemplo n.º 13
0
      def run_tests(tests):
        args = ['--color'] if self.color else []
        args.append('--specs=%s' % ','.join(tests))
        specs_runner_main = 'com.twitter.common.testing.ExplicitSpecsRunnerMain'

        bootstrapped_cp = self._jvm_tool_bootstrapper.get_jvm_tool_classpath(
            self._specs_bootstrap_key)
        classpath = self.classpath(
            bootstrapped_cp,
            confs=self.confs,
            exclusives_classpath=self.get_base_classpath_for_target(targets[0]))

        result = execute_java(
          classpath=classpath,
          main=specs_runner_main,
          jvm_options=self._jvm_options,
          args=args,
          workunit_factory=self.context.new_workunit,
          workunit_name='specs',
          workunit_labels=[WorkUnit.TEST]
        )
        if result != 0:
          raise TaskError('java %s ... exited non-zero (%i)' % (specs_runner_main, result))
Ejemplo n.º 14
0
 def instrument_code():
     safe_mkdir(self.coverage_instrument_dir, clean=True)
     with binary_util.safe_args(
             self.get_coverage_patterns(
                 targets)) as patterns:
         args = [
             'instr', '-out', self.coverage_metadata_file,
             '-d', self.coverage_instrument_dir, '-cp',
             os.pathsep.join(junit_classpath), '-exit'
         ]
         for pattern in patterns:
             args.extend(['-filter', pattern])
         main = 'emma'
         result = execute_java(
             classpath=emma_classpath,
             main=main,
             args=args,
             workunit_factory=self.context.new_workunit,
             workunit_name='emma-instrument')
         if result != 0:
             raise TaskError(
                 "java %s ... exited non-zero (%i)"
                 " 'failed to instrument'" % (main, result))
Ejemplo n.º 15
0
            def run_tests(tests):
                args = ['--color'] if self.color else []
                args.append('--specs=%s' % ','.join(tests))
                specs_runner_main = 'com.twitter.common.testing.ExplicitSpecsRunnerMain'

                bootstrapped_cp = self._jvm_tool_bootstrapper.get_jvm_tool_classpath(
                    self._specs_bootstrap_key)
                classpath = self.classpath(
                    bootstrapped_cp,
                    confs=self.confs,
                    exclusives_classpath=self.get_base_classpath_for_target(
                        targets[0]))

                result = execute_java(
                    classpath=classpath,
                    main=specs_runner_main,
                    jvm_options=self._jvm_options,
                    args=args,
                    workunit_factory=self.context.new_workunit,
                    workunit_name='specs',
                    workunit_labels=[WorkUnit.TEST])
                if result != 0:
                    raise TaskError('java %s ... exited non-zero (%i)' %
                                    (specs_runner_main, result))