Ejemplo n.º 1
0
    def virtual_test(self):
        references = References()
        references[va].add('a.h')

        code = (
            'def virtual(settings):\n\tif(settings.os.family == "windows"):return "win"\n'
            '\telse: return "nix"')
        a = Resource(VirtualCell('user/blocka/a.h', code, {'win', 'nix'}))

        awin = Resource(SimpleCell('user/blocka/win/a.h'))
        anix = Resource(SimpleCell('user/blocka/nix/a.h'))
        b = Resource(SimpleCell('user/blockb/b.h'))
        d1 = Resource(SimpleCell('user/blockd/d.h'))
        awin.cell.dependencies.explicit.add(b.name)
        anix.cell.dependencies.explicit.add(d1.name)

        tables = {va: [vb, vd1], vb: [], vd1: []}
        api = FakeApi(zip([va, va, va, vb, vd1], [a, awin, anix, b, d1]),
                      tables)

        #With windows settings
        settings = Settings(OSInfo(OSFamily("Windows")))
        biiout = OutputStream()
        graph, closure, _ = build_closure(api, references, {}, settings,
                                          biiout)
        expected_graph = BlockVersionGraph()
        expected_graph.add_nodes([va, vb])
        expected_graph.add_edge(va, vb)
        self.assertEqual(expected_graph, graph)
        expected_closure = Closure({
            a.name: ClosureItem(a, va),
            awin.name: ClosureItem(awin, va),
            b.name: ClosureItem(b, vb),
        })
        self.assertEqual(expected_closure, closure)
        self.assertEqual("", str(biiout))

        #Change settings
        settings = Settings(OSInfo(OSFamily("Linux")))
        biiout = OutputStream()
        graph, closure, _ = build_closure(api, references, {}, settings,
                                          biiout)
        expected_graph = BlockVersionGraph()
        expected_graph.add_nodes([va, vd1])
        expected_graph.add_edge(va, vd1)
        self.assertEqual(expected_graph, graph)
        expected_closure = Closure({
            a.name: ClosureItem(a, va),
            anix.name: ClosureItem(anix, va),
            d1.name: ClosureItem(d1, vd1),
        })
        self.assertEqual(expected_closure, closure)
        self.assertEqual("", str(biiout))
Ejemplo n.º 2
0
    def overwrite_test(self):
        """ Blocks: C (defines in requirements B2)
        Deps: A, B2
        C -> A -> B1
        """
        references = References()
        references[va].add('a.h')

        b = Resource(SimpleCell('user/blockb/b.h'))
        b2 = Resource(SimpleCell('user/blockb/b.h'), CPP)
        a = Resource(SimpleCell('user/blocka/a.h'))
        a2 = Resource(SimpleCell('user/blocka/a2.h'))
        a.cell.dependencies.explicit.add(a2.name)
        a2.cell.dependencies.explicit.add(b.name)

        tables = {va: [vb], vb: [], vb2: []}
        api = FakeApi(zip([va, va, vb, vb2], [a, a2, b, b2]), tables)
        base_table = BlockVersionTable([vc, va, vb2])  # Note B2 defined here
        biiout = OutputStream()
        graph, closure, _ = build_closure(api,
                                          references,
                                          base_table,
                                          biiout=biiout)
        expected_graph = BlockVersionGraph()
        expected_graph.add_nodes([va, vb2])
        expected_graph.add_edge(va, vb2)
        self.assertEqual(expected_graph, graph)
        expected_closure = Closure({
            a.name: ClosureItem(a, va),
            a2.name: ClosureItem(a2, va),
            b.name: ClosureItem(b2, vb2)
        })
        self.assertEqual(expected_closure, closure)
        self.assertEqual("", str(biiout))
Ejemplo n.º 3
0
    def simple_test(self):
        """ Blocks: C
        Deps: A, B
        C -> A -> B
        """
        references = References()
        references[va].add('a.h')
        base_table = BlockVersionTable(
            [vc, va])  # The result including or excluding va is same

        b = Resource(SimpleCell('user/blockb/b.h'))
        a = Resource(SimpleCell('user/blocka/a.h'))
        a2 = Resource(SimpleCell('user/blocka/a2.h'))
        a.cell.dependencies.explicit.add(a2.name)
        a2.cell.dependencies.explicit.add(b.name)

        tables = {va: [vb], vb: []}
        api = FakeApi(zip([va, va, vb], [a, a2, b]), tables)
        biiout = OutputStream()
        graph, closure, _ = build_closure(api,
                                          references,
                                          base_table,
                                          biiout=biiout)
        expected_graph = BlockVersionGraph()
        expected_graph.add_nodes([va, vb])
        expected_graph.add_edge(va, vb)
        self.assertEqual(expected_graph, graph)
        expected_closure = Closure({
            a.name: ClosureItem(a, va),
            a2.name: ClosureItem(a2, va),
            b.name: ClosureItem(b, vb)
        })
        self.assertEqual(expected_closure, closure)
        self.assertEqual("", str(biiout))
