def resolve(self, address):
    """Maps an address in the virtual address space to an object.

    :param Address address: the address to lookup in a BUILD file
    :raises AddressLookupError: if the path to the address is not found.
    :returns: A tuple of the natively mapped BuildFileAddress and the Addressable it points to.
    """
    address_map = self._address_map_from_spec_path(address.spec_path)
    if address not in address_map:
      build_file = BuildFile.cached(self._project_tree, address.spec_path, must_exist=False)
      self._raise_incorrect_address_error(build_file, address.target_name, address_map)
    else:
      return address_map[address]
  def _address_map_from_spec_path(self, spec_path):
    """Returns a resolution map of all addresses in a "directory" in the virtual address space.

    :returns {Address: (Address, <resolved Object>)}:
    """
    if spec_path not in self._spec_path_to_address_map_map:
      try:
        try:
          build_file = BuildFile.cached(self._project_tree, spec_path)
        except BuildFile.BuildFileError as e:
          raise self.BuildFileScanError("{message}\n searching {spec_path}"
                                        .format(message=e,
                                                spec_path=spec_path))
        mapping = self._build_file_parser.address_map_from_build_file(build_file)
      except BuildFileParser.BuildFileParserError as e:
        raise AddressLookupError("{message}\n Loading addresses from '{spec_path}' failed."
                                 .format(message=e, spec_path=spec_path))

      address_map = {address: (address, addressed) for address, addressed in mapping.items()}
      self._spec_path_to_address_map_map[spec_path] = address_map
    return self._spec_path_to_address_map_map[spec_path]
示例#3
0
  def to_url(m):
    if m.group(1):
      return m.group(0)  # It's an http(s) url.
    path = m.group(0)

    if path.startswith('/'):
      path = os.path.relpath(path, buildroot)
    else:
      # See if it's a reference to a target in a BUILD file.
      parts = path.split(':')
      if len(parts) == 2:
        putative_dir = parts[0]
      else:
        putative_dir = path
      if os.path.isdir(os.path.join(buildroot, putative_dir)):
        build_file = BuildFile.cached(FileSystemProjectTree(buildroot), putative_dir, must_exist=False)
        path = build_file.relpath
    if os.path.exists(os.path.join(buildroot, path)):
      # The reporting server serves file content at /browse/<path_from_buildroot>.
      return '/browse/{}'.format(path)
    else:
      return None
 def get_build_file(self, relpath, must_exist=True):
   return BuildFile.cached(self._project_tree, relpath, must_exist)