Exemple #1
0
def link_executable_using_cache(file_system: FileSystem,
                                compiler: Compiler,
                                executables_root: str,
                                symbols_tables_root: str,
                                external_libraries_root: str,
                                external_libraries_interfaces_root: str,
                                objects: List[str],
                                external_libraries: List[str],
                                external_libraries_interfaces: List[str],
                                organization: str,
                                artifact: str,
                                version: str,
                                cache: Dict[str, Any],
                                is_test: bool = False) -> Tuple[str, str]:
    file_system.create_directory_if_missing(executables_root)
    file_system.create_directory_if_missing(symbols_tables_root)

    name = get_artifact_full_name(
        organization, artifact, compiler.get_architecture(),
        compiler.get_platform(), compiler.get_name(), compiler.get_mode(),
        version) + ('.test' if is_test else '')
    cache['input'] = input_ = cache.get('input', {})
    (old_executable, old_symbols_table) = cache.get('output', (None, None))
    hasher = lambda path: hash_file(file_system, path)
    updated, removed, new_cache = key_delta(
        objects + external_libraries + external_libraries_interfaces, hasher,
        input_)
    yield_descriptor = compiler.get_yield_descriptor()
    executable = yield_descriptor.get_executable(executables_root, name)
    symbols_table = yield_descriptor.get_symbols_table(symbols_tables_root,
                                                       name)
    remake_executable = executable and not file_system.exists(executable)
    remake_symbols_table = symbols_table and not file_system.exists(
        symbols_table)
    if updated or removed or remake_executable or remake_symbols_table:
        if old_executable and file_system.exists(old_executable):
            file_system.remove_file(old_executable)
        if old_symbols_table and file_system.exists(old_symbols_table):
            file_system.remove_file(old_symbols_table)
        compiler.link_executable(external_libraries_root,
                                 external_libraries_interfaces_root, objects,
                                 external_libraries,
                                 external_libraries_interfaces, executable,
                                 symbols_table)
    cache['input'] = new_cache
    cache['output'] = (executable, symbols_table)
    return (executable, symbols_table)
Exemple #2
0
def validate_project(file_system: FileSystem, resources: StageResources,
                     cache: Dict[str, Any], program_arguments: Dict[str, Any],
                     configuration: Dict[str, Any], remote_proxy: RemoteProxy):
    project_directory = resources['project_directory']
    resources['headers_root'] = join(project_directory, 'sources')
    resources['test_sources_root'] = join(project_directory, 'sources')
    resources['resources_root'] = resources_root = join(
        project_directory, 'resources')
    resources['main_sources_root'] = main_sources_root = join(
        project_directory, 'sources')

    pralinefile = resources['pralinefile']
    organization = pralinefile['organization']
    artifact = pralinefile['artifact']

    file_system.create_directory_if_missing(
        join(resources_root, organization, artifact))
    file_system.create_directory_if_missing(
        join(main_sources_root, organization, artifact))
    check_unique(file_system, resources_root, organization, artifact)
    check_unique(file_system, main_sources_root, organization, artifact)
Exemple #3
0
def compile_using_cache(file_system: FileSystem, compiler: Compiler,
                        headers_root: str, external_headers_root: str,
                        sources_root: str, objects_root: str,
                        headers: List[str], sources: List[str],
                        cache: Dict[str, Any]) -> List[str]:
    file_system.create_directory_if_missing(objects_root)

    def hash_translation_unit(source):
        return hash_binary(
            compiler.preprocess(headers_root, external_headers_root, headers,
                                source))

    updated, removed, new_cache = key_delta(sources, hash_translation_unit,
                                            cache)
    objects = []
    yield_descriptor = compiler.get_yield_descriptor()

    for source in updated:
        object_ = yield_descriptor.get_object(sources_root, objects_root,
                                              source)
        compiler.compile(headers_root, external_headers_root, headers, source,
                         object_)
    for source in removed:
        object_ = yield_descriptor.get_object(sources_root, objects_root,
                                              source)
        if file_system.exists(object_):
            file_system.remove_file(object_)
    for source in sources:
        object_ = yield_descriptor.get_object(sources_root, objects_root,
                                              source)
        if not file_system.exists(object_):
            compiler.compile(headers_root, external_headers_root, headers,
                             source, object_)
        objects.append(object_)

    cache.clear()
    cache.update(new_cache)
    return objects
