Пример #1
0
    def test_json(self):
        json_value = {
            "sources": ["s1", "s2"],
            "dependencies": {
                "private": ["dep1", "dep2"]
            },
            "includes": {
                "public": ["inc1"]
            },
            "cflags": {
                "interface": ["int1"]
            },
            "asmflags": {
                "public": ["asm1"]
            },
            "ldflags": {
                "public": ["ld1"]
            }
        }

        value = Library.from_json(json_value)
        self.assertSetEqual(value.sources, {"s1", "s2"})

        LP = LibraryProperty
        self.assertEqual(value.get_prop(LP.DEPENDENCIES),
                         Property(private={"dep1", "dep2"}))
        self.assertEqual(value.get_prop(LP.INCLUDES),
                         Property(public={"inc1"}))
        self.assertEqual(value.get_prop(LP.CFLAGS),
                         Property(interface={"int1"}))
        self.assertEqual(value.get_prop(LP.ASMFLAGS),
                         Property(public={"asm1"}))
        self.assertEqual(value.get_prop(LP.LDFLAGS), Property(public={"ld1"}))

        self.assertEqual(json_value, value.to_json())
def library_from_example(example: Example) -> Library:
    return Library(
        sources=example.get_prop(ExampleProperty.SOURCES),
        includes=Property(public=example.get_prop(ExampleProperty.INCLUDES)),
        cflags=Property(public=example.get_prop(ExampleProperty.CFLAGS)),
        asmflags=Property(public=example.get_prop(ExampleProperty.ASMFLAGS)),
        ldflags=Property(public=example.get_prop(ExampleProperty.LDFLAGS)))
Пример #3
0
 def test_difference_update(self):
     self.lib2.difference_update(self.lib1)
     self.assertEqual(
         self.lib2,
         Library(sources={'s3'},
                 includes=Property(public={"pub_inc3"},
                                   private={"prv_inc3"}),
                 dependencies=Property(public={"dep1", "dep2"})))
Пример #4
0
 def test_union_update(self):
     self.lib1.union_update(self.lib2)
     self.assertEqual(
         self.lib1,
         Library(sources={'s1', 's2', 's3'},
                 includes=Property(
                     public={"pub_inc1", "pub_inc2", "pub_inc3"},
                     private={'prv_inc1', "prv_inc2", "prv_inc3"}),
                 dependencies=Property(public={"dep1", "dep2"})))
Пример #5
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!")
Пример #6
0
    def test_union(self):
        self.assertEqual(Library.union([]), Library())

        union_lib = Library.union([self.lib1, self.lib2, self.lib3])
        self.assertEqual(
            union_lib,
            Library(sources={'s1', 's2', 's3'},
                    includes=Property(
                        public={"pub_inc1", "pub_inc2", "pub_inc3"},
                        private={'prv_inc1', "prv_inc2", "prv_inc3"}),
                    dependencies=Property(public={"dep1", "dep2"})))
Пример #7
0
 def __init__(self,
              sources: Optional[Set[str]] = None,
              dependencies: Optional[Property] = None,
              includes: Optional[Property] = None,
              cflags: Optional[Property] = None,
              asmflags: Optional[Property] = None,
              ldflags: Optional[Property] = None):
     self._sources: Set[str] = sources or set()
     self._props: Dict[LibraryProperty, Property] = {}
     self._props[LibraryProperty.DEPENDENCIES] = dependencies or Property()
     self._props[LibraryProperty.INCLUDES] = includes or Property()
     self._props[LibraryProperty.CFLAGS] = cflags or Property()
     self._props[LibraryProperty.ASMFLAGS] = asmflags or Property()
     self._props[LibraryProperty.LDFLAGS] = ldflags or Property()
Пример #8
0
 def setUp(self):
     self.lib1 = Library(sources={'s1', 's2'},
                         includes=Property(public={"pub_inc1", "pub_inc2"},
                                           private={'prv_inc1',
                                                    "prv_inc2"}))
     self.lib2 = Library(sources={'s1', 's2', 's3'},
                         includes=Property(
                             public={"pub_inc1", "pub_inc2", "pub_inc3"},
                             private={'prv_inc1', "prv_inc2", "prv_inc3"}),
                         dependencies=Property(public={"dep1", "dep2"}))
     self.lib3 = Library(sources={'s2', 's3'},
                         includes=Property(public={"pub_inc2", "pub_inc3"},
                                           private={'prv_inc2',
                                                    "prv_inc3"}))
Пример #9
0
 def test_intersection_update(self):
     self.lib1.intersection_update(self.lib2)
     self.assertEqual(
         self.lib1,
         Library(sources={'s1', 's2'},
                 includes=Property(public={"pub_inc1", "pub_inc2"},
                                   private={"prv_inc1", "prv_inc2"})))
Пример #10
0
    def test_intersection(self):
        self.assertEqual(Library.intersection([]), Library())

        intersection = Library.intersection([self.lib1, self.lib2, self.lib3])
        self.assertEqual(
            intersection,
            Library(sources={'s2'},
                    includes=Property(public={"pub_inc2"},
                                      private={"prv_inc2"})))
Пример #11
0
    def from_json(json_value: dict) -> Library:
        validate_json(instance=json_value, schema=Library.json_schema)

        library_props = Library()
        if "sources" in json_value:
            library_props._sources = set(json_value["sources"])

        for property_name in LibraryProperty:
            if property_name.value in json_value:
                library_props._props[property_name] = Property.from_json(
                    json_value[property_name.value])

        return library_props