Handle stdstreams from submakefile commands cleanly

Some commands utilise a logfile argument, while others capture the stdstreams
into a file. Discard the stdout/stderr when a logfile argument is used.
This keeps the logs readable.
This commit is contained in:
Harry Callahan 2022-04-07 12:22:33 +01:00 committed by Rupert Swarbrick
parent 7083d669c6
commit 9b52fc132a
2 changed files with 24 additions and 7 deletions

View file

@ -324,9 +324,10 @@ $(metadata)/.instr_gen.run.stamp: \
@sed -i $(REGEX_EMPTY_LINES) $(INSTR_GEN_RUN_COMMANDS)
$(verb)./construct_makefile.py \
--output=$(OUT-SEED)/instr_gen/run.mk \
--test_cmds=$(INSTR_GEN_RUN_COMMANDS)
export RISCV_DV_ROOT
@$(MAKE) -f $(OUT-SEED)/instr_gen/run.mk all
--test_cmds=$(INSTR_GEN_RUN_COMMANDS) \
--discard_stdstreams
@export RISCV_DV_ROOT
@$(MAKE) -s -f $(OUT-SEED)/instr_gen/run.mk all
@ # Bookkeeping
@touch $@
@ -381,7 +382,7 @@ $(metadata)/.iss.run.stamp: \
$(verb)./construct_makefile.py \
--output=$(OUT-SEED)/instr_gen/iss.mk \
--test_cmds=$(ISS_COMMANDS)
@$(MAKE) -f $(OUT-SEED)/instr_gen/iss.mk all
@$(MAKE) -s -f $(OUT-SEED)/instr_gen/iss.mk all
@ # Bookkeeping
$(call dump-vars,$(metadata)/.iss.vars.mk,iss,$(iss-var-deps))
@touch $@

View file

@ -15,16 +15,32 @@ _OLD_SYS_PATH = sys.path
def main() -> int:
"""
Construct a trivial makefile from the --debug output of riscv-dv commands.
Creates a flat makefile, so if the commands have any ordering requirements
this will fall over.
"""
parser = argparse.ArgumentParser()
parser.add_argument('--test_cmds', required=True)
parser.add_argument('--output', required=True)
parser.add_argument('--test_cmds', required=True,
help='File containing --debug output')
parser.add_argument('--output', required=True,
help='Makefile to be constructed')
parser.add_argument("--discard_stdstreams", action='store_true',
help='Redirect stdstreams to /dev/null')
args = parser.parse_args()
# Many commands come with a logfile argument, however some capture the
# stdout/stderr to a file. Handle both cases to ensure the logs are tidy.
tail = '\n'
if args.discard_stdstreams:
tail = ' >/dev/null 2>&1' + tail
with open(args.test_cmds) as f, \
open(args.output, 'w', encoding='UTF-8') as outfile:
for i, line in enumerate(f):
outfile.write(f'{i}:\n')
outfile.write('\t' + line)
outfile.write('\t' + line.strip() + tail)
outfile.write(f'CMDS := $(shell seq 0 {i})\n')
outfile.write('all: $(CMDS)')