Пример #1
0
  def create_binary(self, binary):
    import platform
    safe_mkdir(self.outdir)

    jarmap = self.context.products.get('jars')

    binary_jarname = '%s.jar' % binary.basename
    binaryjarpath = os.path.join(self.outdir, binary_jarname)
    self.context.log.info('creating %s' % os.path.relpath(binaryjarpath, get_buildroot()))

    with open_jar(binaryjarpath, 'w', compression=self.compression, allowZip64=self.zip64) as jar:
      def add_jars(target):
        generated = jarmap.get(target)
        if generated:
          for basedir, jars in generated.items():
            for internaljar in jars:
              self.dump(os.path.join(basedir, internaljar), jar)

      binary.walk(add_jars, lambda t: t.is_internal)

      if self.deployjar:
        for basedir, externaljar in self.list_jar_dependencies(binary):
          self.dump(os.path.join(basedir, externaljar), jar)

      manifest = Manifest()
      manifest.addentry(Manifest.MANIFEST_VERSION, '1.0')
      manifest.addentry(
        Manifest.CREATED_BY,
        'python %s pants %s (Twitter, Inc.)' % (platform.python_version(), get_version())
      )
      main = binary.main or '*** java -jar not supported, please use -cp and pick a main ***'
      manifest.addentry(Manifest.MAIN_CLASS,  main)
      jar.writestr(Manifest.PATH, manifest.contents())

      jarmap.add(binary, self.outdir, [binary_jarname])
Пример #2
0
def _run():
  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 or (len(sys.argv) == 2 and sys.argv[1] in _HELP_ALIASES):
    _help(version, root_dir)

  command_class, command_args = _parse_command(root_dir, sys.argv[1:])

  parser = optparse.OptionParser(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()
  run_tracker = RunTracker(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 server)')

  command = command_class(run_tracker, root_dir, parser, command_args)
  try:
    if command.serialized():
      def onwait(pid):
        print('Waiting on pants process %s to complete' % _process_info(pid), 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)
      _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)
Пример #3
0
    def create_binary(self, binary):
        import platform
        safe_mkdir(self.outdir)

        jarmap = self.context.products.get('jars')

        binary_jarname = '%s.jar' % binary.basename
        binaryjarpath = os.path.join(self.outdir, binary_jarname)
        self.context.log.info('creating %s' %
                              os.path.relpath(binaryjarpath, get_buildroot()))

        with open_jar(binaryjarpath,
                      'w',
                      compression=self.compression,
                      allowZip64=self.zip64) as jar:

            def add_jars(target):
                generated = jarmap.get(target)
                if generated:
                    for basedir, jars in generated.items():
                        for internaljar in jars:
                            self.dump(os.path.join(basedir, internaljar), jar)

            binary.walk(add_jars, lambda t: t.is_internal)

            if self.deployjar:
                for basedir, externaljar in self.list_jar_dependencies(binary):
                    self.dump(os.path.join(basedir, externaljar), jar)

            def write_binary_data(product_type):
                data = self.context.products.get_data(product_type).get(binary)
                if data:
                    for root, rel_paths in data.rel_paths():
                        for rel_path in rel_paths:
                            jar.write(os.path.join(root, rel_path),
                                      arcname=rel_path)

            write_binary_data('classes_by_target')
            write_binary_data('resources_by_target')

            manifest = Manifest()
            manifest.addentry(Manifest.MANIFEST_VERSION, '1.0')
            manifest.addentry(
                Manifest.CREATED_BY, 'python %s pants %s (Twitter, Inc.)' %
                (platform.python_version(), get_version()))
            main = binary.main or '*** java -jar not supported, please use -cp and pick a main ***'
            manifest.addentry(Manifest.MAIN_CLASS, main)
            jar.writestr(Manifest.PATH, manifest.contents())

            jarmap.add(binary, self.outdir, [binary_jarname])
Пример #4
0
def _run():
  """
  To add additional paths to sys.path, add a block to the config similar to the following:
  [main]
  roots: ['src/python/twitter/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 or (len(sys.argv) == 2 and sys.argv[1] in _HELP_ALIASES):
    _help(version, root_dir)

  command_class, command_args = _parse_command(root_dir, sys.argv[1:])

  parser = optparse.OptionParser(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()

  # TODO: This can be replaced once extensions are enabled with
  # https://github.com/pantsbuild/pants/issues/5
  roots = config.getlist('parse', 'roots', default=[])
  sys.path.extend(map(lambda root: os.path.join(root_dir, root), roots))

  # 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 server)')

  command = command_class(run_tracker, root_dir, parser, command_args)
  try:
    if command.serialized():
      def onwait(pid):
        print('Waiting on pants process %s to complete' % _process_info(pid), 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)
      _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)
Пример #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/twitter/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 or (len(sys.argv) == 2
                             and sys.argv[1] in _HELP_ALIASES):
        _help(version, root_dir)

    command_class, command_args = _parse_command(root_dir, sys.argv[1:])

    parser = optparse.OptionParser(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()

    # TODO: This can be replaced once extensions are enabled with
    # https://github.com/pantsbuild/pants/issues/5
    roots = config.getlist('parse', 'roots', default=[])
    sys.path.extend(map(lambda root: os.path.join(root_dir, root), roots))

    # 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 server)')

    command = command_class(run_tracker, root_dir, parser, command_args)
    try:
        if command.serialized():

            def onwait(pid):
                print('Waiting on pants process %s to complete' %
                      _process_info(pid),
                      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)
            _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)