def package_headers_only(file_system: FileSystem, resources: StageResources,
                         cache: Dict[str, Any], program_arguments: Dict[str,
                                                                        Any],
                         configuration: Dict[str,
                                             Any], remote_proxy: RemoteProxy):
    project_directory = resources['project_directory']
    pralinefile = resources['pralinefile']
    compiler = resources['compiler']
    resources_root = resources['resources_root']
    resource_files = resources['resources']
    headers_root = resources['headers_root']
    if resources.activation in [0, 1]:
        headers = resources['formatted_headers']
    elif resources.activation in [2, 3]:
        headers = resources['headers']

    package_path = join(
        project_directory, 'target',
        get_package(pralinefile['organization'], pralinefile['artifact'],
                    compiler.get_architecture(), compiler.get_platform(),
                    compiler.get_name(), compiler.get_mode(),
                    pralinefile['version']))

    file_system.create_directory_if_missing(join(project_directory, 'target'))

    package_files = [(path,
                      join('resources', relative_path(path, resources_root)))
                     for path in resource_files]
    package_files.extend(
        (path, join('headers', relative_path(path, headers_root)))
        for path in headers)
    package_files.append((join(project_directory,
                               'Pralinefile'), 'Pralinefile'))
    pack(file_system, package_path, package_files, cache)

    resources['headers_only_package'] = package_path
def pull_dependencies(file_system: FileSystem, resources: StageResources, cache: Dict[str, Any], program_arguments: Dict[str, Any], configuration: Dict[str, Any], remote_proxy: RemoteProxy):
    project_directory      = resources['project_directory']
    external_root          = join(project_directory, 'target', 'external')
    external_packages_root = join(external_root, 'packages')

    resources['external_resources_root']            = external_resources_root            = join(external_root, 'resources')
    resources['external_headers_root']              = external_headers_root              = join(external_root, 'headers')
    resources['external_executables_root']          = external_executables_root          = join(external_root, 'executables')
    resources['external_libraries_root']            = external_libraries_root            = join(external_root, 'libraries')
    resources['external_libraries_interfaces_root'] = external_libraries_interfaces_root = join(external_root, 'libraries_interfaces')
    resources['external_symbols_tables_root']       = external_symbols_tables_root       = join(external_root, 'symbols_tables')

    file_system.create_directory_if_missing(external_packages_root)
    file_system.create_directory_if_missing(external_resources_root)
    file_system.create_directory_if_missing(external_headers_root)
    file_system.create_directory_if_missing(external_executables_root)
    file_system.create_directory_if_missing(external_libraries_root)
    file_system.create_directory_if_missing(external_libraries_interfaces_root)
    file_system.create_directory_if_missing(external_symbols_tables_root)

    external_resources            = []
    external_headers              = []
    external_libraries            = []
    external_libraries_interfaces = []
    external_symbols_tables       = []
    external_executables          = []

    def extend_externals(contents):
        external_resources.extend(contents['resources'])
        external_headers.extend(contents['headers'])
        external_libraries.extend(contents['libraries'])
        external_libraries_interfaces.extend(contents['libraries_interfaces'])
        external_symbols_tables.extend(contents['symbols_tables'])
        external_executables.extend(contents['executables'])

    pralinefile   = resources['pralinefile']
    compiler      = resources['compiler']
    logging_level = program_arguments['global']['logging_level']
    
    packages = remote_proxy.solve_dependencies(pralinefile,
                                               compiler.get_architecture(),
                                               compiler.get_platform(),
                                               compiler.get_name(),
                                               compiler.get_mode())
    updated, removed, new_cache = key_delta(packages.keys(), lambda p: packages[p], cache)
    
    for package in removed:
        package_path = join(external_packages_root, package)
        clean_up_package(file_system, package_path, external_root, logging_level)

    for package in updated:
        package_path = join(external_packages_root, package)
        clean_up_package(file_system, package_path, external_root, logging_level)
        remote_proxy.pull_package(package_path)
        contents = unpack(file_system, package_path, external_root)
        extend_externals(contents)

    for package in packages:
        if package not in updated:
            package_path = join(external_packages_root, package)
            if not file_system.exists(package_path):
                remote_proxy.pull_package(package_path)
                contents = unpack(file_system, package_path, external_root)
            else:
                contents = get_package_extracted_contents(file_system, package_path, external_root)
            extend_externals(contents)

    resources['external_resources']            = external_resources
    resources['external_headers']              = external_headers
    resources['external_libraries']            = external_libraries
    resources['external_libraries_interfaces'] = external_libraries_interfaces
    resources['external_symbols_tables']       = external_symbols_tables
    resources['external_executables']          = external_executables

    cache.clear()
    cache.update(new_cache)