From 5f723291a8c7e9a30ba3a10a605ea2c5bc428379 Mon Sep 17 00:00:00 2001 From: Michael Behrisch Date: Tue, 11 Feb 2025 11:28:53 +0100 Subject: [PATCH] generate templates in batches fix #16155 --- tools/build_config/templates.py | 42 ++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/tools/build_config/templates.py b/tools/build_config/templates.py index 39eeed0fe1e..687909a2895 100755 --- a/tools/build_config/templates.py +++ b/tools/build_config/templates.py @@ -374,21 +374,8 @@ def generateTemplate(app, appBin): return u'const std::string %sTemplate = "%s";\n' % (app, template) -def generateToolTemplates(toolDir, toolPaths, verbose, testFailure=False): - """ - @brief generate tool template - """ - print("Obtaining tool templates.") - procs = [] +def _collectOutput(procs, toolPaths, failed, verbose, testFailure): result = u"" - for toolPath in toolPaths: - toolName = os.path.basename(toolPath)[:-3] - if verbose: - print("Obtaining '" + toolName + "' tool template.") - # obtain template piping stdout using check_output - procs.append(subprocess.Popen([sys.executable, join(toolDir, toolPath), "--save-template", "stdout"], - stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)) - failed = [] for p, toolPath in zip(procs, toolPaths): toolName = os.path.basename(toolPath)[:-3] d = os.path.dirname(toolPath) @@ -402,6 +389,33 @@ def generateToolTemplates(toolDir, toolPaths, verbose, testFailure=False): else: result += formatToolTemplate(stdout) result += '),\n' + return result + + +def generateToolTemplates(toolDir, toolPaths, verbose, testFailure=False): + """ + @brief generate tool template + """ + print("Obtaining tool templates.") + procs = [] + result = u"" + failed = [] + paths = [] + env = dict(os.environ) + if "SUMO_HOME" not in env: + env["SUMO_HOME"] = join(dirname(__file__), '..', '..') + for toolPath in toolPaths: + toolName = os.path.basename(toolPath)[:-3] + if verbose: + print("Obtaining '" + toolName + "' tool template.") + procs.append(subprocess.Popen([sys.executable, join(toolDir, toolPath), "--save-template", "stdout"], env=env, + stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)) + paths.append(toolPath) + if len(procs) == 32: + result += _collectOutput(procs, paths, failed, verbose, testFailure) + procs = [] + paths = [] + result += _collectOutput(procs, paths, failed, verbose, testFailure) if testFailure: return failed if failed: