def extract_target(java_targets, is_transitive, name = None): meta_target = bang.extract_target(java_targets, name) internal_deps, jar_deps = _extract_target(meta_target, is_transitive, lambda target: is_apt(target)) # TODO(John Sirois): make an empty source set work in ant/compile.xml sources = [ '__no_source__' ] all_deps = OrderedSet() all_deps.update(internal_deps) all_deps.update(jar_deps) if is_java(meta_target): return JavaLibrary('ide', sources, dependencies = all_deps, excludes = meta_target.excludes, is_meta = True) elif is_scala(meta_target): return ScalaLibrary('ide', sources, dependencies = all_deps, excludes = meta_target.excludes, is_meta = True) else: raise TypeError("Cannot generate IDE configuration for targets: %s" % java_targets)
def extract_target(java_targets, is_classpath): primary_target = InternalTarget.sort_targets(java_targets)[0] with ParseContext.temp(primary_target.target_base): internal_deps, jar_deps = _extract_target(java_targets, is_classpath) # TODO(John Sirois): make an empty source set work in ant/compile.xml sources = [ '__no_source__' ] all_deps = OrderedSet() all_deps.update(internal_deps) all_deps.update(jar_deps) if is_java(primary_target): return JavaLibrary('ide', sources, dependencies = all_deps, is_meta = True) elif is_scala(primary_target): return ScalaLibrary('ide', sources, dependencies = all_deps, is_meta = True) else: raise TypeError("Cannot generate IDE configuration for targets: %s" % java_targets)
def configure_target(target): if target not in analyzed: analyzed.add(target) self.has_scala = self.has_scala or is_scala(target) if isinstance(target, JavaLibrary) or isinstance(target, ScalaLibrary): # TODO(John Sirois): this does not handle test resources, make test resources 1st class # in ant build and punch this through to pants model resources = set() if target.resources: resources.update(target.resources) if target.binary_resources: resources.update(target.binary_resources) if resources: self.resource_extensions.update(Project.extract_resource_extensions(resources)) configure_source_sets(ExportableJvmLibrary.RESOURCES_BASE_DIR, resources, is_test = False) if target.sources: test = is_test(target) self.has_tests = self.has_tests or test configure_source_sets(target.target_base, target.sources, is_test = test) siblings = Target.get_all_addresses(target.address.buildfile) return filter(accept_target, [ Target.get(a) for a in siblings if a != target.address ])
def extract_target(java_targets, is_transitive, is_classpath, name = None): meta_target = bang.extract_target(java_targets, name) internal_deps, jar_deps = _extract_target(meta_target, is_transitive, is_classpath) # TODO(John Sirois): make an empty source set work in ant/compile.xml sources = [ '__no_source__' ] all_deps = OrderedSet() all_deps.update(internal_deps) all_deps.update(jar_deps) if is_java(meta_target): return JavaLibrary('ide', sources, dependencies = all_deps, excludes = meta_target.excludes, is_meta = True) elif is_scala(meta_target): return ScalaLibrary('ide', sources, dependencies = all_deps, excludes = meta_target.excludes, is_meta = True) else: raise TypeError("Cannot generate IDE configuration for targets: %s" % java_targets)
def calculate_tests(self, targets): tests = OrderedSet() for target in targets: if is_scala(target) and is_test(target): tests.update( os.path.join(target.target_base, test) for test in target.sources) return tests
def is_cp(target): return ( is_codegen(target) # Some IDEs need annotation processors pre-compiled, others are smart enough to detect and # proceed in 2 compile rounds or is_apt(target) or (self.skip_java and is_java(target)) or (self.skip_scala and is_scala(target)) or (self.intransitive and target not in self.context.target_roots))
def is_cp(target): return ( target.is_codegen # Some IDEs need annotation processors pre-compiled, others are smart enough to detect and # proceed in 2 compile rounds or is_apt(target) or (self.skip_java and is_java(target)) or (self.skip_scala and is_scala(target)) )
def is_cp(target): return ( is_codegen(target) # Some IDEs need annotation processors pre-compiled, others are smart enough to detect and # proceed in 2 compile rounds or is_apt(target) or (self.skip_java and is_java(target)) or (self.skip_scala and is_scala(target)) or (self.intransitive and target not in self.context.target_roots) )
def configure_target(target): if target not in analyzed: analyzed.add(target) self.has_scala = self.has_scala or is_scala(target) if isinstance(target, JavaLibrary) or isinstance( target, ScalaLibrary): # TODO(John Sirois): this does not handle test resources, make test resources 1st class # in ant build and punch this through to pants model resources = set() if target.resources: resources.update(target.resources) if target.binary_resources: resources.update(target.binary_resources) if resources: self.resource_extensions.update( Project.extract_resource_extensions(resources)) configure_source_sets( ExportableJvmLibrary.RESOURCES_BASE_DIR, resources, is_test=False) if target.sources: test = is_test(target) self.has_tests = self.has_tests or test configure_source_sets(target.target_base, target.sources, is_test=test) # Other BUILD files may specify sources in the same directory as this target. Those BUILD # files might be in parent directories (globs('a/b/*.java')) or even children directories if # this target globs children as well. Gather all these candidate BUILD files to test for # sources they own that live in the directories this targets sources live in. target_dirset = find_source_basedirs(target) candidates = Target.get_all_addresses(target.address.buildfile) for ancestor in target.address.buildfile.ancestors(): candidates.update(Target.get_all_addresses(ancestor)) for sibling in target.address.buildfile.siblings(): candidates.update(Target.get_all_addresses(sibling)) for descendant in target.address.buildfile.descendants(): candidates.update(Target.get_all_addresses(descendant)) def is_sibling(target): return source_target( target) and target_dirset.intersection( find_source_basedirs(target)) return filter( is_sibling, [Target.get(a) for a in candidates if a != target.address])
def calculate_tests(self, targets): def is_test_file(test): # TODO(John Sirois): config for a list of include regexes and exclude regexes basename = os.path.basename(test) return (test.endswith('Test.scala') or test.endswith('IT.scala') or test.endswith('Spec.scala')) \ and not basename.startswith('Base') and not basename.startswith('Abstract') tests = set() for target in targets: if is_scala(target) and is_test(target): tests.update(os.path.join(target.target_base, test) for test in target.sources if is_test_file(test)) return tests
def configure_target(target): if target not in analyzed: analyzed.add(target) self.has_scala = not self.skip_scala and (self.has_scala or is_scala(target)) if isinstance(target, JavaLibrary) or isinstance( target, ScalaLibrary): resources = set() if target.resources: resources.update(target.resources) if resources: self.resource_extensions.update( Project.extract_resource_extensions(resources)) configure_source_sets(target.sibling_resources_base, resources, is_test=False) if target.sources: test = is_test(target) self.has_tests = self.has_tests or test configure_source_sets(target.target_base, target.sources, is_test=test) # Other BUILD files may specify sources in the same directory as this target. Those BUILD # files might be in parent directories (globs('a/b/*.java')) or even children directories if # this target globs children as well. Gather all these candidate BUILD files to test for # sources they own that live in the directories this targets sources live in. target_dirset = find_source_basedirs(target) candidates = Target.get_all_addresses(target.address.buildfile) for ancestor in target.address.buildfile.ancestors(): candidates.update(Target.get_all_addresses(ancestor)) for sibling in target.address.buildfile.siblings(): candidates.update(Target.get_all_addresses(sibling)) for descendant in target.address.buildfile.descendants(): candidates.update(Target.get_all_addresses(descendant)) def is_sibling(target): return source_target( target) and target_dirset.intersection( find_source_basedirs(target)) return filter( is_sibling, [Target.get(a) for a in candidates if a != target.address])
def configure_target(target): if target not in analyzed: analyzed.add(target) self.has_scala = self.has_scala or is_scala(target) if isinstance(target, JavaLibrary) or isinstance(target, ScalaLibrary): # TODO(John Sirois): this does not handle test resources, make test resources 1st class # in ant build and punch this through to pants model resources = set() if target.resources: resources.update(target.resources) if target.binary_resources: resources.update(target.binary_resources) if resources: self.resource_extensions.update(Project.extract_resource_extensions(resources)) configure_source_sets(ExportableJvmLibrary.RESOURCES_BASE_DIR, resources, is_test = False) if target.sources: test = is_test(target) self.has_tests = self.has_tests or test configure_source_sets(target.target_base, target.sources, is_test = test) # Other BUILD files may specify sources in the same directory as this target. Those BUILD # files might be in parent directories (globs('a/b/*.java')) or even children directories if # this target globs children as well. Gather all these candidate BUILD files to test for # sources they own that live in the directories this targets sources live in. target_dirset = find_source_basedirs(target) candidates = Target.get_all_addresses(target.address.buildfile) for ancestor in target.address.buildfile.ancestors(): candidates.update(Target.get_all_addresses(ancestor)) for sibling in target.address.buildfile.siblings(): candidates.update(Target.get_all_addresses(sibling)) for descendant in target.address.buildfile.descendants(): candidates.update(Target.get_all_addresses(descendant)) def is_sibling(target): return source_target(target) and target_dirset.intersection(find_source_basedirs(target)) return filter(is_sibling, [ Target.get(a) for a in candidates if a != target.address ])
def configure_target(target): if target not in analyzed: analyzed.add(target) self.has_scala = not self.skip_scala and (self.has_scala or is_scala(target)) if isinstance(target, JavaLibrary) or isinstance(target, ScalaLibrary): resources = set() if target.resources: resources.update(target.resources) if resources: self.resource_extensions.update(Project.extract_resource_extensions(resources)) configure_source_sets(target.sibling_resources_base, resources, is_test = False) if target.sources: test = is_test(target) self.has_tests = self.has_tests or test configure_source_sets(target.target_base, target.sources, is_test = test) # Other BUILD files may specify sources in the same directory as this target. Those BUILD # files might be in parent directories (globs('a/b/*.java')) or even children directories if # this target globs children as well. Gather all these candidate BUILD files to test for # sources they own that live in the directories this targets sources live in. target_dirset = find_source_basedirs(target) candidates = Target.get_all_addresses(target.address.buildfile) for ancestor in target.address.buildfile.ancestors(): candidates.update(Target.get_all_addresses(ancestor)) for sibling in target.address.buildfile.siblings(): candidates.update(Target.get_all_addresses(sibling)) for descendant in target.address.buildfile.descendants(): candidates.update(Target.get_all_addresses(descendant)) def is_sibling(target): return source_target(target) and target_dirset.intersection(find_source_basedirs(target)) return filter(is_sibling, [ Target.get(a) for a in candidates if a != target.address ])
def source_target(target): return (self.transitive or target in self.targets) and has_sources(target) \ and (not is_codegen(target) and not (self.skip_java and is_java(target)) and not (self.skip_scala and is_scala(target)))
def is_cp(target): return target.is_codegen \ or is_apt(target) \ or (skip_java and is_java(target)) \ or (skip_scala and is_scala(target))
def is_coverage_target(self, tgt): return (is_java(tgt) or is_scala(tgt)) and not is_test(tgt) and not is_codegen(tgt)
def calculate_tests(self, targets): for target in targets: if (is_java(target) or is_scala(target)) and is_test(target): for test in target.sources: for cls in self.normalize(test, target.target_base): yield cls
def _is_scala(target): return (is_scala(target) or (isinstance(target, (JvmBinary, junit_tests, Benchmark)) and _has_sources(target, '.scala')))
def source_target(target): return has_sources(target) \ and (not target.is_codegen and not (self.skip_java and is_java(target)) and not (self.skip_scala and is_scala(target)))
def calculate_tests(self, targets): tests = OrderedSet() for target in targets: if is_scala(target) and is_test(target): tests.update(os.path.join(target.target_base, test) for test in target.sources) return tests