jw.pkg.cmds.projects.CmdBuild: Use run_cmd("make")

Use run_cmd() for centralized process handling, instead of
hand-rolled Popen().

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-02-18 11:00:00 +01:00
commit 838b745581

View file

@ -4,6 +4,7 @@ import os, re, sys, subprocess, datetime, time
from argparse import Namespace, ArgumentParser
from functools import lru_cache
from ...lib.util import run_cmd
from ...lib.log import *
from ..Cmd import Cmd
from ..CmdProjects import CmdProjects
@ -84,32 +85,29 @@ class CmdBuild(Cmd): # export
return 1
async def run_make(module, target, cur_project, num_projects):
#make_cmd = "make " + target + " 2>&1"
make_cmd = [ "make", target ]
path = self.app.find_dir(module, pretty=False)
delim_len = 120
delim = '---- [%d/%d]: running %s in %s -' % (cur_project, num_projects, make_cmd, path)
delim = delim + '-' * (delim_len - len(delim))
print(',' + delim + ' >')
wd = self.app.find_dir(module, pretty=False)
title = '---- [%d/%d]: Running "%s" in %s -' % (cur_project, num_projects, ' '.join(make_cmd), wd)
patt = self.app.is_excluded_from_build(module)
if patt is not None:
print('| Configured to skip build on platform >' + patt + '<')
print('`' + delim + ' <')
return
print(',' + title + ' >')
print('| Configured to skip build on platform >' + patt + '<')
print('`' + title + ' <')
return
os.chdir(path)
p = subprocess.Popen(make_cmd, shell=False, stdout=subprocess.PIPE, stderr=None, close_fds=True)
for line in iter(p.stdout.readline, b''):
line = line.decode(sys.stdout.encoding)
sys.stdout.write('| ' + line) # avoid extra newlines from print()
sys.stdout.flush()
p.wait()
print('`' + delim + ' <')
if p.returncode:
print(' '.join(make_cmd) + ' failed')
raise Exception(time.strftime("%Y-%m-%d %H:%M") + ": failed to make target " + target + " in module " + module + " below base " + self.app.projs_root)
try:
stdout, stderr = await run_cmd(
*make_cmd,
wd=wd,
throw=True,
verbose=True,
cmd_input=None,
env=None,
title=title
)
except Exception as e:
raise RuntimeError(f'Failed to make target "{target}" in module "{module}" below base {self.app.projs_root}: {str(e)}')
async def run_make_on_modules(modules, order, target):
cur_project = 0