Exemplo n.º 1
0
def get_toolchain(fips_dir, proj_dir, cfg):
    """get the toolchain path location for a config, this first checks
    for a 'cmake-toolchain' attribute, and if this does not exist, builds
    a xxx.toolchain.cmake file from the platform name (only for cross-
    compiling platforms). Toolchain files are searched in the
    following locations:
    - a fips-files/toolchains subdirectory in the project directory
    - a fips-files/toolchains subdirectory in all imported projects
    - finally in the cmake-toolchains subdirectory of the fips directory

    :param fips_dir:    absolute path to fips
    :param plat:        the target platform name
    :returns:           path to toolchain file or None for non-cross-compiling
    """

    # ignore native target platforms
    if 'platform' in cfg:
        if cfg['platform'] in native_platforms:
            return None
    else:
        log.error("config has no 'platform' attribute!'")

    # build toolchain file name
    toolchain = None
    if 'cmake-toolchain' in cfg:
        toolchain = cfg['cmake-toolchain']
    else:
        toolchain = '{}.toolchain.cmake'.format(cfg['platform'])

    # look for toolchain file in current project directory
    toolchain_dir = util.get_toolchains_dir(proj_dir)
    toolchain_path = None
    if toolchain_dir:
        toolchain_path = toolchain_dir + '/' + toolchain
    if toolchain_path and os.path.isfile(toolchain_path):
        return toolchain_path
    else:
        # look for toolchain in all imported directories
        _, imported_projs = dep.get_all_imports_exports(fips_dir, proj_dir)
        for imported_proj_name in imported_projs:
            imported_proj_dir = imported_projs[imported_proj_name]['proj_dir']
            toolchain_dir = util.get_toolchains_dir(imported_proj_dir)
            toolchain_path = None
            if toolchain_dir:
                toolchain_path = toolchain_dir + '/' + toolchain
            if toolchain_path and os.path.isfile(toolchain_path):
                return toolchain_path
        else:
            # toolchain is not in current project or imported projects,
            # try the fips directory
            toolchain_path = '{}/cmake-toolchains/{}'.format(
                fips_dir, toolchain)
            if os.path.isfile(toolchain_path):
                return toolchain_path
    # fallthrough: no toolchain file found
    return None
Exemplo n.º 2
0
def get_toolchain(fips_dir, proj_dir, cfg) :
    """get the toolchain path location for a config, this first checks
    for a 'cmake-toolchain' attribute, and if this does not exist, builds
    a xxx.toolchain.cmake file from the platform name (only for cross-
    compiling platforms). Toolchain files are searched in the
    following locations:
    - a fips-files/toolchains subdirectory in the project directory
    - a fips-files/toolchains subdirectory in all imported projects
    - finally in the cmake-toolchains subdirectory of the fips directory

    :param fips_dir:    absolute path to fips
    :param plat:        the target platform name
    :returns:           path to toolchain file or None for non-cross-compiling
    """

    # ignore native target platforms
    if 'platform' in cfg :
        if cfg['platform'] in native_platforms :
            return None
    else :
        log.error("config has no 'platform' attribute!'")

    # build toolchain file name
    toolchain = None
    if 'cmake-toolchain' in cfg :
        toolchain = cfg['cmake-toolchain']
    else :
        toolchain = '{}.toolchain.cmake'.format(cfg['platform'])
    
    # look for toolchain file in current project directory
    toolchain_dir = util.get_toolchains_dir(proj_dir)
    toolchain_path = None
    if toolchain_dir:
        toolchain_path = toolchain_dir + '/' + toolchain
    if toolchain_path and os.path.isfile(toolchain_path) :
        return toolchain_path
    else :
        # look for toolchain in all imported directories
        _, imported_projs = dep.get_all_imports_exports(fips_dir, proj_dir)
        for imported_proj_name in imported_projs :
            imported_proj_dir = imported_projs[imported_proj_name]['proj_dir']
            toolchain_dir = util.get_toolchains_dir(imported_proj_dir)
            toolchain_path = None
            if toolchain_dir:
                toolchain_path = toolchain_dir + '/' + toolchain
            if toolchain_path and os.path.isfile(toolchain_path):
                return toolchain_path
        else :
            # toolchain is not in current project or imported projects, 
            # try the fips directory
            toolchain_path = '{}/cmake-toolchains/{}'.format(fips_dir, toolchain)
            if os.path.isfile(toolchain_path) :
                return toolchain_path
    # fallthrough: no toolchain file found
    return None