コード例 #1
0
    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

        # Some targets will not have extra_jvm_options in their payload,
        # so we can't access it with target.payload.extra_jvm_options
        extra_jvm_options = target.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 = DistributionLocator.cached()
            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('java {} ... exited non-zero ({})'.format(
                    binary.main, result),
                                exit_code=result)
コード例 #2
0
ファイル: jvm_run.py プロジェクト: cosmicexplorer/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

    # 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 = DistributionLocator.cached()
      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('java {} ... exited non-zero ({})'.format(binary.main, result),
                        exit_code=result)
コード例 #3
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)
コード例 #4
0
ファイル: jvm_run.py プロジェクト: digideskio/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)
コード例 #5
0
ファイル: jvm_run.py プロジェクト: scalameta/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):
            platform = binary.runtime_platform
            jvm = self.preferred_jvm_distribution([platform])
            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 +
                                 list(platform.jvm_options) +
                                 list(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)
コード例 #6
0
ファイル: test_expand_path.py プロジェクト: Yasumoto/pants
 def test_env_var_expansion(self):
   with self.root() as root:
     with environment_as(A='B', C='D'):
       self.assertEquals(os.path.join(root, 'B/D/E'), expand_path('$A/${C}/E'))
コード例 #7
0
ファイル: test_expand_path.py プロジェクト: Yasumoto/pants
 def test_user_expansion(self):
   with environment_as(HOME='/tmp/jake'):
     self.assertEquals('/tmp/jake/bob', expand_path('~/bob'))
コード例 #8
0
ファイル: test_expand_path.py プロジェクト: Yasumoto/pants
 def test_absolute(self):
   self.assertEquals('/tmp/jake/bob', expand_path('/tmp/jake/bob'))
コード例 #9
0
ファイル: test_expand_path.py プロジェクト: Yasumoto/pants
 def test_dot_relative(self):
   with self.root() as root:
     self.assertEquals(os.path.join(root, 'a'), expand_path('./a'))
コード例 #10
0
 def test_pure_relative(self):
   with self.root() as root:
     self.assertEqual(os.path.join(root, 'a'), expand_path('a'))
コード例 #11
0
ファイル: test_expand_path.py プロジェクト: wiwa/pants
 def test_user_expansion(self):
     with environment_as(HOME="/tmp/jake"):
         self.assertEqual("/tmp/jake/bob", expand_path("~/bob"))
コード例 #12
0
ファイル: test_expand_path.py プロジェクト: youprofit/pants
 def test_absolute(self):
   self.assertEquals('/tmp/jake/bob', expand_path('/tmp/jake/bob'))
コード例 #13
0
ファイル: test_expand_path.py プロジェクト: youprofit/pants
 def test_dot_relative(self):
   with self.root() as root:
     self.assertEquals(os.path.join(root, 'a'), expand_path('./a'))
コード例 #14
0
 def test_pure_relative(self):
   with self.root() as root:
     self.assertEqual(os.path.join(root, 'a'), expand_path('a'))
コード例 #15
0
ファイル: test_expand_path.py プロジェクト: wiwa/pants
 def test_dot_relative(self):
     with self.root() as root:
         self.assertEqual(os.path.join(root, "a"), expand_path("./a"))
コード例 #16
0
ファイル: test_expand_path.py プロジェクト: wiwa/pants
 def test_absolute(self):
     self.assertEqual("/tmp/jake/bob", expand_path("/tmp/jake/bob"))
コード例 #17
0
ファイル: test_expand_path.py プロジェクト: youprofit/pants
 def test_user_expansion(self):
   with environment_as(HOME='/tmp/jake'):
     self.assertEquals('/tmp/jake/bob', expand_path('~/bob'))
コード例 #18
0
ファイル: test_expand_path.py プロジェクト: wiwa/pants
 def test_env_var_expansion(self):
     with self.root() as root:
         with environment_as(A="B", C="D"):
             self.assertEqual(os.path.join(root, "B/D/E"),
                              expand_path("$A/${C}/E"))
コード例 #19
0
ファイル: test_expand_path.py プロジェクト: youprofit/pants
 def test_env_var_expansion(self):
   with self.root() as root:
     with environment_as(A='B', C='D'):
       self.assertEquals(os.path.join(root, 'B/D/E'), expand_path('$A/${C}/E'))