Ejemplo n.º 4
0
    def dep_overwriten_in_blocks_test(self):
        """ Blocks: C, B (None version)
        Deps: A
        C -> A -> B
        """
        references = References()
        references[va].add('a.h')
        vbn = BlockVersion(vb.block, None)

        b = Resource(SimpleCell('user/blockb/b.h'))
        a = Resource(SimpleCell('user/blocka/a.h'))
        a2 = Resource(SimpleCell('user/blocka/a2.h'))
        a.cell.dependencies.explicit.add(a2.name)
        a2.cell.dependencies.explicit.add(b.name)

        tables = {va: [vb], vb: []}
        api = FakeApi(zip([va, va, vb], [a, a2, b]), tables)
        base_table = BlockVersionTable([vc, vbn])
        biiout = OutputStream()
        graph, closure, _ = build_closure(api,
                                          references,
                                          base_table,
                                          biiout=biiout)
        expected_graph = BlockVersionGraph()
        expected_graph.add_nodes([va])
        expected_graph.add_edge(va, vbn)
        self.assertEqual(expected_graph, graph)
        expected_closure = Closure({
            a.name: ClosureItem(a, va),
            a2.name: ClosureItem(a2, va)
        })
        self.assertEqual(expected_closure, closure)
        self.assertEqual("", str(biiout))
