示例#1
0
async def parse_address_family(
    parser: Parser,
    build_file_options: BuildFileOptions,
    prelude_symbols: BuildFilePreludeSymbols,
    directory: AddressFamilyDir,
) -> AddressFamily:
    """Given an AddressMapper and a directory, return an AddressFamily.

    The AddressFamily may be empty, but it will not be None.
    """
    digest_contents = await Get(
        DigestContents,
        PathGlobs(globs=(
            *(os.path.join(directory.path, p)
              for p in build_file_options.patterns),
            *(f"!{p}" for p in build_file_options.ignores),
        )),
    )
    if not digest_contents:
        raise ResolveError(
            f"Directory '{directory.path}' does not contain any BUILD files.")

    address_maps = [
        AddressMap.parse(fc.path, fc.content.decode(), parser, prelude_symbols)
        for fc in digest_contents
    ]
    return AddressFamily.create(directory.path, address_maps)
示例#2
0
async def parse_address_family(address_mapper: AddressMapper,
                               prelude_symbols: BuildFilePreludeSymbols,
                               directory: Dir) -> AddressFamily:
    """Given an AddressMapper and a directory, return an AddressFamily.

    The AddressFamily may be empty, but it will not be None.
    """

    path_globs = PathGlobs(globs=(
        *(os.path.join(directory.path, p)
          for p in address_mapper.build_patterns),
        *(f"!{p}" for p in address_mapper.build_ignore_patterns),
    ))
    snapshot = await Get[Snapshot](PathGlobs, path_globs)
    files_content = await Get[FilesContent](Digest, snapshot.digest)

    if not files_content:
        raise ResolveError(
            'Directory "{}" does not contain any BUILD files.'.format(
                directory.path))
    address_maps = []
    for filecontent_product in files_content:
        address_maps.append(
            AddressMap.parse(
                filecontent_product.path,
                filecontent_product.content,
                address_mapper.parser,
                prelude_symbols,
            ))
    return AddressFamily.create(directory.path, address_maps)
示例#3
0
def parse_address_map(build_file: str) -> AddressMap:
    path = "/dev/null"
    parser = Parser(target_type_aliases=["thing"],
                    object_aliases=BuildFileAliases())
    address_map = AddressMap.parse(path, build_file, parser,
                                   BuildFilePreludeSymbols(FrozenDict()))
    assert path == address_map.path
    return address_map
示例#4
0
 def parse_address_map(self, json):
     path = "/dev/null"
     address_map = AddressMap.parse(path, json, self._parser,
                                    BuildFilePreludeSymbols(FrozenDict()))
     self.assertEqual(path, address_map.path)
     yield address_map