def check_config_valid(fips_dir, proj_dir, cfg, print_errors=False) :
    """check if provided config is valid, and print errors if not

    :param cfg:     a loaded config object
    :returns:       (True, [ messages ]) tuple with result and error messages
    """
    messages = []
    valid = True

    # check whether all required fields are present
    # (NOTE: name and folder should always be present since they are appended
    # during loading)
    required_fields = ['name', 'folder', 'platform', 'generator', 'build_tool', 'build_type']
    for field in required_fields :
        if field not in cfg :
            messages.append("missing field '{}' in '{}'".format(field, cfg['path']))
            valid = False
    
    # check if the target platform SDK is installed
    if not check_sdk(fips_dir, cfg['platform']) :
        messages.append("platform sdk for '{}' not installed (see './fips help setup')".format(cfg['platform']))
        valid = False

    # check if the generator name is valid
    if not valid_generator(cfg['generator']) :
        messages.append("invalid generator name '{}' in '{}'".format(cfg['generator'], cfg['path']))
        valid = False

    # check if build tool is valid
    if not valid_build_tool(cfg['build_tool']) :
        messages.append("invalid build_tool name '{}' in '{}'".format(cfg['build_tool'], cfg['path']))
        valid = False

    # check if the build tool can be found
    if not check_build_tool(fips_dir, cfg['build_tool']) :
        messages.append("build tool '{}' not found".format(cfg['build_tool']))
        valid = False

    # check if build type is valid (Debug, Release, Profiling)
    if not valid_build_type(cfg['build_type']) :
        messages.append("invalid build_type '{}' in '{}'".format(cfg['build_type'], cfg['path']))
        valid = False

    # check if the toolchain file can be found (if this is a crosscompiling toolchain)
    if cfg['platform'] not in native_platforms :
        toolchain_path = get_toolchain(fips_dir, proj_dir, cfg)
        if not toolchain_path :
            messages.append("toolchain file not found for config '{}'!".format(cfg['name']))
            valid = False

    if print_errors :
        for msg in messages :
            log.error(msg, False)

    return (valid, messages)
dataset/ETHPy150Open floooh/fips/mod/config.py/check_config_valid/original