def _check_toolchain_rules(
        gn_rules, gn_toolchain, zn_rules, zn_toolchain, verbose):
    """Check the toolchain rules between a GN toolchain and its ZN equivalent.

    Args:
      gn_rules: A { tool -> { key: value } } map, as returned by
        parse_toolchain_ninja_file(), corresponding to a GN toolchain.
      gn_toolchain: The GN toolchain label.
      zn_rules: Same as |gn_rules|, for the corresponding ZN toolchain.
      zn_toolchain: The ZN toolchain label.
      verbose: If True, add key value differences to error messages.

    Returns:
      A (warnings, errors) pair, where |warnings| and |errors| are list of
      strings describing warnings or errors found in the comparison.
    """

    warnings = []
    errors = []

    # Check that all tools in the ZN toolchain are in the GN one.
    zn_tools = set(zn_rules.keys())
    gn_tools = set(gn_rules.keys())
    missing_tools = zn_tools - gn_tools
    if missing_tools:
        message = 'Missing tools from GN:%s (compared with ZN:%s): %s' % (
            gn_toolchain, zn_toolchain, ' '.join(sorted(missing_tools)))
        errors += [message]

    # For each tool, check that the keys are the same.
    # Then check that their values are also identical.
    for tool in zn_tools:
        zn_tool = zn_rules[tool]
        gn_tool = gn_rules[tool]

        gn_keys = set(gn_tool.keys())
        zn_keys = set(zn_tool.keys())
        extra_keys = gn_keys - zn_keys
        if extra_keys:
            warnings += [
                'GN:%s: extra %s tool keys: %s' %
                (gn_toolchain, tool, sorted(extra_keys))
            ]

        missing_keys = zn_keys - gn_keys
        if missing_keys:
            errors += [
                'GN:%s: Missing %s tool keys: %s' %
                (gn_toolchain, tool, sorted(missing_keys))
            ]

        for key in gn_keys & zn_keys:
            zn_value = zn_tool[key]
            gn_value = gn_tool[key]

            if zn_value != gn_value:
                message = 'GN:%s:%s: %s key values differ' % (
                    gn_toolchain, tool, key)
                if verbose:
                    message += '\n  gn [%s]\n  zn [%s]\n' % (gn_value, zn_value)
                errors += [message]

    return warnings, errors