human
Complete this python program:
def _TopologicallySortedEnvVarKeys(env):
assistant
#Here is the Python program you requested.

    """Takes a dict |env| whose values are strings that can refer to other keys,
    for example env[\foo\] = \$(bar) and $(baz)\. Returns a list L of all keys of
    env such that key2 is after key1 in L if env[key2] refers to env[key1].
    Throws an Exception in case of dependency cycles.
    """
    regex = re.compile('\\$\\{([a-zA-Z0-9\\-_]+)\\}')
    def GetEdges(node):
        matches = set([v for v in regex.findall(env[node]) if (v in env)])
        for dependee in matches:
            assert ('${' not in dependee), ('Nested    variables    not    supported:    ' + dependee)
        return matches
    try:
        order = gyp.common.TopologicallySorted(env.keys(), GetEdges)
        order.reverse()
        return order
    except gyp.common.CycleError as e:
        raise GypError(('Xcode    environment    variables    are    cyclically    dependent:    ' + str(e.nodes)))