def scan_addresses(self, root=None):
    """Recursively gathers all addresses visible under `root` of the virtual address space.

    :param string root: The absolute path of the root to scan; defaults to the root directory of the
                        pants project.
    :rtype: set of :class:`pants.build_graph.address.Address`
    :raises AddressLookupError: if there is a problem parsing a BUILD file
    """
    root_dir = get_buildroot()
    base_path = None

    if root:
      try:
        base_path = fast_relpath(root, root_dir)
      except ValueError as e:
        raise self.InvalidRootError(e)

    addresses = set()
    try:
      for build_file in BuildFile.scan_build_files(self._project_tree,
                                                   base_relpath=base_path,
                                                   build_ignore_patterns=self._build_ignore_patterns):
        for address in self.addresses_in_spec_path(build_file.spec_path):
          addresses.add(address)
    except BuildFile.BuildFileError as e:
      # Handle exception from BuildFile out of paranoia.  Currently, there is no way to trigger it.
      raise self.BuildFileScanError("{message}\n while scanning BUILD files in '{root}'."
                                    .format(message=e, root=root))
    return addresses
 def scan_buildfiles(self, base_relpath, build_ignore_patterns=None):
     return BuildFile.scan_build_files(
         self._project_tree,
         base_relpath,
         build_ignore_patterns=self._create_ignore_spec(
             build_ignore_patterns),
     )
  def scan_addresses(self, root=None):
    """Recursively gathers all addresses visible under `root` of the virtual address space.

    :param string root: The absolute path of the root to scan; defaults to the root directory of the
                        pants project.
    :rtype: set of :class:`pants.build_graph.address.Address`
    :raises AddressLookupError: if there is a problem parsing a BUILD file
    """
    root_dir = get_buildroot()
    base_path = None

    if root:
      try:
        base_path = fast_relpath(root, root_dir)
      except ValueError as e:
        raise self.InvalidRootError(e)

    addresses = set()
    try:
      for build_file in BuildFile.scan_build_files(self._project_tree,
                                                   base_relpath=base_path,
                                                   build_ignore_patterns=self._build_ignore_patterns):
        for address in self.addresses_in_spec_path(build_file.spec_path):
          addresses.add(address)
    except BuildFile.BuildFileError as e:
      # Handle exception from BuildFile out of paranoia.  Currently, there is no way to trigger it.
      raise self.BuildFileScanError("{message}\n while scanning BUILD files in '{root}'."
                                    .format(message=e, root=root))
    return addresses
 def scan_build_files(self, base_path, spec_excludes=None):
     deprecated_conditional(
         lambda: spec_excludes is not None, '0.0.75',
         'Use build_ignore_patterns consturctor parameter instead.')
     return BuildFile.scan_build_files(
         self._project_tree,
         base_path,
         spec_excludes,
         build_ignore_patterns=self._build_ignore_patterns)
示例#5
0
文件: ide_gen.py 项目: caveness/pants
        def configure_target(target):
            if target not in analyzed_targets:
                analyzed_targets.add(target)
                self.has_scala = not self.skip_scala and (self.has_scala or is_scala(target))

                # Hack for java_sources and Eclipse/IntelliJ: add java_sources to project
                if isinstance(target, ScalaLibrary):
                    for java_source in target.java_sources:
                        configure_target(java_source)

                # Resources are already in the target set
                if target.has_resources:
                    resources_by_basedir = defaultdict(set)
                    for resources in target.resources:
                        analyzed_targets.add(resources)
                        resources_by_basedir[resources.target_base].update(relative_sources(resources))
                    for basedir, resources in resources_by_basedir.items():
                        self.resource_extensions.update(Project.extract_resource_extensions(resources))
                        configure_source_sets(basedir, resources, is_test=target.is_test, resources_only=True)
                if target.has_sources():
                    test = target.is_test
                    self.has_tests = self.has_tests or test
                    base = target.target_base
                    configure_source_sets(
                        base, relative_sources(target), is_test=test, resources_only=isinstance(target, Resources)
                    )

                # TODO(Garrett Malmquist): This is dead code, and should be redone/reintegrated.
                # 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)
                if not isinstance(target.address, BuildFileAddress):
                    return []  # Siblings only make sense for BUILD files.
                candidates = OrderedSet()
                build_file = target.address.build_file
                dir_relpath = os.path.dirname(build_file.relpath)
                for descendant in BuildFile.scan_build_files(
                    build_file.project_tree,
                    dir_relpath,
                    spec_excludes=self.spec_excludes,
                    build_ignore_patterns=self.build_ignore_patterns,
                ):
                    candidates.update(self.target_util.get_all_addresses(descendant))
                if not self._is_root_relpath(dir_relpath):
                    ancestors = self._collect_ancestor_build_files(
                        build_file.project_tree, os.path.dirname(dir_relpath), self.build_ignore_patterns
                    )
                    for ancestor in ancestors:
                        candidates.update(self.target_util.get_all_addresses(ancestor))

                def is_sibling(target):
                    return source_target(target) and target_dirset.intersection(find_source_basedirs(target))

                return filter(is_sibling, [self.target_util.get(a) for a in candidates if a != target.address])