Ejemplo n.º 5
0
def deps_process(biiapi, hive_holder, processor_changes, biiout, settings=None):
    """Try to find unresolved in the existing external references or in the external references
    of the previous execution, so moving a file from one place to another does not require a
    find
    """
    logger.debug("---------- process deps --------")
    _change_local_versions(hive_holder)  # to edition ones if you opened blocks
    _discover_tag_versions(hive_holder, biiapi, processor_changes, biiout)
    common_table = compute_common_table(hive_holder)  # BlockVersionTable
    _update_resolved(biiapi, hive_holder, common_table, biiout)

    src_graph, references = compute_src_graph(hive_holder, common_table)
    dep_graph, closure, overwrites = build_closure(biiapi, references, common_table, settings,
                                                   biiout)
    hive_dependencies = hive_holder.hive.hive_dependencies
    hive_dependencies.src_graph = src_graph  # BlockVersionGraph
    hive_dependencies.dep_graph = dep_graph  # BlockVersionGraph
    hive_dependencies.closure = closure
    hive_dependencies.references = references

    real_graph = src_graph + dep_graph
    real_graph.sanitize(biiout)
    _update_requirements(hive_holder, real_graph, overwrites, common_table, biiout)

    for block_holder in hive_holder.block_holders:
        biiconfig = block_holder.commit_config()  # Resource
        if biiconfig:
            processor_changes.upsert(biiconfig.name, biiconfig.content, blob_changed=True)

    hive_holder.hive.update(processor_changes)
    def overwrite_test(self):
        """ Blocks: C (defines in requirements B2)
        Deps: A, B2
        C -> A -> B1
        """
        references = References()
        references[va].add('a.h')

        b = Resource(SimpleCell('user/blockb/b.h'))
        b2 = Resource(SimpleCell('user/blockb/b.h'), CPP)
        a = Resource(SimpleCell('user/blocka/a.h'))
        a2 = Resource(SimpleCell('user/blocka/a2.h'))
        a.cell.dependencies.explicit.add(a2.name)
        a2.cell.dependencies.explicit.add(b.name)

        tables = {va: [vb], vb: [], vb2: []}
        api = FakeApi(zip([va, va, vb, vb2], [a, a2, b, b2]), tables)
        base_table = BlockVersionTable([vc, va, vb2])  # Note B2 defined here
        biiout = OutputStream()
        graph, closure, _ = build_closure(api, references, base_table, biiout=biiout)
        expected_graph = BlockVersionGraph()
        expected_graph.add_nodes([va, vb2])
        expected_graph.add_edge(va, vb2)
        self.assertEqual(expected_graph, graph)
        expected_closure = Closure({a.name: ClosureItem(a, va),
                                    a2.name: ClosureItem(a2, va),
                                    b.name: ClosureItem(b2, vb2)})
        self.assertEqual(expected_closure, closure)
        self.assertEqual("", str(biiout))
    def simple_test(self):
        """ Blocks: C
        Deps: A, B
        C -> A -> B
        """
        references = References()
        references[va].add('a.h')
        base_table = BlockVersionTable([vc, va])  # The result including or excluding va is same

        b = Resource(SimpleCell('user/blockb/b.h'))
        a = Resource(SimpleCell('user/blocka/a.h'))
        a2 = Resource(SimpleCell('user/blocka/a2.h'))
        a.cell.dependencies.explicit.add(a2.name)
        a2.cell.dependencies.explicit.add(b.name)

        tables = {va: [vb], vb: []}
        api = FakeApi(zip([va, va, vb], [a, a2, b]), tables)
        biiout = OutputStream()
        graph, closure, _ = build_closure(api, references, base_table, biiout=biiout)
        expected_graph = BlockVersionGraph()
        expected_graph.add_nodes([va, vb])
        expected_graph.add_edge(va, vb)
        self.assertEqual(expected_graph, graph)
        expected_closure = Closure({a.name: ClosureItem(a, va),
                                    a2.name: ClosureItem(a2, va),
                                    b.name: ClosureItem(b, vb)})
        self.assertEqual(expected_closure, closure)
        self.assertEqual("", str(biiout))
    def diamond_test(self, conflict):
        """ Blocks: C
        Deps: A, B, D1-D2
        C -> A, B; A->D1, B->D2
        """
        references = References()
        references[va].add('a.h')
        references[vb].add('b.h')

        b = Resource(SimpleCell('user/blockb/b.h'))
        a = Resource(SimpleCell('user/blocka/a.h'))
        d1 = Resource(SimpleCell('user/blockd/d.h'))
        if conflict:
            d2 = Resource(SimpleCell('user/blockd/d.h', CPP))
        else:
            d2 = Resource(SimpleCell('user/blockd/d.h'))
        a.cell.dependencies.explicit.add(d1.name)
        b.cell.dependencies.explicit.add(d2.name)

        tables = {va: [vd1], vb: [vd2], vd1: [], vd2: []}
        api = FakeApi(zip([va, vb, vd1, vd2], [a, b, d1, d2]), tables)
        base_table = BlockVersionTable([vc, va, vb])
        biiout = OutputStream()
        graph, closure, _ = build_closure(api, references, base_table, biiout=biiout)
        expected_graph = BlockVersionGraph()
        expected_graph.add_nodes([va, vb, vd1, vd2])
        expected_graph.add_edge(va, vd1)
        expected_graph.add_edge(vb, vd2)
        self.assertEqual(expected_graph, graph)
        self.assertEqual({a.name, b.name, d1.name}, set(closure.keys()))
        if conflict:
            self.assertIn('Incompatible dependency "user/blockd/d.h"', str(biiout))
        else:
            self.assertEqual("", str(biiout))
    def dep_overwriten_in_blocks_test(self):
        """ Blocks: C, B (None version)
        Deps: A
        C -> A -> B
        """
        references = References()
        references[va].add('a.h')
        vbn = BlockVersion(vb.block, None)

        b = Resource(SimpleCell('user/blockb/b.h'))
        a = Resource(SimpleCell('user/blocka/a.h'))
        a2 = Resource(SimpleCell('user/blocka/a2.h'))
        a.cell.dependencies.explicit.add(a2.name)
        a2.cell.dependencies.explicit.add(b.name)

        tables = {va: [vb], vb: []}
        api = FakeApi(zip([va, va, vb], [a, a2, b]), tables)
        base_table = BlockVersionTable([vc, vbn])
        biiout = OutputStream()
        graph, closure, _ = build_closure(api, references, base_table, biiout=biiout)
        expected_graph = BlockVersionGraph()
        expected_graph.add_nodes([va])
        expected_graph.add_edge(va, vbn)
        self.assertEqual(expected_graph, graph)
        expected_closure = Closure({a.name: ClosureItem(a, va),
                                    a2.name: ClosureItem(a2, va)})
        self.assertEqual(expected_closure, closure)
        self.assertEqual("", str(biiout))
    def virtual_test(self):
        references = References()
        references[va].add('a.h')

        code = ('def virtual(settings):\n\tif(settings.os.family == "windows"):return "win"\n'
                '\telse: return "nix"')
        a = Resource(VirtualCell('user/blocka/a.h', code, {'win', 'nix'}))

        awin = Resource(SimpleCell('user/blocka/win/a.h'))
        anix = Resource(SimpleCell('user/blocka/nix/a.h'))
        b = Resource(SimpleCell('user/blockb/b.h'))
        d1 = Resource(SimpleCell('user/blockd/d.h'))
        awin.cell.dependencies.explicit.add(b.name)
        anix.cell.dependencies.explicit.add(d1.name)

        tables = {va: [vb, vd1], vb: [], vd1: []}
        api = FakeApi(zip([va, va, va, vb, vd1], [a, awin, anix, b, d1]), tables)

        #With windows settings
        settings = Settings(OSInfo(OSFamily("Windows")))
        biiout = OutputStream()
        graph, closure, _ = build_closure(api, references, {}, settings, biiout)
        expected_graph = BlockVersionGraph()
        expected_graph.add_nodes([va, vb])
        expected_graph.add_edge(va, vb)
        self.assertEqual(expected_graph, graph)
        expected_closure = Closure({a.name: ClosureItem(a, va),
                                    awin.name: ClosureItem(awin, va),
                                    b.name: ClosureItem(b, vb),
                                    })
        self.assertEqual(expected_closure, closure)
        self.assertEqual("", str(biiout))

        #Change settings
        settings = Settings(OSInfo(OSFamily("Linux")))
        biiout = OutputStream()
        graph, closure, _ = build_closure(api, references, {}, settings, biiout)
        expected_graph = BlockVersionGraph()
        expected_graph.add_nodes([va, vd1])
        expected_graph.add_edge(va, vd1)
        self.assertEqual(expected_graph, graph)
        expected_closure = Closure({a.name: ClosureItem(a, va),
                                    anix.name: ClosureItem(anix, va),
                                    d1.name: ClosureItem(d1, vd1),
                                    })
        self.assertEqual(expected_closure, closure)
        self.assertEqual("", str(biiout))
