From 838b745581b75fb76b8e495e5b208a5152fab18b Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Wed, 18 Feb 2026 11:00:00 +0100 Subject: [PATCH] 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 --- src/python/jw/pkg/cmds/projects/CmdBuild.py | 40 ++++++++++----------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/python/jw/pkg/cmds/projects/CmdBuild.py b/src/python/jw/pkg/cmds/projects/CmdBuild.py index e74aa059..c6424ecf 100644 --- a/src/python/jw/pkg/cmds/projects/CmdBuild.py +++ b/src/python/jw/pkg/cmds/projects/CmdBuild.py @@ -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