cmds.projects.CmdBuild: Annotate types
CmdBuild lacks consistent type annotation, add that.
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
40eac92333
commit
9623870f9a
1 changed files with 29 additions and 30 deletions
|
|
@ -1,15 +1,16 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from ...App import Scope
|
from ...App import Scope
|
||||||
from ...lib.log import DEBUG, ERR, NOTICE, log
|
from ...lib.log import DEBUG, ERR, NOTICE, log
|
||||||
from ...lib.util import get_profile_env, pretty_cmd
|
from ...lib.util import get_profile_env, pretty_cmd
|
||||||
from .Cmd import Cmd, Parent
|
from .Cmd import Cmd, Parent
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from argparse import ArgumentParser, Namespace
|
from argparse import ArgumentParser, Namespace
|
||||||
|
|
@ -150,7 +151,9 @@ class CmdBuild(Cmd): # export
|
||||||
dep_tree[k].remove(d)
|
dep_tree[k].remove(d)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
async def run_make(module, target, cur_project, num_projects) -> None:
|
async def run_make(
|
||||||
|
module: str, target: str, cur_project: int, num_projects: int
|
||||||
|
) -> None:
|
||||||
|
|
||||||
patt = self.app.is_excluded_from_build(module)
|
patt = self.app.is_excluded_from_build(module)
|
||||||
if patt is not None:
|
if patt is not None:
|
||||||
|
|
@ -194,17 +197,21 @@ class CmdBuild(Cmd): # export
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log(
|
log(
|
||||||
ERR,
|
ERR,
|
||||||
(
|
|
||||||
f'Failed to make target "{target}" in module "{module}" '
|
f'Failed to make target "{target}" in module "{module}" '
|
||||||
f'below base {self.app.projs_root}: {str(e)}'
|
f'below base {self.app.projs_root}: {str(e)}'
|
||||||
),
|
|
||||||
)
|
)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def run_make_on_modules(modules, order, target):
|
async def run_make_on_modules(
|
||||||
|
modules: set[str], order: list[str], target: str
|
||||||
|
) -> None:
|
||||||
cur_project = 0
|
cur_project = 0
|
||||||
num_projects = len(order)
|
num_projects = len(order)
|
||||||
if target in ['clean', 'distclean']:
|
if target not in ['clean', 'distclean']:
|
||||||
|
for m in order:
|
||||||
|
cur_project += 1
|
||||||
|
await run_make(m, target, cur_project, num_projects)
|
||||||
|
return
|
||||||
for m in reversed(order):
|
for m in reversed(order):
|
||||||
cur_project += 1
|
cur_project += 1
|
||||||
await run_make(m, target, cur_project, num_projects)
|
await run_make(m, target, cur_project, num_projects)
|
||||||
|
|
@ -212,27 +219,22 @@ class CmdBuild(Cmd): # export
|
||||||
modules.remove(m)
|
modules.remove(m)
|
||||||
if not len(modules):
|
if not len(modules):
|
||||||
log(NOTICE, 'All modules cleaned')
|
log(NOTICE, 'All modules cleaned')
|
||||||
return
|
|
||||||
else:
|
|
||||||
for m in order:
|
|
||||||
cur_project += 1
|
|
||||||
await run_make(m, target, cur_project, num_projects)
|
|
||||||
|
|
||||||
async def run(args):
|
async def run(args) -> None:
|
||||||
|
|
||||||
log(DEBUG, f'-------------------------------------- running {pretty_cmd()}')
|
log(DEBUG, f'-------------------------------------- running {pretty_cmd()}')
|
||||||
|
|
||||||
modules = args.modules
|
modules = set(args.modules)
|
||||||
exclude = args.exclude.split()
|
exclude = set(args.exclude.split())
|
||||||
target = args.target
|
target = args.target
|
||||||
|
|
||||||
env_exclude = os.getenv('BUILD_EXCLUDE', '')
|
env_exclude = os.getenv('BUILD_EXCLUDE', '')
|
||||||
if len(env_exclude):
|
if env_exclude is not None:
|
||||||
log(NOTICE, 'Exluding modules from environment: ' + env_exclude)
|
log(NOTICE, f'Exluding modules from environment: {env_exclude}')
|
||||||
exclude += ' ' + env_exclude
|
exclude |= set(env_exclude.split())
|
||||||
|
|
||||||
# -- build
|
# -- build
|
||||||
order = []
|
order: list[str] = []
|
||||||
|
|
||||||
glob_prereq_types = ['build']
|
glob_prereq_types = ['build']
|
||||||
if re.match('pkg-.*', target) is not None:
|
if re.match('pkg-.*', target) is not None:
|
||||||
|
|
@ -251,7 +253,7 @@ class CmdBuild(Cmd): # export
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
cur_project = 0
|
cur_project = 0
|
||||||
log(NOTICE, 'Building target %s in %d projects:' % (target, len(order)))
|
log(NOTICE, f'Building target {target} in {len(order)} projects:')
|
||||||
for m in order:
|
for m in order:
|
||||||
cur_project += 1
|
cur_project += 1
|
||||||
log(NOTICE, ' %3d %s' % (cur_project, m))
|
log(NOTICE, ' %3d %s' % (cur_project, m))
|
||||||
|
|
@ -263,12 +265,9 @@ class CmdBuild(Cmd): # export
|
||||||
|
|
||||||
log(
|
log(
|
||||||
NOTICE,
|
NOTICE,
|
||||||
(
|
|
||||||
'Build done at %s' %
|
'Build done at %s' %
|
||||||
(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
|
(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
dep_cache: dict[str, dict[str, list[str]]] = {}
|
dep_cache: dict[str, dict[str, list[str]]] = {}
|
||||||
|
|
||||||
await run(args)
|
await run(args)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue