Construct dictionary {header_file : set_of_included_files}.

    This function operates on "real" set of includes, in the sense that it
    parses each header file to check which files are included from there.

def build_headermap(headers):
    """
    Construct dictionary {header_file : set_of_included_files}.

    This function operates on "real" set of includes, in the sense that it
    parses each header file to check which files are included from there.
    """
    # TODO: what happens if some headers are circularly dependent?
    headermap = {}
    for hfile in headers:
        headermap[hfile] = None
    for hfile in headers:
        assert (hfile.startswith("c/") or
                hfile.startswith("datatable/include/"))
        inc = find_includes(hfile)
        for f in inc:
            assert f != hfile, "File %s includes itself?" % f
            assert f.startswith("c/")
            if f not in headers:
                raise ValueError("Unknown header \"%s\" included from %s"
                                 % (f, hfile))
        headermap[hfile] = set(inc)
    return headermap