Beispiel #1
0
  def compute_dependency_specs(cls, kwargs=None, payload=None):
    for spec in super(JavacPlugin, cls).compute_dependency_specs(kwargs, payload):
      yield spec

    yield (
      Java.global_instance().injectables_spec_for_key('javac') or
      Java.global_instance().injectables_spec_for_key('tools.jar')
    )
Beispiel #2
0
    def _compile_vts(self, vts, ctx, upstream_analysis, dependency_classpath,
                     progress_message, settings, compiler_option_sets,
                     zinc_file_manager, counter):
        """Compiles sources for the given vts into the given output dir.

    :param vts: VersionedTargetSet with one entry for the target.
    :param ctx: - A CompileContext instance for the target.
    :param dependency_classpath: A list of classpath entries of type ClasspathEntry for dependencies

    May be invoked concurrently on independent target sets.

    Postcondition: The individual targets in vts are up-to-date, as if each were
                   compiled individually.
    """
        if not ctx.sources:
            self.context.log.warn(
                'Skipping {} compile for targets with no sources:\n  {}'.
                format(self.name(), vts.targets))
        else:
            counter_val = str(counter()).rjust(counter.format_length(), ' ')
            counter_str = '[{}/{}] '.format(counter_val, counter.size)
            # Do some reporting.
            self.context.log.info(
                counter_str, 'Compiling ',
                items_to_report_element(ctx.sources,
                                        '{} source'.format(self.name())),
                ' in ',
                items_to_report_element(
                    [t.address.reference() for t in vts.targets], 'target'),
                ' (', progress_message, ').')
            with self.context.new_workunit('compile',
                                           labels=[WorkUnitLabel.COMPILER
                                                   ]) as compile_workunit:
                try:
                    directory_digest = self.compile(
                        ctx,
                        self._args,
                        dependency_classpath,
                        upstream_analysis,
                        settings,
                        compiler_option_sets,
                        zinc_file_manager,
                        self._get_plugin_map('javac', Java.global_instance(),
                                             ctx.target),
                        self._get_plugin_map('scalac',
                                             ScalaPlatform.global_instance(),
                                             ctx.target),
                    )
                    self._capture_logs(compile_workunit, ctx.log_dir)
                    return directory_digest
                except TaskError:
                    if self.get_options().suggest_missing_deps:
                        logs = [
                            path for _, name, _, path in self._find_logs(
                                compile_workunit) if name == self.name()
                        ]
                        if logs:
                            self._find_missing_deps(logs, ctx.target)
                    raise
Beispiel #3
0
  def javac_compiler_plugins_src(self, zinc_compile_instance=None):
    """Returns an instance of JvmToolMixin that should provide javac compiler plugins.

    TODO: Remove this method once the deprecation of `(scalac|javac)_plugins` on Zinc has
    completed in `1.9.0.dev0`.
    """
    return Zinc._select_jvm_tool_mixin(zinc_compile_instance,
                                       Java.global_instance(),
                                       ['javac_plugins', 'javac_plugin_args', 'javac_plugin_dep'])
Beispiel #4
0
  def javac_compiler_plugins_src(self, zinc_compile_instance=None):
    """Returns an instance of JvmToolMixin that should provide javac compiler plugins.

    TODO: Remove this method once the deprecation of `(scalac|javac)_plugins` on Zinc has
    completed in `1.9.0.dev0`.
    """
    return Zinc._select_jvm_tool_mixin(zinc_compile_instance,
                                       Java.global_instance(),
                                       ['javac_plugins', 'javac_plugin_args', 'javac_plugin_dep'])
Beispiel #5
0
  def _compiler_plugins_cp_entries(self):
    """Any additional global compiletime classpath entries for compiler plugins."""
    java_options_src = Java.global_instance()
    scala_options_src = ScalaPlatform.global_instance()

    def cp(instance, toolname):
      scope = instance.options_scope
      return instance.tool_classpath_from_products(self._products, toolname, scope=scope)
    classpaths = (cp(java_options_src, 'javac-plugin-dep') +
                  cp(scala_options_src, 'scalac-plugin-dep'))
    return [(conf, ClasspathEntry(jar)) for conf in self.DEFAULT_CONFS for jar in classpaths]
