Ejemplo n.º 1
0
def generate_libraries_dependencies(
        examples: List[Example],
        lib_descs: Dict[str, LibraryDescription]):

    print("Generating dependencies...")
    remaining_deps = len(lib_descs)

    for lib_desc_name in lib_descs:
        lib_desc = lib_descs[lib_desc_name]

        # Get info about dependencies generation
        sys.stdout.write("\rRemaining dependencies: " +
                         str(remaining_deps).ljust(4)
                         )
        remaining_deps -= 1

        # Function which checks if all sources from the library are included
        # in the example sources

        def includes_all_sources_from_library(example: Example):
            example_sources = example.get_prop(ExampleProperty.SOURCES)
            library_sources = lib_desc.library.sources
            sources_intersection = set.intersection(
                example_sources,
                library_sources
            )
            return len(sources_intersection) == len(library_sources)

        # Find library converted from all examples, which include all sources
        # from the library.
        intersection_lib = Library.intersection(
            library_from_example(example) for example in examples
            if includes_all_sources_from_library(example)
        )

        # Remove used resources from library
        intersection_lib.difference_update(lib_desc.library)

        # While there are any sources left we try to find library for them.
        dependencies = Property()
        while len(intersection_lib.sources) > 0:

            # Take one random source and find library for it.
            source = intersection_lib.sources.pop()
            found_library = find_library_including_source(source, lib_descs)

            if found_library == None:
                print("WARNING: library not found for: " + source)
            else:
                dependencies.add_item(found_library[0], Access.PUBLIC)
                intersection_lib.difference_update(found_library[1].library)

        # Update library's dependencies:
        lib_desc.library.set_prop(LibraryProperty.DEPENDENCIES, dependencies)

    # Info about success
    print("\nDependency generation finished!")
Ejemplo n.º 2
0
 def union_library() -> Library:
     return Library.union((library_from_example(x) for x in examples))
Ejemplo n.º 3
0
 def intersection_library_including_src(source: str) -> Library:
     return Library.intersection(
         library_from_example(e) for e in examples
         if source in e.get_prop(ExampleProperty.SOURCES))
Ejemplo n.º 4
0
libraries = libraries_load_from_file(generated_libraries)


def is_generated_library(name: str) -> bool:
    return re.match(r"lib[0-9]+", name) != None


unique_examples: Dict[str, Example] = {}
for example in examples:
    unique_examples[example.local_path] = example

# Collect information about each example (how many sources are not covered yet)
remaining_example_libraries: Dict[str, Library] = {}

for (path, example) in unique_examples.items():
    example_library = library_from_example(example)
    for (library_name, library_desc) in libraries.items():
        if is_generated_library(library_name):
            continue
        library = library_desc.library_for_sdk_version(example.sdk_version)
        if library == None:
            continue
        example_library.difference_update(library)
    remaining_example_libraries[path] = example_library

sorted_examples_by_remaining_example_libraries = sorted(
    remaining_example_libraries.items(), key=lambda a: len(a[1].sources))

# Collect information about examples, which are already covered
covered_examples: Set[str] = set()
for path in Path(examples_dir).rglob('CMakeLists.txt'):
Ejemplo n.º 5
0
all_examples: List[Example] = examples_load_from_file(examples)
all_libraries: Dict[str,
                    LibraryDescription] = libraries_load_from_file(libraries)

# Find all examples for supported SDKs and create an union from them.
union_example: Optional[Library] = None
supported_sdks: Set[Version] = set()

for example in all_examples:
    if example.local_path != "examples/" + example_name:
        continue

    supported_sdks.add(example.sdk_version)

    if union_example:
        union_example.union_update(library_from_example(example))
    else:
        union_example = library_from_example(example)

# For each source file, find a library.
found_libraries: Dict[str, LibraryDescription] = {}


def library_for_source(source_file: str) -> Optional[Tuple[str, Set[str]]]:
    for (library_name, library) in all_libraries.items():
        all_sources = library.library.sources.copy()
        for patch in library.patches:
            all_sources.update(patch.library.sources)
        if source_file in all_sources:
            return (library_name, all_sources)