コード例 #1
0
ファイル: goal_runner.py プロジェクト: UrbanCompass/pants
    def run(self):
        def fail():
            self.run_tracker.set_root_outcome(WorkUnit.FAILURE)

        kill_nailguns = self.options.for_global_scope().kill_nailguns
        try:
            result = self._do_run()
            if result:
                fail()
        except KeyboardInterrupt:
            fail()
            # On ctrl-c we always kill nailguns, otherwise they might keep running
            # some heavyweight compilation and gum up the system during a subsequent run.
            kill_nailguns = True
            raise
        except Exception:
            fail()
            raise
        finally:
            self.run_tracker.end()
            # Must kill nailguns only after run_tracker.end() is called, otherwise there may still
            # be pending background work that needs a nailgun.
            if kill_nailguns:
                # TODO: This is JVM-specific and really doesn't belong here.
                # TODO: Make this more selective? Only kill nailguns that affect state?
                # E.g., checkstyle may not need to be killed.
                NailgunTask.killall()
        return result
コード例 #2
0
ファイル: goal_runner.py プロジェクト: dominichamon/pants
  def run(self):
    def fail():
      self.run_tracker.set_root_outcome(WorkUnit.FAILURE)

    kill_nailguns = self.options.for_global_scope().kill_nailguns
    try:
      result = self._do_run()
      if result:
        fail()
    except KeyboardInterrupt:
      fail()
      # On ctrl-c we always kill nailguns, otherwise they might keep running
      # some heavyweight compilation and gum up the system during a subsequent run.
      kill_nailguns = True
      raise
    except Exception:
      fail()
      raise
    finally:
      self.run_tracker.end()
      # Must kill nailguns only after run_tracker.end() is called, otherwise there may still
      # be pending background work that needs a nailgun.
      if kill_nailguns:
        # TODO: This is JVM-specific and really doesn't belong here.
        # TODO: Make this more selective? Only kill nailguns that affect state?
        # E.g., checkstyle may not need to be killed.
        NailgunTask.killall()
    return result
コード例 #3
0
  def __init__(self, context, workdir):
    NailgunTask.__init__(self, context, workdir)

    self.args = context.config.getlist('spindle-gen', 'args', [])
    self.jvm_options = context.config.getlist('spindle-gen', 'jvm_options', [])
    self.main_class = context.config.get(
      'spindle-gen',
      'main_class',
      default='com.foursquare.spindle.codegen.binary.ThriftCodegen',
    )

    self._spindle_bootstrap_key = 'spindle'
    bootstrap_tools = context.config.getlist('spindle-gen', 'bootstrap-tools')
    self._jvm_tool_bootstrapper.register_jvm_tool(self._spindle_bootstrap_key, bootstrap_tools)

    self.scalate_workdir = os.path.join(workdir, 'scalate_workdir')
    self.namespace_out = os.path.join(workdir, 'scala_record')

    self.setup_artifact_cache_from_config(config_section='spindle-gen')
    self.template = context.config.getdict('spindle-gen', 'scala_record', {}).get('template')
    self.javaTemplate = context.config.getdict('spindle-gen', 'scala_record', {}).get('javaTemplate')
コード例 #4
0
 def tearDownClass(cls):
     # Kill any nailguns launched in our ephemeral build root
     NailgunTask.killall()
コード例 #5
0
def _run():
  """
  To add additional paths to sys.path, add a block to the config similar to the following:
  [main]
  roots: ['src/python/pants_internal/test/',]
  """
  version = get_version()
  if len(sys.argv) == 2 and sys.argv[1] == _VERSION_OPTION:
    _do_exit(version)

  root_dir = get_buildroot()
  if not os.path.exists(root_dir):
    _exit_and_fail('PANTS_BUILD_ROOT does not point to a valid path: %s' % root_dir)

  if len(sys.argv) < 2:
    argv = ['goal']
  else:
    argv = sys.argv[1:]
  # Hack to force ./pants -h etc. to redirect to goal.
  if argv[0] != 'goal' and set(['-h', '--help', 'help']).intersection(argv):
    argv = ['goal'] + argv

  parser = optparse.OptionParser(add_help_option=False, version=version)
  RcFile.install_disable_rc_option(parser)
  parser.add_option(_LOG_EXIT_OPTION,
                    action='store_true',
                    default=False,
                    dest='log_exit',
                    help = 'Log an exit message on success or failure.')

  config = Config.load()

  # XXX(wickman) This should be in the command goal, not un pants_exe.py!
  run_tracker = RunTracker.from_config(config)
  report = initial_reporting(config, run_tracker)
  run_tracker.start(report)

  url = run_tracker.run_info.get_info('report_url')
  if url:
    run_tracker.log(Report.INFO, 'See a report at: %s' % url)
  else:
    run_tracker.log(Report.INFO, '(To run a reporting server: ./pants goal server)')

  build_file_parser = BuildFileParser(root_dir=root_dir, run_tracker=run_tracker)
  build_graph = BuildGraph(run_tracker=run_tracker)

  additional_backends = config.getlist('backends', 'packages')
  load_backends_from_source(build_file_parser, additional_backends=additional_backends)

  command_class, command_args = _parse_command(root_dir, argv)
  command = command_class(run_tracker,
                          root_dir,
                          parser,
                          command_args,
                          build_file_parser,
                          build_graph)
  try:
    if command.serialized():
      def onwait(pid):
        process = psutil.Process(pid)
        print('Waiting on pants process %d (%s) to complete' %
              (pid, ' '.join(process.cmdline)), file=sys.stderr)
        return True
      runfile = os.path.join(root_dir, '.pants.run')
      lock = Lock.acquire(runfile, onwait=onwait)
    else:
      lock = Lock.unlocked()
    try:
      result = command.run(lock)
      if result:
        run_tracker.set_root_outcome(WorkUnit.FAILURE)
      _do_exit(result)
    except KeyboardInterrupt:
      command.cleanup()
      raise
    finally:
      lock.release()
  finally:
    run_tracker.end()
    # Must kill nailguns only after run_tracker.end() is called, because there may still
    # be pending background work that needs a nailgun.
    if (hasattr(command.options, 'cleanup_nailguns') and command.options.cleanup_nailguns) \
        or config.get('nailgun', 'autokill', default=False):
      NailgunTask.killall(None)
