Support test data generators in generate_files_helper.py

Support check and always-update mode. Update-if-needed mode falls back to
always-update mode because test_data_generation.py doesn't support
update-if-needed.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine
2026-02-11 16:38:28 +01:00
parent 2fe235d289
commit d85217d8f5
@@ -6,6 +6,8 @@ and configuration-independent.
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
import argparse
import os
import subprocess
import sys
from typing import Dict, Iterable, List, Sequence, Set
@@ -46,6 +48,39 @@ class Generator:
raise NotImplementedError
class TestDataGenerator(Generator):
"""A test data generator script.
Even though the test data generator scripts are written in Python, we
run them as a separate process, because their output depends on the
program name (they write sys.argv[0] in a comment in the .data file).
"""
def __init__(self, script: str) -> None:
"""Run the specified test generator to generate files.
Assume that the script is written in Python and has the command line
interface of test_data_generation.py.
"""
self.script = script
def generator_name(self) -> str:
return os.path.basename(self.script)
def target_files(self) -> List[str]:
output = subprocess.check_output([sys.executable, self.script, '--list'],
encoding='utf-8')
return output.splitlines()
def outdated_files(self) -> List[str]:
output = subprocess.check_output([sys.executable, self.script, '--list-outdated'],
encoding='utf-8')
return output.splitlines()
def update(self, _always) -> None:
subprocess.check_call([sys.executable, self.script])
def assemble(available: Iterable[Generator]) -> Dict[str, Generator]:
"""Assemble the generators into a dictionary with both names and targets as keys."""
by_ident = {} #type: Dict[str, Generator]