Ejemplo n.º 11
0
    def diamond_test(self, conflict):
        """ Blocks: C
        Deps: A, B, D1-D2
        C -> A, B; A->D1, B->D2
        """
        references = References()
        references[va].add('a.h')
        references[vb].add('b.h')

        b = Resource(SimpleCell('user/blockb/b.h'))
        a = Resource(SimpleCell('user/blocka/a.h'))
        d1 = Resource(SimpleCell('user/blockd/d.h'))
        if conflict:
            d2 = Resource(SimpleCell('user/blockd/d.h', CPP))
        else:
            d2 = Resource(SimpleCell('user/blockd/d.h'))
        a.cell.dependencies.explicit.add(d1.name)
        b.cell.dependencies.explicit.add(d2.name)

        tables = {va: [vd1], vb: [vd2], vd1: [], vd2: []}
        api = FakeApi(zip([va, vb, vd1, vd2], [a, b, d1, d2]), tables)
        base_table = BlockVersionTable([vc, va, vb])
        biiout = OutputStream()
        graph, closure, _ = build_closure(api,
                                          references,
                                          base_table,
                                          biiout=biiout)
        expected_graph = BlockVersionGraph()
        expected_graph.add_nodes([va, vb, vd1, vd2])
        expected_graph.add_edge(va, vd1)
        expected_graph.add_edge(vb, vd2)
        self.assertEqual(expected_graph, graph)
        self.assertEqual({a.name, b.name, d1.name}, set(closure.keys()))
        if conflict:
            self.assertIn('Incompatible dependency "user/blockd/d.h"',
                          str(biiout))
        else:
            self.assertEqual("", str(biiout))
Ejemplo n.º 12
0
def deps_process(biiapi,
                 hive_holder,
                 processor_changes,
                 biiout,
                 settings=None):
    """Try to find unresolved in the existing external references or in the external references
    of the previous execution, so moving a file from one place to another does not require a
    find
    """
    logger.debug("---------- process deps --------")
    _change_local_versions(hive_holder)  # to edition ones if you opened blocks
    _discover_tag_versions(hive_holder, biiapi, processor_changes, biiout)
    common_table = compute_common_table(hive_holder)  # BlockVersionTable
    _update_resolved(biiapi, hive_holder, common_table, biiout)

    src_graph, references = compute_src_graph(hive_holder, common_table)
    dep_graph, closure, overwrites = build_closure(biiapi, references,
                                                   common_table, settings,
                                                   biiout)
    hive_dependencies = hive_holder.hive.hive_dependencies
    hive_dependencies.src_graph = src_graph  # BlockVersionGraph
    hive_dependencies.dep_graph = dep_graph  # BlockVersionGraph
    hive_dependencies.closure = closure
    hive_dependencies.references = references

    real_graph = src_graph + dep_graph
    real_graph.sanitize(biiout)
    _update_requirements(hive_holder, real_graph, overwrites, common_table,
                         biiout)

    for block_holder in hive_holder.block_holders:
        biiconfig = block_holder.commit_config()  # Resource
        if biiconfig:
            processor_changes.upsert(biiconfig.name,
                                     biiconfig.content,
                                     blob_changed=True)

    hive_holder.hive.update(processor_changes)