2025-11-16 11:39:27 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
from argparse import Namespace, ArgumentParser
|
|
|
|
|
|
2026-01-25 15:18:27 +01:00
|
|
|
from ...lib.log import *
|
2025-11-16 11:39:27 +01:00
|
|
|
from ..Cmd import Cmd
|
2026-01-27 10:22:16 +01:00
|
|
|
from ..CmdProjects import CmdProjects
|
2025-11-16 11:39:27 +01:00
|
|
|
|
|
|
|
|
class CmdCheck(Cmd): # export
|
|
|
|
|
|
2026-01-27 10:22:16 +01:00
|
|
|
def __init__(self, parent: CmdProjects) -> None:
|
|
|
|
|
super().__init__(parent, 'check', help='Check for circular dependencies between given modules')
|
2025-11-16 11:39:27 +01:00
|
|
|
|
|
|
|
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
|
|
|
|
super().add_arguments(parser)
|
|
|
|
|
parser.add_argument('module', nargs='*', help='Modules')
|
|
|
|
|
parser.add_argument('-f', '--flavour', nargs='?', default = 'build')
|
|
|
|
|
|
2026-01-27 14:31:25 +01:00
|
|
|
async def _run(self, args: Namespace) -> None:
|
2025-11-16 11:39:27 +01:00
|
|
|
graph = {}
|
|
|
|
|
path = []
|
|
|
|
|
self.app.read_dep_graph(args.module, args.flavour, graph)
|
|
|
|
|
unvisited = list(graph.keys())
|
|
|
|
|
temp = set()
|
|
|
|
|
while len(unvisited) != 0:
|
|
|
|
|
m = unvisited[0]
|
2026-01-25 15:18:27 +01:00
|
|
|
log(DEBUG, 'Checking circular dependency of', m)
|
2025-11-16 11:39:27 +01:00
|
|
|
last = self.app.check_circular_deps(m, args.flavour, self.app.flip_graph(graph), unvisited, temp, path)
|
|
|
|
|
if last is not None:
|
2026-01-25 15:18:27 +01:00
|
|
|
log(DEBUG, 'Found circular dependency below', m, ', last is', last)
|
2025-11-16 11:39:27 +01:00
|
|
|
print('Found circular dependency in flavour', args.flavour, ':', ' -> '.join(path))
|
|
|
|
|
exit(1)
|
|
|
|
|
print('No circular dependency found for flavour', args.flavour, ' in modules:',
|
|
|
|
|
' '.join(args.module))
|
|
|
|
|
exit(0)
|