Beispiel #6
0
  def _compiler_plugins_cp_entries(self):
    """Any additional global compiletime classpath entries for compiler plugins."""
    java_options_src = Java.global_instance()
    scala_options_src = ScalaPlatform.global_instance()

    def cp(instance, toolname):
      scope = instance.options_scope
      return instance.tool_classpath_entries_from_products(self._products, toolname, scope=scope)
    classpaths = (cp(java_options_src, 'javac-plugin-dep') +
                  cp(scala_options_src, 'scalac-plugin-dep'))
    return [(conf, jar) for conf in self.DEFAULT_CONFS for jar in classpaths]
Beispiel #7
0
  def _compile_vts(self, vts, ctx, upstream_analysis, classpath, progress_message, settings, 
                   compiler_option_sets, zinc_file_manager, counter):
    """Compiles sources for the given vts into the given output dir.

    :param vts: VersionedTargetSet with one entry for the target.
    :param ctx: - A CompileContext instance for the target.
    :param classpath: A list of classpath entries

    May be invoked concurrently on independent target sets.

    Postcondition: The individual targets in vts are up-to-date, as if each were
                   compiled individually.
    """
    if not ctx.sources:
      self.context.log.warn('Skipping {} compile for targets with no sources:\n  {}'
                            .format(self.name(), vts.targets))
    else:
      counter_val = str(counter()).rjust(counter.format_length(), b' ')
      counter_str = '[{}/{}] '.format(counter_val, counter.size)
      # Do some reporting.
      self.context.log.info(
        counter_str,
        'Compiling ',
        items_to_report_element(ctx.sources, '{} source'.format(self.name())),
        ' in ',
        items_to_report_element([t.address.reference() for t in vts.targets], 'target'),
        ' (',
        progress_message,
        ').')
      with self.context.new_workunit('compile', labels=[WorkUnitLabel.COMPILER]) as compile_workunit:
        if self.get_options().capture_classpath:
          self._record_compile_classpath(classpath, vts.targets, ctx.classes_dir)

        try:
          self.compile(
            ctx,
            self._args,
            classpath,
            upstream_analysis,
            settings,
            compiler_option_sets,
            zinc_file_manager,
            self._get_plugin_map('javac', Java.global_instance(), ctx.target),
            self._get_plugin_map('scalac', ScalaPlatform.global_instance(), ctx.target),
          )
          self._capture_logs(compile_workunit, ctx.log_dir)
        except TaskError:
          if self.get_options().suggest_missing_deps:
            logs = [path
                    for _, name, _, path in self._find_logs(compile_workunit)
                    if name == self.name()]
            if logs:
              self._find_missing_deps(logs, ctx.target)
          raise
Beispiel #8
0
    def create_extra_products_for_targets(self, targets):
        if not targets:
            return
        if self.context.products.is_required_data("zinc_args"):
            zinc_args = self.context.products.get_data("zinc_args")
            with self.invalidated(
                    targets, invalidate_dependents=False,
                    topological_order=True) as invalidation_check:

                compile_contexts = {
                    vt.target:
                    self.create_compile_context(vt.target, vt.results_dir)
                    for vt in invalidation_check.all_vts
                }
                runtime_compile_contexts = {
                    target: self.select_runtime_context(cc)
                    for target, cc in compile_contexts.items()
                }
                for vt in invalidation_check.all_vts:
                    dependency_classpath = self._zinc.compile_classpath_entries(
                        "runtime_classpath",
                        vt.target,
                        extra_cp_entries=self._extra_compile_time_classpath,
                    )
                    dep_context = DependencyContext.global_instance()
                    compiler_option_sets = dep_context.defaulted_property(
                        vt.target, "compiler_option_sets")
                    zinc_file_manager = dep_context.defaulted_property(
                        vt.target, "zinc_file_manager")
                    ctx = runtime_compile_contexts[vt.target]
                    absolute_classpath = (ctx.classes_dir.path, ) + tuple(
                        ce.path for ce in dependency_classpath)
                    upstream_analysis = dict(
                        self._upstream_analysis(compile_contexts,
                                                dependency_classpath))
                    zinc_args[vt.target] = self.create_zinc_args(
                        ctx,
                        self._args,
                        upstream_analysis,
                        absolute_classpath,
                        vt.target.platform,
                        compiler_option_sets,
                        zinc_file_manager,
                        self._get_plugin_map("javac", Java.global_instance(),
                                             ctx.target),
                        self._get_plugin_map("scalac",
                                             ScalaPlatform.global_instance(),
                                             ctx.target),
                    )
  def defaulted_property(self, target, option_name):
    """Computes a language property setting for the given JvmTarget.

    :param selector A function that takes a target or platform and returns the boolean value of the
                    property for that target or platform, or None if that target or platform does
                    not directly define the property.

    If the target does not override the language property, returns true iff the property
    is true for any of the matched languages for the target.
    """
    if target.has_sources('.java'):
      matching_subsystem = Java.global_instance()
    elif target.has_sources('.scala'):
      matching_subsystem = ScalaPlatform.global_instance()
    else:
      return getattr(target, option_name)

    return matching_subsystem.get_scalar_mirrored_target_option(option_name, target)