示例#6
0
    def configure_target(target):
      if target not in analyzed_targets:
        analyzed_targets.add(target)
        self.has_scala = not self.skip_scala and (self.has_scala or is_scala(target))

        # Hack for java_sources and Eclipse/IntelliJ: add java_sources to project
        if isinstance(target, ScalaLibrary):
          for java_source in target.java_sources:
            configure_target(java_source)

        # Resources are already in the target set
        if target.has_resources:
          resources_by_basedir = defaultdict(set)
          for resources in target.resources:
            analyzed_targets.add(resources)
            resources_by_basedir[resources.target_base].update(relative_sources(resources))
          for basedir, resources in resources_by_basedir.items():
            self.resource_extensions.update(Project.extract_resource_extensions(resources))
            configure_source_sets(basedir, resources, is_test=target.is_test,
                                  resources_only=True)
        if target.has_sources():
          test = target.is_test
          self.has_tests = self.has_tests or test
          base = target.target_base
          configure_source_sets(base, relative_sources(target), is_test=test,
                                resources_only=isinstance(target, Resources))

        # TODO(Garrett Malmquist): This is dead code, and should be redone/reintegrated.
        # 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)
        if not isinstance(target.address, BuildFileAddress):
          return []  # Siblings only make sense for BUILD files.
        candidates = OrderedSet()
        build_file = target.address.build_file
        dir_relpath = os.path.dirname(build_file.relpath)
        for descendant in BuildFile.scan_build_files(build_file.project_tree, dir_relpath,
                                                     spec_excludes=self.spec_excludes,
                                                     build_ignore_patterns=self.build_ignore_patterns):
          candidates.update(self.target_util.get_all_addresses(descendant))
        if not self._is_root_relpath(dir_relpath):
          ancestors = self._collect_ancestor_build_files(build_file.project_tree, os.path.dirname(dir_relpath),
                                                         self.build_ignore_patterns)
          for ancestor in ancestors:
            candidates.update(self.target_util.get_all_addresses(ancestor))

        def is_sibling(target):
          return source_target(target) and target_dirset.intersection(find_source_basedirs(target))

        return filter(is_sibling, [self.target_util.get(a) for a in candidates if a != target.address])
 def scan_build_files(self, base_path):
   build_files = BuildFile.scan_build_files(self._project_tree, base_path,
                                            build_ignore_patterns=self._build_ignore_patterns)
   return OrderedSet(bf.relpath for bf in build_files)
 def scan_build_files(self, base_path):
   return BuildFile.scan_build_files(self._project_tree, base_path,
                                     build_ignore_patterns=self._build_ignore_patterns)
示例#9
0
 def scan_buildfiles(self, base_relpath, build_ignore_patterns=None):
   return BuildFile.scan_build_files(self._project_tree, base_relpath,
                                     build_ignore_patterns=self._create_ignore_spec(build_ignore_patterns))
示例#10
0
 def scan_build_files(self, base_path):
   build_files = BuildFile.scan_build_files(self._project_tree, base_path,
                                            build_ignore_patterns=self._build_ignore_patterns)
   return OrderedSet(bf.relpath for bf in build_files)
示例#11
0
 def scan_build_files(self, base_path, spec_excludes=None):
   deprecated_conditional(lambda: spec_excludes is not None,
                          '0.0.75',
                          'Use build_ignore_patterns consturctor parameter instead.')
   return BuildFile.scan_build_files(self._project_tree, base_path, spec_excludes,
                                     build_ignore_patterns=self._build_ignore_patterns)
 def scan_build_files(self, base_path, spec_excludes):
   return BuildFile.scan_build_files(self._project_tree, base_path, spec_excludes)
示例#13
0
 def scan_buildfiles(self, base_relpath, spec_excludes=None):
   return BuildFile.scan_build_files(self._project_tree, base_relpath, spec_excludes)
示例#14
0
 def scan_build_files(self, base_path):
     return BuildFile.scan_build_files(
         self._project_tree,
         base_path,
         build_ignore_patterns=self._build_ignore_patterns)