예제 #1
0
파일: jvm_run.py 프로젝트: sikopet/pants
    def execute(self):
        # 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
        target = self.require_single_root_target()

        working_dir = None
        cwd_opt = self.get_options().cwd
        if cwd_opt != _CWD_NOT_PRESENT:
            working_dir = self.get_options().cwd
            if not working_dir:
                working_dir = target.address.spec_path
        logger.debug("Working dir is {0}".format(working_dir))

        if isinstance(target, JvmApp):
            binary = target.binary
        else:
            binary = target

        # We can't throw if binary isn't a JvmBinary, because perhaps we were called on a
        # python_binary, in which case we have to no-op and let python_run do its thing.
        # TODO(benjy): Some more elegant way to coordinate how tasks claim targets.
        if isinstance(binary, JvmBinary):
            executor = CommandLineGrabber(
            ) if self.only_write_cmd_line else None
            self.context.release_lock()
            exclusives_classpath = self.get_base_classpath_for_target(binary)
            result = execute_java(
                classpath=(self.classpath(
                    confs=self.confs,
                    exclusives_classpath=exclusives_classpath)),
                main=binary.main,
                executor=executor,
                jvm_options=self.jvm_options,
                args=self.args,
                workunit_factory=self.context.new_workunit,
                workunit_name='run',
                workunit_labels=[WorkUnit.RUN],
                cwd=working_dir,
            )

            if self.only_write_cmd_line:
                with safe_open(expand_path(self.only_write_cmd_line),
                               'w') as outfile:
                    outfile.write(' '.join(executor.cmd))
            elif result != 0:
                raise TaskError('java %s ... exited non-zero (%i)' %
                                (binary.main, result),
                                exit_code=result)
예제 #2
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)
예제 #3
0
파일: jvm_run.py 프로젝트: mcguigan/pants
    def execute(self):
        # 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
        target = self.require_single_root_target()

        working_dir = None
        cwd_opt = self.get_options().cwd
        if cwd_opt != _CWD_NOT_PRESENT:
            working_dir = self.get_options().cwd
            if not working_dir:
                working_dir = target.address.spec_path
        logger.debug(f"Working dir is {working_dir}")

        if isinstance(target, JvmApp):
            binary = target.binary
        else:
            binary = target

        # This task is installed in the "run" goal.
        # This means that, when invoked with ./pants run, it will run regardless of whether
        # the target is a jvm target.
        # As a result, not all targets passed here will have good defaults for extra_jvm_options
        extra_jvm_options = binary.payload.get_field_value(
            "extra_jvm_options", [])

        # We can't throw if binary isn't a JvmBinary, because perhaps we were called on a
        # python_binary, in which case we have to no-op and let python_run do its thing.
        # TODO(benjy): Some more elegant way to coordinate how tasks claim targets.
        if isinstance(binary, JvmBinary):
            jvm = self.preferred_jvm_distribution_for_targets([binary])
            executor = CommandLineGrabber(
                jvm) if self.only_write_cmd_line else None
            self.context.release_lock()
            with self.context.new_workunit(name='run',
                                           labels=[WorkUnitLabel.RUN]):
                result = jvm.execute_java(
                    classpath=self.classpath([target]),
                    main=self.get_options().main or binary.main,
                    executor=executor,
                    jvm_options=self.jvm_options + extra_jvm_options,
                    args=self.args,
                    cwd=working_dir,
                    synthetic_jar_dir=self.workdir,
                    create_synthetic_jar=self.synthetic_classpath)

            if self.only_write_cmd_line:
                with safe_open(expand_path(self.only_write_cmd_line),
                               'w') as outfile:
                    outfile.write(' '.join(executor.cmd))
            elif result != 0:
                raise TaskError(
                    f'java {binary.main} ... exited non-zero ({result})',
                    exit_code=result)