コード例 #6
0
ファイル: goal_runner.py プロジェクト: patricklaw/pants
 def cleanup(self):
     # TODO: This is JVM-specific and really doesn't belong here.
     # TODO: Make this more selective? Only kill nailguns that affect state? E.g., checkstyle
     # may not need to be killed.
     NailgunTask.killall(log.info)
     sys.exit(1)
コード例 #7
0
ファイル: pants_exe.py プロジェクト: ankurgarg1986/pants
def _run():
  # Place the registration of the unhandled exception hook as early as possible in the code.
  sys.excepthook = _unhandled_exception_hook

  """
  To add additional paths to sys.path, add a block to the config similar to the following:
  [main]
  roots: ['src/python/pants_internal/test/',]
  """

  logging.basicConfig()
  version = pants_version()
  if len(sys.argv) == 2 and sys.argv[1] == _VERSION_OPTION:
    _do_exit(msg=version, out=sys.stdout)

  root_dir = get_buildroot()
  if not os.path.exists(root_dir):
    _exit_and_fail('PANTS_BUILD_ROOT does not point to a valid path: %s' % root_dir)

  if len(sys.argv) < 2:
    argv = ['goal']
  else:
    argv = sys.argv[1:]
  # Hack to force ./pants -h etc. to redirect to goal.
  if argv[0] != 'goal' and set(['-h', '--help', 'help']).intersection(argv):
    argv = ['goal'] + argv

  parser = optparse.OptionParser(add_help_option=False, version=version)
  RcFile.install_disable_rc_option(parser)
  parser.add_option(_LOG_EXIT_OPTION,
                    action='store_true',
                    default=False,
                    dest='log_exit',
                    help='Log an exit message on success or failure.')

  config = Config.load()

  # XXX(wickman) This should be in the command goal, not in pants_exe.py!
  run_tracker = RunTracker.from_config(config)
  report = initial_reporting(config, run_tracker)
  run_tracker.start(report)

  url = run_tracker.run_info.get_info('report_url')
  if url:
    run_tracker.log(Report.INFO, 'See a report at: %s' % url)
  else:
    run_tracker.log(Report.INFO, '(To run a reporting server: ./pants goal server)')

  backend_packages = config.getlist('backends', 'packages')
  build_configuration = load_build_configuration_from_source(additional_backends=backend_packages)
  build_file_parser = BuildFileParser(build_configuration=build_configuration,
                                      root_dir=root_dir,
                                      run_tracker=run_tracker)
  address_mapper = BuildFileAddressMapper(build_file_parser)
  build_graph = BuildGraph(run_tracker=run_tracker, address_mapper=address_mapper)

  command_class, command_args = _parse_command(root_dir, argv)
  command = command_class(run_tracker,
                          root_dir,
                          parser,
                          command_args,
                          build_file_parser,
                          address_mapper,
                          build_graph)
  try:
    if command.serialized():
      def onwait(pid):
        process = psutil.Process(pid)
        print('Waiting on pants process %d (%s) to complete' %
              (pid, ' '.join(process.cmdline)), file=sys.stderr)
        return True
      runfile = os.path.join(root_dir, '.pants.run')
      lock = Lock.acquire(runfile, onwait=onwait)
    else:
      lock = Lock.unlocked()
    try:
      result = command.run(lock)
      if result:
        run_tracker.set_root_outcome(WorkUnit.FAILURE)
      _do_exit(result)
    except KeyboardInterrupt:
      command.cleanup()
      raise
    except Exception:
      run_tracker.set_root_outcome(WorkUnit.FAILURE)
      raise
    finally:
      lock.release()
  finally:
    run_tracker.end()
    # Must kill nailguns only after run_tracker.end() is called, because there may still
    # be pending background work that needs a nailgun.
    if (hasattr(command.old_options, 'cleanup_nailguns') and command.old_options.cleanup_nailguns) \
        or config.get('nailgun', 'autokill', default=False):
      NailgunTask.killall(None)
コード例 #8
0
 def tearDownClass(cls):
   # Kill any nailguns launched in our ephemeral build root
   NailgunTask.killall()
コード例 #9
0
 def cleanup(self):
     # TODO: This is JVM-specific and really doesn't belong here.
     # TODO: Make this more selective? Only kill nailguns that affect state? E.g., checkstyle
     # may not need to be killed.
     NailgunTask.killall(log.info)
     sys.exit(1)