Beispiel #10
0
    def defaulted_property(self, target, selector):
        """Computes a language property setting for the given JvmTarget.

    :param selector A function that takes a target or platform and returns the boolean value of the
                    property for that target or platform, or None if that target or platform does
                    not directly define the property.

    If the target does not override the language property, returns true iff the property
    is true for any of the matched languages for the target.
    """
        if selector(target) is not None:
            return selector(target)

        prop = False
        if target.has_sources('.java'):
            prop |= selector(Java.global_instance())
        if target.has_sources('.scala'):
            prop |= selector(ScalaPlatform.global_instance())
        return prop
Beispiel #11
0
    def defaulted_property(self, target, option_name):
        """Computes a language property setting for the given JvmTarget.

    :param selector A function that takes a target or platform and returns the boolean value of the
                    property for that target or platform, or None if that target or platform does
                    not directly define the property.

    If the target does not override the language property, returns true iff the property
    is true for any of the matched languages for the target.
    """
        if target.has_sources('.java'):
            matching_subsystem = Java.global_instance()
        elif target.has_sources('.scala'):
            matching_subsystem = ScalaPlatform.global_instance()
        else:
            return getattr(target, option_name)

        return matching_subsystem.get_scalar_mirrored_target_option(
            option_name, target)
  def defaulted_property(self, target, selector):
    """Computes a language property setting for the given JvmTarget.

    :param selector A function that takes a target or platform and returns the boolean value of the
                    property for that target or platform, or None if that target or platform does
                    not directly define the property.

    If the target does not override the language property, returns true iff the property
    is true for any of the matched languages for the target.
    """
    if selector(target) is not None:
      return selector(target)

    prop = False
    if target.has_sources('.java'):
      prop |= selector(Java.global_instance())
    if target.has_sources('.scala'):
      prop |= selector(ScalaPlatform.global_instance())
    return prop
Beispiel #13
0
    def _compute_language_property(self, target, selector):
        """Computes the a language property setting for the given target sources.

    :param target The target whose language property will be calculated.
    :param selector A function that takes a target or platform and returns the boolean value of the
                    property for that target or platform, or None if that target or platform does
                    not directly define the property.

    If the target does not override the language property, returns true iff the property
    is true for any of the matched languages for the target.
    """
        if selector(target) is not None:
            return selector(target)

        property = False
        if target.has_sources(".java"):
            property |= selector(Java.global_instance())
        if target.has_sources(".scala"):
            property |= selector(ScalaPlatform.global_instance())
        return property
Beispiel #14
0
    def compute_dependency_specs(cls, kwargs=None, payload=None):
        for spec in super(JvmTarget,
                          cls).compute_dependency_specs(kwargs, payload):
            yield spec

        target_representation = kwargs or payload.as_dict()
        resources = target_representation.get('resources')
        if resources:
            for spec in resources:
                yield spec

        # TODO: https://github.com/pantsbuild/pants/issues/3409
        if Java.is_initialized():
            # Add deps on anything we might need to find plugins.
            # Note that this will also add deps from scala targets to javac plugins, but there's
            # no real harm in that, and the alternative is to check for .java sources, which would
            # eagerly evaluate all the globs, which would be a performance drag for goals that
            # otherwise wouldn't do that (like `list`).
            for spec in Java.global_instance().injectables_specs_for_key(
                    'plugin'):
                yield spec
Beispiel #15
0
  def compute_dependency_address_specs(cls, kwargs=None, payload=None):
    for address_spec in super().compute_dependency_address_specs(kwargs, payload):
      yield address_spec

    yield Java.global_instance().injectables_address_spec_for_key('tools.jar')