def classname_for_classfile(self, target, classpath_products): contents = ClasspathUtil.classpath_contents((target,), classpath_products) for f in contents: classname = ClasspathUtil.classname_for_rel_classfile(f) # None for non `.class` files if classname: yield classname
def classname_for_classfile(self, target, classpath_products): contents = ClasspathUtil.classpath_contents((target, ), classpath_products) for f in contents: classname = ClasspathUtil.classname_for_rel_classfile(f) # None for non `.class` files if classname: yield classname
def add_sources_under_test(tgt): if self.is_coverage_target(tgt): contents = ClasspathUtil.classpath_contents( (tgt,), classpath_products, confs=self._task_exports.confs, transitive=False ) for f in contents: clsname = _classfile_to_classname(f) if clsname: classes_under_test.add(clsname)
def add_sources_under_test(tgt): if self.is_coverage_target(tgt): contents = ClasspathUtil.classpath_contents( (tgt, ), classpath_products, confs=self._task_exports.confs, transitive=False) for f in contents: clsname = _classfile_to_classname(f) if clsname: classes_under_test.add(clsname)
def _target_classes(self, target): """Set of target's provided classes. Call at the target level is to memoize efficiently. """ target_classes = set() contents = ClasspathUtil.classpath_contents((target,), self.runtime_classpath) for f in contents: classname = ClasspathUtil.classname_for_rel_classfile(f) if classname: target_classes.add(classname) return target_classes
def _get_internal_dependencies(self, binary_target): artifacts_by_file_name = defaultdict(set) classpath_products = self.context.products.get_data('runtime_classpath') # Select classfiles from the classpath. target = binary_target targets = ([target] + target.resources) if target.has_resources else [target] contents = ClasspathUtil.classpath_contents(targets, classpath_products, transitive=False) for f in contents: if not f.endswith('/'): artifacts_by_file_name[f].add(target) return artifacts_by_file_name
def _calculate_tests_from_targets(self, targets): """ :param list targets: list of targets to calculate test classes for. generates tuples (class_name, target). """ classpath_products = self.context.products.get_data('runtime_classpath') for target in targets: contents = ClasspathUtil.classpath_contents((target,), classpath_products, confs=self.confs) for f in contents: classname = ClasspathUtil.classname_for_rel_classfile(f) if classname: yield (classname, target)
def _calculate_tests_from_targets(self, targets): """ :param list targets: list of targets to calculate test classes for. generates tuples (Test, Target). """ classpath_products = self.context.products.get_data('runtime_classpath') for target in targets: contents = ClasspathUtil.classpath_contents((target,), classpath_products, confs=self.confs) for f in contents: classname = ClasspathUtil.classname_for_rel_classfile(f) if classname: yield Test(classname=classname), target
def _target_classes(self, target): """Set of target's provided classes. Call at the target level is to memoize efficiently. """ target_classes = set() contents = ClasspathUtil.classpath_contents((target,), self.runtime_classpath) for f in contents: classname = ClasspathUtil.classname_for_rel_classfile(f) if classname: target_classes.add(classname) return target_classes
def _calculate_tests_from_targets(self, targets): """ :param list targets: list of targets to calculate test classes for. generates tuples (class_name, target). """ classpath_products = self._context.products.get_data( 'runtime_classpath') for target in targets: contents = ClasspathUtil.classpath_contents( (target, ), classpath_products, confs=self._task_exports.confs, transitive=False) for f in contents: classname = ClasspathUtil.classname_for_rel_classfile(f) if classname: yield (classname, target)
def gen(): # Compute src -> target. if isinstance(target, JvmTarget): for src in target.sources_relative_to_buildroot(): yield os.path.join(self.buildroot, src) # TODO(Tejal Desai): pantsbuild/pants/65: Remove java_sources attribute for ScalaLibrary if isinstance(target, ScalaLibrary): for java_source in target.java_sources: for src in java_source.sources_relative_to_buildroot(): yield os.path.join(self.buildroot, src) # Compute classfile -> target and jar -> target. files = ClasspathUtil.classpath_contents((target,), self.runtime_classpath) # And jars; for binary deps, zinc doesn't emit precise deps (yet). cp_entries = ClasspathUtil.classpath((target,), self.runtime_classpath) jars = [cpe for cpe in cp_entries if ClasspathUtil.is_jar(cpe)] for coll in [files, jars]: for f in coll: yield f
def gen(): # Compute src -> target. if isinstance(target, JvmTarget): for src in target.sources_relative_to_buildroot(): yield os.path.join(self.buildroot, src) # TODO(Tejal Desai): pantsbuild/pants/65: Remove java_sources attribute for ScalaLibrary if isinstance(target, ScalaLibrary): for java_source in target.java_sources: for src in java_source.sources_relative_to_buildroot(): yield os.path.join(self.buildroot, src) # Compute classfile -> target and jar -> target. files = ClasspathUtil.classpath_contents((target,), self.runtime_classpath) # And jars; for binary deps, zinc doesn't emit precise deps (yet). cp_entries = ClasspathUtil.classpath((target,), self.runtime_classpath) jars = [cpe for cpe in cp_entries if ClasspathUtil.is_jar(cpe)] for coll in [files, jars]: for f in coll: yield f
def targets_by_file(self): """Returns a map from abs path of source, class or jar file to an OrderedSet of targets. The value is usually a singleton, because a source or class file belongs to a single target. However a single jar may be provided (transitively or intransitively) by multiple JarLibrary targets. But if there is a JarLibrary target that depends on a jar directly, then that "canonical" target will be the first one in the list of targets. """ targets_by_file = defaultdict(OrderedSet) runtime_classpath = self.context.products.get_data('runtime_classpath') # Compute src -> target. self.context.log.debug('Mapping sources...') buildroot = get_buildroot() # Look at all targets in-play for this pants run. Does not include synthetic targets, for target in self.context.targets(): if isinstance(target, JvmTarget): for src in target.sources_relative_to_buildroot(): targets_by_file[os.path.join(buildroot, src)].add(target) # TODO(Tejal Desai): pantsbuild/pants/65: Remove java_sources attribute for ScalaLibrary if isinstance(target, ScalaLibrary): for java_source in target.java_sources: for src in java_source.sources_relative_to_buildroot(): targets_by_file[os.path.join(buildroot, src)].add(target) # Compute classfile -> target and jar -> target. self.context.log.debug('Mapping classpath...') for target in self.context.targets(): # Classpath content. files = ClasspathUtil.classpath_contents((target, ), runtime_classpath, transitive=False) # And jars; for binary deps, zinc doesn't emit precise deps (yet). cp_entries = ClasspathUtil.classpath((target, ), runtime_classpath, transitive=False) jars = [cpe for cpe in cp_entries if ClasspathUtil.is_jar(cpe)] for coll in [files, jars]: for f in coll: targets_by_file[f].add(target) return targets_by_file
def targets_by_file(self): """Returns a map from abs path of source, class or jar file to an OrderedSet of targets. The value is usually a singleton, because a source or class file belongs to a single target. However a single jar may be provided (transitively or intransitively) by multiple JarLibrary targets. But if there is a JarLibrary target that depends on a jar directly, then that "canonical" target will be the first one in the list of targets. """ targets_by_file = defaultdict(OrderedSet) runtime_classpath = self.context.products.get_data('runtime_classpath') # Compute src -> target. self.context.log.debug('Mapping sources...') buildroot = get_buildroot() # Look at all targets in-play for this pants run. Does not include synthetic targets, for target in self.context.targets(): if isinstance(target, JvmTarget): for src in target.sources_relative_to_buildroot(): targets_by_file[os.path.join(buildroot, src)].add(target) # TODO(Tejal Desai): pantsbuild/pants/65: Remove java_sources attribute for ScalaLibrary if isinstance(target, ScalaLibrary): for java_source in target.java_sources: for src in java_source.sources_relative_to_buildroot(): targets_by_file[os.path.join(buildroot, src)].add(target) # Compute classfile -> target and jar -> target. self.context.log.debug('Mapping classpath...') for target in self.context.targets(): # Classpath content. files = ClasspathUtil.classpath_contents((target,), runtime_classpath, transitive=False) # And jars; for binary deps, zinc doesn't emit precise deps (yet). cp_entries = ClasspathUtil.classpath((target,), runtime_classpath, transitive=False) jars = [cpe for cpe in cp_entries if ClasspathUtil.is_jar(cpe)] for coll in [files, jars]: for f in coll: targets_by_file[f].add(target) return targets_by_file
def _count_products(self, classpath_products, target): contents = ClasspathUtil.classpath_contents((target,), classpath_products, transitive=False) # Generators don't implement len. return sum(1 for _ in contents)
def _count_products(self, classpath_products, target): contents = ClasspathUtil.classpath_contents((target, ), classpath_products) # Generators don't implement len. return sum(1 for _ in contents)
def count_products(self, target): contents = ClasspathUtil.classpath_contents((target,), self.runtime_classpath) # Generators don't implement len. return sum(1 for _ in contents)